From ce1b388668f3126c81a6b275fb33a5e4b0fd21d2 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Mon, 28 Sep 2020 10:09:09 +0200 Subject: [PATCH] Add registry key kotlin.resolve.forceFullResolveOnHighlighting Relates to ^KT-41195 Relates to ^KT-38687 --- .../idea/project/ResolveElementCache.kt | 10 ++++- .../idea/DaemonCodeAnalyzerStatusService.kt | 43 +++++++++++++++++++ .../DaemonCodeAnalyzerStatusService.kt.202 | 43 +++++++++++++++++++ idea/resources/META-INF/plugin-common.xml | 16 ++++--- 4 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 idea/idea-core/src/org/jetbrains/kotlin/idea/DaemonCodeAnalyzerStatusService.kt create mode 100644 idea/idea-core/src/org/jetbrains/kotlin/idea/DaemonCodeAnalyzerStatusService.kt.202 diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt index 8bef75edd6c..b7517f7be03 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.project import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.project.Project import com.intellij.openapi.roots.ProjectRootModificationTracker +import com.intellij.openapi.util.registry.Registry import com.intellij.psi.util.CachedValue import com.intellij.psi.util.CachedValueProvider import com.intellij.psi.util.CachedValuesManager @@ -22,6 +23,7 @@ import org.jetbrains.kotlin.context.withProject import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.frontend.di.createContainerForBodyResolve +import org.jetbrains.kotlin.idea.DaemonCodeAnalyzerStatusService import org.jetbrains.kotlin.idea.caches.resolve.CodeFragmentAnalyzer import org.jetbrains.kotlin.idea.caches.resolve.util.analyzeControlFlow import org.jetbrains.kotlin.idea.caches.trackers.KotlinCodeBlockModificationListener @@ -50,6 +52,8 @@ class ResolveElementCache( private val codeFragmentAnalyzer: CodeFragmentAnalyzer ) : BodyResolveCache { + private val forcedFullResolveOnHighlighting = Registry.`is`("kotlin.resolve.force.full.resolve.on.highlighting", true) + private class CachedFullResolve(val bindingContext: BindingContext, resolveElement: KtElement) { private val modificationStamp: Long? = modificationStamp(resolveElement) @@ -162,7 +166,11 @@ class ResolveElementCache( // neither result of PARTIAL nor result of PARTIAL_WITH_CFA analyses could be reused by FULL analysis. // // Force perform FULL analysis to avoid redundant analysis for the current selected files. - if (bodyResolveMode != BodyResolveMode.FULL && bodyResolveMode != BodyResolveMode.PARTIAL_FOR_COMPLETION && (!isUnitTestMode() || forceFullAnalysisModeInTests)) { + if (bodyResolveMode != BodyResolveMode.FULL && + bodyResolveMode != BodyResolveMode.PARTIAL_FOR_COMPLETION && + (!isUnitTestMode() || forceFullAnalysisModeInTests) && + forcedFullResolveOnHighlighting && DaemonCodeAnalyzerStatusService.getInstance(project).daemonRunning + ) { val virtualFile = resolveElement.containingFile.virtualFile // applicable for real (physical) files only if (virtualFile != null && FileEditorManager.getInstance(resolveElement.project).selectedFiles.any { it == virtualFile }) { diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/DaemonCodeAnalyzerStatusService.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/DaemonCodeAnalyzerStatusService.kt new file mode 100644 index 00000000000..526a762cab2 --- /dev/null +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/DaemonCodeAnalyzerStatusService.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea + +import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer +import com.intellij.openapi.Disposable +import com.intellij.openapi.fileEditor.FileEditor +import com.intellij.openapi.project.Project +import org.jetbrains.kotlin.idea.util.application.getServiceSafe + +class DaemonCodeAnalyzerStatusService(project: Project) : Disposable { + companion object { + fun getInstance(project: Project): DaemonCodeAnalyzerStatusService = project.getServiceSafe() + } + + @Volatile + var daemonRunning: Boolean = false + private set + + init { + val messageBusConnection = project.messageBus.connect(this) + messageBusConnection.subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, object : DaemonCodeAnalyzer.DaemonListener { + override fun daemonStarting(fileEditors: MutableCollection) { + daemonRunning = true + } + + override fun daemonFinished(fileEditors: MutableCollection) { + daemonRunning = false + } + + override fun daemonCancelEventOccurred(reason: String) { + daemonRunning = false + } + }) + } + + override fun dispose() { + + } +} \ No newline at end of file diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/DaemonCodeAnalyzerStatusService.kt.202 b/idea/idea-core/src/org/jetbrains/kotlin/idea/DaemonCodeAnalyzerStatusService.kt.202 new file mode 100644 index 00000000000..0eaadbe3162 --- /dev/null +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/DaemonCodeAnalyzerStatusService.kt.202 @@ -0,0 +1,43 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea + +import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer +import com.intellij.openapi.Disposable +import com.intellij.openapi.fileEditor.FileEditor +import com.intellij.openapi.project.Project +import org.jetbrains.kotlin.idea.util.application.getServiceSafe + +class DaemonCodeAnalyzerStatusService(project: Project) : Disposable { + companion object { + fun getInstance(project: Project): DaemonCodeAnalyzerStatusService = project.getServiceSafe() + } + + @Volatile + var daemonRunning: Boolean = false + private set + + init { + val messageBusConnection = project.messageBus.connect(this) + messageBusConnection.subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, object : DaemonCodeAnalyzer.DaemonListener { + override fun daemonStarting(fileEditors: MutableCollection) { + daemonRunning = true + } + + override fun daemonFinished(fileEditors: MutableCollection) { + daemonRunning = false + } + + override fun daemonCancelEventOccurred(reason: String) { + daemonRunning = false + } + }) + } + + override fun dispose() { + + } +} \ No newline at end of file diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index 3519563cbd8..be399d9e6f5 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -179,6 +179,8 @@ + + @@ -292,11 +294,15 @@ - + + +