Export filename extension from KotlinScriptDefinition, register...
extensions after loading definitions
This commit is contained in:
+7
-9
@@ -41,7 +41,6 @@ import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.script.*
|
||||
import org.jetbrains.kotlin.script.util.scriptCompilationClasspathFromContextOrStlib
|
||||
import org.jetbrains.kotlin.scripting.compiler.plugin.KotlinScriptDefinitionAdapterFromNewAPI
|
||||
import org.jetbrains.kotlin.scripting.compiler.plugin.KotlinScriptDefinitionAdapterFromNewAPIBase
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.flattenTo
|
||||
@@ -136,18 +135,17 @@ class ScriptDefinitionsManager(private val project: Project) : LazyScriptDefinit
|
||||
assert(lock.isWriteLocked) { "updateDefinitions should only be called under the write lock" }
|
||||
definitions = definitionsByContributor.values.flattenTo(mutableListOf()).asSequence()
|
||||
|
||||
// Register new file extensions
|
||||
val fileTypeManager = FileTypeManager.getInstance()
|
||||
val extensions = definitions?.mapNotNull { definition ->
|
||||
(definition as? KotlinScriptDefinitionAdapterFromNewAPIBase)
|
||||
?.scriptFileExtensionWithDot?.removePrefix(".")
|
||||
?.takeIf { fileTypeManager.getFileTypeByExtension(it) != KotlinFileType.INSTANCE }
|
||||
}?.toList()
|
||||
|
||||
if (extensions?.isNotEmpty() == true) {
|
||||
val newExtensions = getKnownFilenameExtensions().filter {
|
||||
fileTypeManager.getFileTypeByExtension(it) != KotlinFileType.INSTANCE
|
||||
}.toList()
|
||||
|
||||
if (newExtensions.any()) {
|
||||
// Register new file extensions
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
runWriteAction {
|
||||
extensions.forEach {
|
||||
newExtensions.forEach {
|
||||
fileTypeManager.associateExtension(KotlinFileType.INSTANCE, it)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user