diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/highlighting/HighlightUsagesHandlerTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/highlighting/HighlightUsagesHandlerTest.java index bfb44360894d..1a05b74ebce8 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/highlighting/HighlightUsagesHandlerTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/highlighting/HighlightUsagesHandlerTest.java @@ -261,7 +261,7 @@ public class HighlightUsagesHandlerTest extends DaemonAnalyzerTestCase { } public void testIdentifierHighlighterForStaticImports() { - IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), getTestRootDisposable(), ()->{ + IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), ()->{ try { createClass(""" @@ -329,7 +329,7 @@ public class HighlightUsagesHandlerTest extends DaemonAnalyzerTestCase { } public void testMethodParameterEndOfIdentifier() { - IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), getTestRootDisposable(), ()-> { + IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), ()-> { try { configureFile(); } diff --git a/platform/lang-impl/api-dump-unreviewed.txt b/platform/lang-impl/api-dump-unreviewed.txt index 860e60f4e137..85ac5cf0f301 100644 --- a/platform/lang-impl/api-dump-unreviewed.txt +++ b/platform/lang-impl/api-dump-unreviewed.txt @@ -2274,7 +2274,6 @@ f:com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass f:com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPassFactory - ():V - createHighlightingPass(com.intellij.psi.PsiFile,com.intellij.openapi.editor.Editor,com.intellij.openapi.util.TextRange):com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass -- s:doWithHighlightingEnabled(com.intellij.openapi.project.Project,com.intellij.openapi.Disposable,java.lang.Runnable):V - s:isEnabled():Z - s:waitForIdentifierHighlighting():V c:com.intellij.codeInsight.daemon.impl.IndentGuideRenderer diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlighterPassFactory.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlighterPassFactory.java index 9a9193ed7072..4932e345a617 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlighterPassFactory.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlighterPassFactory.java @@ -3,7 +3,6 @@ package com.intellij.codeInsight.daemon.impl; import com.intellij.codeInsight.CodeInsightSettings; import com.intellij.codeInsight.highlighting.BackgroundHighlighter; -import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.impl.NonBlockingReadActionImpl; import com.intellij.openapi.editor.Editor; @@ -17,6 +16,7 @@ import com.intellij.psi.PsiFile; import com.intellij.testFramework.TestModeFlags; import com.intellij.util.concurrency.ThreadingAssertions; import com.intellij.util.concurrency.annotations.RequiresEdt; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.TestOnly; @@ -46,15 +46,17 @@ public final class IdentifierHighlighterPassFactory { @TestOnly @RequiresEdt - public static void doWithHighlightingEnabled(@NotNull Project project, @NotNull Disposable parentDisposable, @NotNull Runnable r) { + @ApiStatus.Internal + public static void doWithHighlightingEnabled(@NotNull Project project, @NotNull Runnable r) { ThreadingAssertions.assertEventDispatchThread(); - BackgroundHighlighter.Companion.enableListenersInTest(project, parentDisposable); - try { - TestModeFlags.runWithFlag(ourTestingIdentifierHighlighting, true, r); - } - finally { - waitForIdentifierHighlighting(); - } + BackgroundHighlighter.Companion.runWithEnabledListenersInTest(project, ()-> { + try { + TestModeFlags.runWithFlag(ourTestingIdentifierHighlighting, true, r); + } + finally { + waitForIdentifierHighlighting(); + } + }); } @TestOnly diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlighter.kt b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlighter.kt index cc72b81d2690..a39229eaff5a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlighter.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlighter.kt @@ -82,13 +82,20 @@ internal class BackgroundHighlighter(coroutineScope: CoroutineScope) { companion object { @TestOnly - fun enableListenersInTest(project: Project, parentDisposable: Disposable) { + fun runWithEnabledListenersInTest(project: Project, r: Runnable) { val d = project.service() + val parentDisposable = Disposer.newDisposable() val coroutineScope = d.coroutineScope.childScope("Test Background Highlighter(disposable=$parentDisposable)") Disposer.register(parentDisposable, Disposable { coroutineScope.cancel() }) service().registerListeners(project, parentDisposable, coroutineScope) + try { + r.run() + } + finally { + Disposer.dispose(parentDisposable) + } } } diff --git a/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java index 223335f5fab7..05d69c0709c7 100644 --- a/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java @@ -840,7 +840,7 @@ public final class EditorTestUtil { caretModel.removeSecondaryCarets(); CharSequence documentSequence = InjectedLanguageEditorUtil.getTopLevelEditor(editor).getDocument().getCharsSequence(); - IdentifierHighlighterPassFactory.doWithHighlightingEnabled(fixture.getProject(), fixture.getProjectDisposable(), () -> { + IdentifierHighlighterPassFactory.doWithHighlightingEnabled(fixture.getProject(), () -> { for (Integer caretsOffset : caretsOffsets) { if (caretsOffset != -1) { caretModel.moveToOffset(caretsOffset); diff --git a/plugins/devkit/devkit-java-tests/testSrc/org/jetbrains/idea/devkit/codeInsight/PluginXmlIdentifierHighlightingTest.java b/plugins/devkit/devkit-java-tests/testSrc/org/jetbrains/idea/devkit/codeInsight/PluginXmlIdentifierHighlightingTest.java index 155b6c812846..73f972f84aca 100644 --- a/plugins/devkit/devkit-java-tests/testSrc/org/jetbrains/idea/devkit/codeInsight/PluginXmlIdentifierHighlightingTest.java +++ b/plugins/devkit/devkit-java-tests/testSrc/org/jetbrains/idea/devkit/codeInsight/PluginXmlIdentifierHighlightingTest.java @@ -17,7 +17,7 @@ public class PluginXmlIdentifierHighlightingTest extends LightJavaCodeInsightFix } public void test_ep_references() { - IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), getTestRootDisposable(), () -> { + IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), () -> { myFixture.configureByText("plugin.xml", """ diff --git a/plugins/editorconfig/backend/test/language/codeinsight/EditorConfigHighlightUsagesTest.kt b/plugins/editorconfig/backend/test/language/codeinsight/EditorConfigHighlightUsagesTest.kt index ff0e9e709b1a..b1624273aec2 100644 --- a/plugins/editorconfig/backend/test/language/codeinsight/EditorConfigHighlightUsagesTest.kt +++ b/plugins/editorconfig/backend/test/language/codeinsight/EditorConfigHighlightUsagesTest.kt @@ -22,7 +22,7 @@ class EditorConfigHighlightUsagesTest : BasePlatformTestCase() { private fun doTest() { SeveritiesProvider.EP_NAME.point.registerExtension(SEVERITIES_PROVIDER, testRootDisposable) val name = getTestName(true) - IdentifierHighlighterPassFactory.doWithHighlightingEnabled (project, testRootDisposable, Runnable { + IdentifierHighlighterPassFactory.doWithHighlightingEnabled (project, Runnable { myFixture.configureByFile("${name}/.editorconfig") myFixture.setReadEditorMarkupModel(true) myFixture.checkHighlighting() diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightUsagesTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightUsagesTest.java index 286c6f9ac938..605f92d95606 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightUsagesTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightUsagesTest.java @@ -29,7 +29,7 @@ public class GroovyHighlightUsagesTest extends LightGroovyTestCase { private void doTest(boolean directoryTest) { SeveritiesProvider.EP_NAME.getPoint().registerExtension(SEVERITIES_PROVIDER, getTestRootDisposable()); - IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), getTestRootDisposable(), () -> { + IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), () -> { String name = getTestName(); JavaCodeInsightTestFixture fixture = getFixture(); if (directoryTest) { diff --git a/plugins/java-decompiler/plugin/test/com/intellij/java/decompiler/IdeaDecompilerTest.kt b/plugins/java-decompiler/plugin/test/com/intellij/java/decompiler/IdeaDecompilerTest.kt index 118f01e4b841..0f27b9baaa91 100644 --- a/plugins/java-decompiler/plugin/test/com/intellij/java/decompiler/IdeaDecompilerTest.kt +++ b/plugins/java-decompiler/plugin/test/com/intellij/java/decompiler/IdeaDecompilerTest.kt @@ -174,7 +174,7 @@ class IdeaDecompilerTest : LightJavaCodeInsightFixtureTestCase() { fun testHighlighting() { myFixture.setReadEditorMarkupModel(true) - IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, testRootDisposable, Runnable { + IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, Runnable { myFixture.openFileInEditor(getTestFile("Navigation.class")) myFixture.editor.caretModel.moveToOffset(offset(8, 14)) // m2(): usage, declaration assertEquals(2, highlightUnderCaret().size) @@ -196,7 +196,7 @@ class IdeaDecompilerTest : LightJavaCodeInsightFixtureTestCase() { fun testNameHighlightingInsideCompiledFile() { myFixture.setReadEditorMarkupModel(true) myFixture.openFileInEditor(getTestFile("NamesHighlightingInsideCompiledFile.class")) - IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, testRootDisposable, Runnable { + IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, Runnable { val infos = myFixture.doHighlighting() assertTrue(infos.toString(), infos.all { info: HighlightInfo -> info.severity === HighlightInfoType.SYMBOL_TYPE_SEVERITY }) assertEquals(68, infos.size) @@ -206,7 +206,7 @@ class IdeaDecompilerTest : LightJavaCodeInsightFixtureTestCase() { fun testNameHighlightingInsideCompiledModuleFile() { myFixture.setReadEditorMarkupModel(true) myFixture.openFileInEditor(getTestFile("module-info.class")) - IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, testRootDisposable, Runnable { + IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, Runnable { val infos = myFixture.doHighlighting() .filter { it.severity === HighlightInfoType.SYMBOL_TYPE_SEVERITY } assertEquals(5, infos.size) @@ -225,7 +225,7 @@ class IdeaDecompilerTest : LightJavaCodeInsightFixtureTestCase() { val testFile = getTestFile("RecordHighlighting.class") testFile.parent.children; testFile.parent.refresh(false, true) // inner classes myFixture.openFileInEditor(testFile) - IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, testRootDisposable, Runnable { + IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, Runnable { val infos = myFixture.doHighlighting() .filter { it.severity === HighlightInfoType.SYMBOL_TYPE_SEVERITY } val texts = infos.map { it.text }.toSet() diff --git a/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/live/AbstractPerformanceProjectsTest.kt b/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/live/AbstractPerformanceProjectsTest.kt index 9b69c2971b2e..92b20c0d8f16 100644 --- a/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/live/AbstractPerformanceProjectsTest.kt +++ b/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/live/AbstractPerformanceProjectsTest.kt @@ -548,7 +548,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() { internal fun Project.highlightFile(block: () -> T): T { var value: T? = null - IdentifierHighlighterPassFactory.doWithHighlightingEnabled(this, this) { + IdentifierHighlighterPassFactory.doWithHighlightingEnabled(this) { value = block() } return value!! diff --git a/plugins/sh/core/tests/com/intellij/sh/highlighting/ShHighlightUsagesTest.kt b/plugins/sh/core/tests/com/intellij/sh/highlighting/ShHighlightUsagesTest.kt index d89c3ca6c6ce..7d8acbbae625 100644 --- a/plugins/sh/core/tests/com/intellij/sh/highlighting/ShHighlightUsagesTest.kt +++ b/plugins/sh/core/tests/com/intellij/sh/highlighting/ShHighlightUsagesTest.kt @@ -30,7 +30,7 @@ class ShHighlightUsagesTest : BasePlatformTestCase() { } private fun doTest(vararg expectedHighlighting: String) { - IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, testRootDisposable) { + IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project) { myFixture.setReadEditorMarkupModel(true) myFixture.configureByFile(getTestName(true) + ".sh") myFixture.doHighlighting()