Fix scripts discovery in IDEA after adding optional marker extension

This commit is contained in:
Ilya Chernikov
2019-03-25 22:44:18 +01:00
parent 4f1ee649b0
commit 3a3ba5bd8d
2 changed files with 5 additions and 4 deletions
@@ -15,6 +15,8 @@ import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.kotlin.idea.core.script.loadDefinitionsFromTemplates
import org.jetbrains.kotlin.idea.util.projectStructure.allModules
import org.jetbrains.kotlin.script.KotlinScriptDefinition
import org.jetbrains.kotlin.scripting.shared.definitions.SCRIPT_DEFINITION_MARKERS_EXTENSION_WITH_DOT
import org.jetbrains.kotlin.scripting.shared.definitions.SCRIPT_DEFINITION_MARKERS_PATH
import java.io.File
import java.util.concurrent.locks.ReentrantReadWriteLock
import kotlin.concurrent.write
@@ -69,15 +71,14 @@ private data class TemplatesWithCp(
private fun scriptDefinitionsFromDependencies(project: Project): TemplatesWithCp {
val templates = LinkedHashSet<String>()
val classpath = LinkedHashSet<File>()
val templatesPath = "META-INF/kotlin/script/templates/"
fun addTemplatesFromRoot(vfile: VirtualFile): Boolean {
var templatesFound = false
val root = JarFileSystem.getInstance().getJarRootForLocalFile(vfile) ?: vfile
if (root.isValid) {
root.findFileByRelativePath(templatesPath)?.takeIf { it.isDirectory }?.children?.forEach {
root.findFileByRelativePath(SCRIPT_DEFINITION_MARKERS_PATH)?.takeIf { it.isDirectory }?.children?.forEach {
if (it.isValid && !it.isDirectory) {
templates.add(it.name)
templates.add(it.name.removeSuffix(SCRIPT_DEFINITION_MARKERS_EXTENSION_WITH_DOT))
templatesFound = true
}
}
@@ -23,7 +23,7 @@ import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
import kotlin.script.templates.ScriptTemplateDefinition
const val SCRIPT_DEFINITION_MARKERS_PATH = "META-INF/kotlin/script/templates/"
internal const val SCRIPT_DEFINITION_MARKERS_EXTENSION_WITH_DOT = ".classname"
const val SCRIPT_DEFINITION_MARKERS_EXTENSION_WITH_DOT = ".classname"
class ScriptDefinitionsFromClasspathDiscoverySource(
private val classpath: List<File>,