mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
[kotlin][scripting] KTIJ-28405: remove outdated code
After IDEA-335705 is complete we can remove the code used as a workaround. GitOrigin-RevId: db2a1ee3ff0a8f87f20dab9ad5c23c812fce038d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f60a136213
commit
115a85167f
@@ -3,12 +3,6 @@
|
||||
package org.jetbrains.kotlin.idea.script
|
||||
|
||||
import com.intellij.openapi.application.ReadAction
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.progress.EmptyProgressIndicator
|
||||
import com.intellij.openapi.progress.ProgressIndicator
|
||||
import com.intellij.openapi.progress.ProgressManager
|
||||
import com.intellij.openapi.progress.Task
|
||||
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.*
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
@@ -16,12 +10,12 @@ import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.search.FileTypeIndex
|
||||
import com.intellij.psi.search.FilenameIndex
|
||||
import com.intellij.util.concurrency.annotations.RequiresBlockingContext
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.base.util.allScope
|
||||
import org.jetbrains.kotlin.idea.core.KotlinPluginDisposable
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptDefinitionSourceAsContributor
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptDefinitionsManager
|
||||
import org.jetbrains.kotlin.idea.core.script.loadDefinitionsFromTemplatesByPaths
|
||||
import org.jetbrains.kotlin.idea.core.script.scriptingDebugLog
|
||||
import org.jetbrains.kotlin.scripting.definitions.SCRIPT_DEFINITION_MARKERS_EXTENSION_WITH_DOT
|
||||
import org.jetbrains.kotlin.scripting.definitions.ScriptDefinition
|
||||
import org.jetbrains.kotlin.scripting.definitions.getEnvironment
|
||||
@@ -34,8 +28,6 @@ import kotlin.concurrent.withLock
|
||||
import kotlin.script.experimental.host.ScriptingHostConfiguration
|
||||
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
||||
|
||||
private val logger = Logger.getInstance(ScriptTemplatesFromDependenciesProvider::class.java)
|
||||
|
||||
class ScriptTemplatesFromDependenciesProvider(private val project: Project) : ScriptDefinitionSourceAsContributor {
|
||||
|
||||
@Deprecated("migrating to new configuration refinement: drop usages")
|
||||
@@ -51,7 +43,7 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc
|
||||
}
|
||||
|
||||
forceStartUpdate = false
|
||||
asyncRunUpdateScriptTemplates()
|
||||
runUpdateScriptTemplates()
|
||||
return _definitions?.asSequence() ?: emptySequence()
|
||||
}
|
||||
|
||||
@@ -61,18 +53,18 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc
|
||||
connection.subscribe(FileTypeIndex.INDEX_CHANGE_TOPIC, FileTypeIndex.IndexChangeListener { fileType ->
|
||||
if (fileType == ScriptDefinitionMarkerFileType && project.isInitialized) {
|
||||
forceStartUpdate = true
|
||||
asyncRunUpdateScriptTemplates(isFileIndexUpdate = true)
|
||||
runUpdateScriptTemplates()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun asyncRunUpdateScriptTemplates(isFileIndexUpdate: Boolean = false) {
|
||||
private fun runUpdateScriptTemplates() {
|
||||
definitionsLock.withLock {
|
||||
if (!forceStartUpdate && _definitions != null) return
|
||||
}
|
||||
|
||||
if (inProgress.compareAndSet(false, true)) {
|
||||
loadScriptDefinitions(isFileIndexUpdate)
|
||||
loadScriptDefinitions()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,36 +85,15 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc
|
||||
private var forceStartUpdate = false
|
||||
|
||||
@RequiresBlockingContext
|
||||
private fun loadScriptDefinitions(isFileIndexUpdate: Boolean) {
|
||||
private fun loadScriptDefinitions() {
|
||||
if (project.isDefault || project.isDisposed) {
|
||||
return onEarlyEnd()
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled) {
|
||||
logger.debug("async script definitions update started")
|
||||
}
|
||||
|
||||
if (!isFileIndexUpdate) {
|
||||
loadSync(EmptyProgressIndicator())
|
||||
} else {
|
||||
val task = object : Task.Backgroundable(
|
||||
project, KotlinBundle.message("kotlin.script.lookup.definitions"), false
|
||||
) {
|
||||
override fun run(indicator: ProgressIndicator) {
|
||||
loadSync(indicator)
|
||||
}
|
||||
}
|
||||
|
||||
ProgressManager.getInstance().runProcessWithProgressAsynchronously(
|
||||
task,
|
||||
BackgroundableProcessIndicator(task)
|
||||
)
|
||||
}
|
||||
loadSync()
|
||||
}
|
||||
|
||||
|
||||
private fun loadSync(indicator: ProgressIndicator) {
|
||||
indicator.isIndeterminate = true
|
||||
private fun loadSync() {
|
||||
val pluginDisposable = KotlinPluginDisposable.getInstance(project)
|
||||
val (templates, classpath) =
|
||||
ReadAction.nonBlocking(Callable {
|
||||
@@ -136,21 +107,17 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc
|
||||
?.children ?: continue
|
||||
files += children
|
||||
}
|
||||
getTemplateClassPath(files, indicator)
|
||||
getTemplateClassPath(files)
|
||||
})
|
||||
.expireWith(pluginDisposable)
|
||||
.wrapProgress(indicator)
|
||||
.executeSynchronously() ?: return onEarlyEnd()
|
||||
try {
|
||||
indicator.checkCanceled()
|
||||
if (pluginDisposable.disposed || !inProgress.get() || templates.isEmpty()) return onEarlyEnd()
|
||||
|
||||
val newTemplates = TemplatesWithCp(templates.toList(), classpath.toList())
|
||||
if (!inProgress.get() || newTemplates == oldTemplates) return onEarlyEnd()
|
||||
|
||||
if (logger.isDebugEnabled) {
|
||||
logger.debug("script templates found: $newTemplates")
|
||||
}
|
||||
scriptingDebugLog { "Script templates found: $newTemplates" }
|
||||
|
||||
oldTemplates = newTemplates
|
||||
|
||||
@@ -167,10 +134,8 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc
|
||||
templateClasspath = newTemplates.classpath,
|
||||
baseHostConfiguration = hostConfiguration,
|
||||
)
|
||||
indicator.checkCanceled()
|
||||
if (logger.isDebugEnabled) {
|
||||
logger.debug("script definitions found: ${newDefinitions.joinToString()}")
|
||||
}
|
||||
|
||||
scriptingDebugLog { "Script definitions found: ${newDefinitions.joinToString()}" }
|
||||
|
||||
val needReload = definitionsLock.withLock {
|
||||
if (newDefinitions != _definitions) {
|
||||
@@ -196,7 +161,7 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc
|
||||
}
|
||||
|
||||
// public for tests
|
||||
fun getTemplateClassPath(files: Collection<VirtualFile>, indicator: ProgressIndicator): Pair<Collection<String>, Collection<Path>> {
|
||||
fun getTemplateClassPath(files: Collection<VirtualFile>): Pair<Collection<String>, Collection<Path>> {
|
||||
val rootDirToTemplates: MutableMap<VirtualFile, MutableList<VirtualFile>> = hashMapOf()
|
||||
for (file in files) {
|
||||
// parent of SCRIPT_DEFINITION_MARKERS_PATH, i.e. of `META-INF/kotlin/script/templates/`
|
||||
@@ -208,13 +173,10 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc
|
||||
val classpath = linkedSetOf<Path>()
|
||||
|
||||
rootDirToTemplates.forEach { (root, templateFiles) ->
|
||||
if (logger.isDebugEnabled) {
|
||||
logger.debug("root matching SCRIPT_DEFINITION_MARKERS_PATH found: ${root.path}")
|
||||
}
|
||||
scriptingDebugLog { "Root matching SCRIPT_DEFINITION_MARKERS_PATH found: ${root.path}" }
|
||||
|
||||
val orderEntriesForFile = ProjectFileIndex.getInstance(project).getOrderEntriesForFile(root)
|
||||
.filter {
|
||||
indicator.checkCanceled()
|
||||
if (it is ModuleSourceOrderEntry) {
|
||||
if (ModuleRootManager.getInstance(it.ownerModule).fileIndex.isInTestSourceContent(root)) {
|
||||
return@filter false
|
||||
@@ -238,7 +200,6 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc
|
||||
// the other has properly configured classpath, so assuming that the dependencies are set correctly everywhere
|
||||
for (orderEntry in orderEntriesForFile) {
|
||||
for (virtualFile in OrderEnumerator.orderEntries(orderEntry.ownerModule).withoutSdk().classesRoots) {
|
||||
indicator.checkCanceled()
|
||||
val localVirtualFile = VfsUtil.getLocalFile(virtualFile)
|
||||
localVirtualFile.fileSystem.getNioPath(localVirtualFile)?.let(classpath::add)
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ abstract class AbstractScriptTemplatesFromDependenciesTest : HeavyPlatformTestCa
|
||||
val provider = ScriptDefinitionContributor.find<ScriptTemplatesFromDependenciesProvider>(project)
|
||||
?: error("Cannot find ScriptTemplatesFromDependenciesProvider")
|
||||
|
||||
val (templates, classpath) = provider.getTemplateClassPath(roots.toList(), EmptyProgressIndicator())
|
||||
val (templates, classpath) = provider.getTemplateClassPath(roots.toList())
|
||||
|
||||
checkTemplateNames(fileText, templates)
|
||||
checkTemplateClasspath(fileText, classpath)
|
||||
|
||||
Reference in New Issue
Block a user