Fix scripts discovery in IDEA after adding optional marker extension
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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>,
|
||||
|
||||
Reference in New Issue
Block a user