gradle.kts: improve service initializtion
- prevent analyzing .gradle.kts files until all services are loaded - remove services caches where it is not required - replace cached services with cache only during vfs events batch processing - prevent services loading in actions updating
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.idea.core.script
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.components.serviceIfCreated
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.util.Key
|
||||
@@ -108,6 +109,9 @@ interface ScriptConfigurationManager {
|
||||
fun getAllScriptDependenciesSources(): List<VirtualFile>
|
||||
|
||||
companion object {
|
||||
fun getServiceIfCreated(project: Project): ScriptConfigurationManager? =
|
||||
ServiceManager.getServiceIfCreated(project, ScriptConfigurationManager::class.java)
|
||||
|
||||
@JvmStatic
|
||||
fun getInstance(project: Project): ScriptConfigurationManager =
|
||||
ServiceManager.getService(project, ScriptConfigurationManager::class.java)
|
||||
|
||||
+3
-1
@@ -84,7 +84,9 @@ class ScriptDefinitionsManager(private val project: Project) : LazyScriptDefinit
|
||||
private val scriptDefinitionsCacheLock = ReentrantLock()
|
||||
private val scriptDefinitionsCache = SLRUMap<String, ScriptDefinition>(10, 10)
|
||||
|
||||
val configurations = (ScriptConfigurationManager.getInstance(project) as CompositeScriptConfigurationManager)
|
||||
// cache service as it's getter is on the hot path
|
||||
// it is safe, since both services are in same plugin
|
||||
val configurations = ScriptConfigurationManager.getInstance(project) as CompositeScriptConfigurationManager
|
||||
|
||||
override fun findDefinition(script: SourceCode): ScriptDefinition? {
|
||||
val locationId = script.locationId ?: return null
|
||||
|
||||
+8
-2
@@ -27,10 +27,16 @@ class ScriptTrafficLightRendererContributor : TrafficLightRendererContributor {
|
||||
TrafficLightRenderer(project, document, file) {
|
||||
override fun getDaemonCodeAnalyzerStatus(severityRegistrar: SeverityRegistrar): DaemonCodeAnalyzerStatus {
|
||||
val status = super.getDaemonCodeAnalyzerStatus(severityRegistrar)
|
||||
if (!ScriptDefinitionsManager.getInstance(file.project).isReady()) {
|
||||
|
||||
val configurations = ScriptConfigurationManager.getServiceIfCreated(project)
|
||||
if (configurations == null) {
|
||||
// services not yet initialized (it should be initialized under the LoadScriptDefinitionsStartupActivity)
|
||||
status.reasonWhySuspended = KotlinIdeaCoreBundle.message("text.loading.kotlin.script.configuration")
|
||||
status.errorAnalyzingFinished = false
|
||||
} else if (!ScriptDefinitionsManager.getInstance(file.project).isReady()) {
|
||||
status.reasonWhySuspended = KotlinIdeaCoreBundle.message("text.loading.kotlin.script.definitions")
|
||||
status.errorAnalyzingFinished = false
|
||||
} else if (ScriptConfigurationManager.getInstance(project).isConfigurationLoadingInProgress(file)) {
|
||||
} else if (configurations.isConfigurationLoadingInProgress(file)) {
|
||||
status.reasonWhySuspended = KotlinIdeaCoreBundle.message("text.loading.kotlin.script.configuration")
|
||||
status.errorAnalyzingFinished = false
|
||||
}
|
||||
|
||||
+2
-1
@@ -49,7 +49,8 @@ class CompositeScriptConfigurationManager(val project: Project) : ScriptConfigur
|
||||
private val classpathRoots: ScriptClassRootsCache
|
||||
get() = updater.classpathRoots
|
||||
|
||||
private val plugins = ScriptingSupport.EPN.getPoint(project).extensionList
|
||||
private val plugins
|
||||
get() = ScriptingSupport.EPN.getPoint(project).extensionList
|
||||
|
||||
val default = DefaultScriptingSupport(this)
|
||||
|
||||
|
||||
+5
-4
@@ -83,10 +83,11 @@ internal class ScriptChangesNotifier(
|
||||
}
|
||||
|
||||
private val defaultListener = DefaultScriptChangeListener(project)
|
||||
private val listeners: Collection<ScriptChangeListener> = mutableListOf<ScriptChangeListener>().apply {
|
||||
addAll(LISTENER.getPoint(project).extensionList)
|
||||
add(defaultListener)
|
||||
}
|
||||
private val listeners: Collection<ScriptChangeListener>
|
||||
get() = mutableListOf<ScriptChangeListener>().apply {
|
||||
addAll(LISTENER.getPoint(project).extensionList)
|
||||
add(defaultListener)
|
||||
}
|
||||
|
||||
private fun getListener(project: Project, file: VirtualFile): ScriptChangeListener? {
|
||||
if (project.isDisposed || areListenersDisabled()) return null
|
||||
|
||||
Reference in New Issue
Block a user