From 9c989a578d4fdbda5a68eac31c3429fe22271bec Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 8 May 2025 14:49:48 +0200 Subject: [PATCH] refactor waitForIdentifierHighlighting (part of IJPL-183582 port IdentifierHighlightingPass to the frontend) GitOrigin-RevId: bb68a20c6f50ca65221ae77b574f52744c71335b --- .../highlighting/HighlightUsagesHandlerTest.java | 6 +++--- platform/lang-impl/api-dump-unreviewed.txt | 1 - .../impl/IdentifierHighlighterPassFactory.java | 15 ++++++++++++--- .../intellij/testFramework/EditorTestUtil.java | 2 +- .../fixtures/impl/CodeInsightTestFixtureImpl.java | 10 +++------- .../PluginXmlIdentifierHighlightingTest.java | 2 +- .../EditorConfigHighlightUsagesTest.kt | 2 +- .../highlighting/GroovyHighlightUsagesTest.java | 2 +- .../java/decompiler/IdeaDecompilerTest.kt | 10 +++++----- .../perf/live/AbstractPerformanceProjectsTest.kt | 2 +- .../sh/highlighting/ShHighlightUsagesTest.kt | 2 +- 11 files changed, 29 insertions(+), 25 deletions(-) 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 1a05b74ebce8..50ced379bbe8 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(), ()->{ + IdentifierHighlighterPassFactory.doWithIdentifierHighlightingEnabled(getProject(), ()->{ try { createClass(""" @@ -283,7 +283,7 @@ public class HighlightUsagesHandlerTest extends DaemonAnalyzerTestCase { } }"""); - IdentifierHighlighterPassFactory.waitForIdentifierHighlighting(); + IdentifierHighlighterPassFactory.waitForIdentifierHighlighting(getEditor()); assertEquals(2, getIdentifierHighlighters() .stream() @@ -329,7 +329,7 @@ public class HighlightUsagesHandlerTest extends DaemonAnalyzerTestCase { } public void testMethodParameterEndOfIdentifier() { - IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), ()-> { + IdentifierHighlighterPassFactory.doWithIdentifierHighlightingEnabled(getProject(), ()-> { try { configureFile(); } diff --git a/platform/lang-impl/api-dump-unreviewed.txt b/platform/lang-impl/api-dump-unreviewed.txt index 552668eb795c..27db547a6241 100644 --- a/platform/lang-impl/api-dump-unreviewed.txt +++ b/platform/lang-impl/api-dump-unreviewed.txt @@ -2275,7 +2275,6 @@ 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:isEnabled():Z -- s:waitForIdentifierHighlighting():V c:com.intellij.codeInsight.daemon.impl.IndentGuideRenderer - com.intellij.openapi.editor.markup.CustomHighlighterRenderer - ():V 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 4932e345a617..891d6c272961 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 @@ -7,6 +7,9 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.impl.NonBlockingReadActionImpl; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.fileEditor.FileEditor; +import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.fileEditor.TextEditor; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; @@ -47,20 +50,26 @@ public final class IdentifierHighlighterPassFactory { @TestOnly @RequiresEdt @ApiStatus.Internal - public static void doWithHighlightingEnabled(@NotNull Project project, @NotNull Runnable r) { + public static void doWithIdentifierHighlightingEnabled(@NotNull Project project, @NotNull Runnable r) { ThreadingAssertions.assertEventDispatchThread(); BackgroundHighlighter.Companion.runWithEnabledListenersInTest(project, ()-> { try { TestModeFlags.runWithFlag(ourTestingIdentifierHighlighting, true, r); } finally { - waitForIdentifierHighlighting(); + for (FileEditor fileEditor : FileEditorManager.getInstance(project).getAllEditors()) { + if (fileEditor instanceof TextEditor te) { + waitForIdentifierHighlighting(te.getEditor()); + } + } } }); } + @ApiStatus.Internal @TestOnly - public static void waitForIdentifierHighlighting() { + @RequiresEdt + public static void waitForIdentifierHighlighting(@NotNull Editor editor) { // wait for async "highlight identifier" computation to apply in com.intellij.codeInsight.highlighting.BackgroundHighlighter.updateHighlighted NonBlockingReadActionImpl.waitForAsyncTaskCompletion(); NonBlockingReadActionImpl.waitForAsyncTaskCompletion(); diff --git a/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java index 03b8338fdc36..7c71b00ead37 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(), () -> { + IdentifierHighlighterPassFactory.doWithIdentifierHighlightingEnabled(fixture.getProject(), () -> { for (Integer caretsOffset : caretsOffsets) { if (caretsOffset != -1) { caretModel.moveToOffset(caretsOffset); diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index be30684ada41..aac03f1cbca2 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -308,7 +308,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig if (policy != null) { policy.waitForHighlighting(project, editor); } - IdentifierHighlighterPassFactory.waitForIdentifierHighlighting(); + IdentifierHighlighterPassFactory.waitForIdentifierHighlighting(editor); waitForLazyQuickFixesUnderCaret(psiFile, editor); UIUtil.dispatchAllInvocationEvents(); Segment focusModeRange = (editor instanceof EditorImpl) ? ((EditorImpl)editor).getFocusModeRange() : null; @@ -574,7 +574,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig if (filePaths.length > 0) { configureByFilesInner(filePaths); } - return collectAndCheckHighlighting(checkWarnings, checkInfos, checkWeakWarnings); + return collectAndCheckHighlighting(checkWarnings, checkInfos, checkWeakWarnings, false); } @Override @@ -637,7 +637,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @Override public long testHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, @NotNull VirtualFile file) { openFileInEditor(file); - return collectAndCheckHighlighting(checkWarnings, checkInfos, checkWeakWarnings); + return collectAndCheckHighlighting(checkWarnings, checkInfos, checkWeakWarnings, false); } @Override @@ -1732,10 +1732,6 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig return editor; } - private long collectAndCheckHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings) { - return collectAndCheckHighlighting(checkWarnings, checkInfos, checkWeakWarnings, false); - } - private long collectAndCheckHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, 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 73f972f84aca..b2251d9fa4eb 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(), () -> { + IdentifierHighlighterPassFactory.doWithIdentifierHighlightingEnabled(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 b1624273aec2..f508c4193d12 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, Runnable { + IdentifierHighlighterPassFactory.doWithIdentifierHighlightingEnabled (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 605f92d95606..ef53f38d453d 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(), () -> { + IdentifierHighlighterPassFactory.doWithIdentifierHighlightingEnabled(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 0f27b9baaa91..ee8f22e07dcd 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, Runnable { + IdentifierHighlighterPassFactory.doWithIdentifierHighlightingEnabled(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, Runnable { + IdentifierHighlighterPassFactory.doWithIdentifierHighlightingEnabled(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, Runnable { + IdentifierHighlighterPassFactory.doWithIdentifierHighlightingEnabled(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, Runnable { + IdentifierHighlighterPassFactory.doWithIdentifierHighlightingEnabled(project, Runnable { val infos = myFixture.doHighlighting() .filter { it.severity === HighlightInfoType.SYMBOL_TYPE_SEVERITY } val texts = infos.map { it.text }.toSet() @@ -239,7 +239,7 @@ class IdeaDecompilerTest : LightJavaCodeInsightFixtureTestCase() { } private fun highlightUnderCaret(): List { - IdentifierHighlighterPassFactory.waitForIdentifierHighlighting() + IdentifierHighlighterPassFactory.waitForIdentifierHighlighting(editor) return myFixture.doHighlighting().filter { it.severity === HighlightInfoType.ELEMENT_UNDER_CARET_SEVERITY } } 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 92b20c0d8f16..d8b3073fe519 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) { + IdentifierHighlighterPassFactory.doWithIdentifierHighlightingEnabled(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 7d8acbbae625..fc29d4dcbe9f 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) { + IdentifierHighlighterPassFactory.doWithIdentifierHighlightingEnabled(project) { myFixture.setReadEditorMarkupModel(true) myFixture.configureByFile(getTestName(true) + ".sh") myFixture.doHighlighting()