refactor waitForIdentifierHighlighting (part of IJPL-183582 port IdentifierHighlightingPass to the frontend)

GitOrigin-RevId: bb68a20c6f50ca65221ae77b574f52744c71335b
This commit is contained in:
Alexey Kudravtsev
2025-05-08 14:53:38 +00:00
committed by intellij-monorepo-bot
parent 788e2246e0
commit 9c989a578d
11 changed files with 29 additions and 25 deletions
@@ -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();
}
@@ -2275,7 +2275,6 @@ f:com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPassFactory
- <init>():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
- <init>():V
@@ -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();
@@ -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);
@@ -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,
@@ -17,7 +17,7 @@ public class PluginXmlIdentifierHighlightingTest extends LightJavaCodeInsightFix
}
public void test_ep_references() {
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), () -> {
IdentifierHighlighterPassFactory.doWithIdentifierHighlightingEnabled(getProject(), () -> {
myFixture.configureByText("plugin.xml", """
<idea-plugin>
@@ -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()
@@ -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) {
@@ -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<HighlightInfo> {
IdentifierHighlighterPassFactory.waitForIdentifierHighlighting()
IdentifierHighlighterPassFactory.waitForIdentifierHighlighting(editor)
return myFixture.doHighlighting().filter { it.severity === HighlightInfoType.ELEMENT_UNDER_CARET_SEVERITY }
}
@@ -548,7 +548,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
internal fun <T> Project.highlightFile(block: () -> T): T {
var value: T? = null
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(this) {
IdentifierHighlighterPassFactory.doWithIdentifierHighlightingEnabled(this) {
value = block()
}
return value!!
@@ -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()