From 7bf24ac4f3c307e7acb674b8a9a3c252f2a0ce3c Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 10 Feb 2023 12:44:50 +0100 Subject: [PATCH] replace three similar inspections "syntax error", "generic error", "annotator" with one "annotator" to simplify code and reduce complexity/UI burden for a user GitOrigin-RevId: 7153708a721abdffa755f41c2530d7ccc142e500 --- .../quickfix/FixAllAnnotatorQuickfixTest.java | 4 +- .../LightAnnotatorHighlightingTest.java | 10 +- .../codeInspection/RedundantSuppressTest.java | 4 +- .../messages/InspectionsBundle.properties | 7 +- ...efaultHighlightVisitorBasedInspection.java | 226 ------------------ .../daemon/impl/HighlightInfo.java | 7 +- .../impl/HighlightVisitorBasedInspection.java | 150 ++++++++++++ .../src/inspectionDescriptions/Annotator.html | 11 +- .../inspectionDescriptions/GenericError.html | 5 - .../inspectionDescriptions/SyntaxError.html | 5 - .../src/META-INF/LangExtensions.xml | 12 +- .../commands/DoHighlighting.java | 14 +- 12 files changed, 191 insertions(+), 264 deletions(-) delete mode 100644 platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightVisitorBasedInspection.java create mode 100644 platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightVisitorBasedInspection.java delete mode 100644 platform/platform-resources-en/src/inspectionDescriptions/GenericError.html delete mode 100644 platform/platform-resources-en/src/inspectionDescriptions/SyntaxError.html diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/quickfix/FixAllAnnotatorQuickfixTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/quickfix/FixAllAnnotatorQuickfixTest.java index 03da3d746a6b..7eaae2833eec 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/quickfix/FixAllAnnotatorQuickfixTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/quickfix/FixAllAnnotatorQuickfixTest.java @@ -2,7 +2,7 @@ package com.intellij.codeInsight.daemon.impl.quickfix; -import com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitorBasedInspection; +import com.intellij.codeInsight.daemon.impl.HighlightVisitorBasedInspection; import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.LocalQuickFix; @@ -28,7 +28,7 @@ public class FixAllAnnotatorQuickfixTest extends LightQuickFixTestCase { Annotator annotator = new MyAnnotator(); Language javaLanguage = JavaFileType.INSTANCE.getLanguage(); LanguageAnnotators.INSTANCE.addExplicitExtension(javaLanguage, annotator); - enableInspectionTool(new DefaultHighlightVisitorBasedInspection.AnnotatorBasedInspection()); + enableInspectionTool(new HighlightVisitorBasedInspection().setRunAnnotators(true)); try { doAllTests(); } diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAnnotatorHighlightingTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAnnotatorHighlightingTest.java index 2180cafdfe59..ceef50ec7716 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAnnotatorHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAnnotatorHighlightingTest.java @@ -7,10 +7,7 @@ import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; import com.intellij.codeInsight.daemon.impl.*; import com.intellij.codeInsight.daemon.impl.quickfix.DeleteElementFix; import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.codeInspection.LocalQuickFix; -import com.intellij.codeInspection.ProblemDescriptor; -import com.intellij.codeInspection.ProblemHighlightType; -import com.intellij.codeInspection.QuickFix; +import com.intellij.codeInspection.*; import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase; import com.intellij.diagnostic.PluginException; import com.intellij.ide.highlighter.JavaFileType; @@ -529,8 +526,9 @@ public class LightAnnotatorHighlightingTest extends LightDaemonAnalyzerTestCase * Checks that the Platform doesn't add useless "Inspection 'Annotator' options" quick fix. see https://youtrack.jetbrains.com/issue/WEB-55217 */ public void testNoFixesOrOptionsMustBeShownWhenAnnotatorProvidedQuickFixWhichIsDisabled() { - enableInspectionTool(new DefaultHighlightVisitorBasedInspection.AnnotatorBasedInspection()); - assertNotNull(HighlightDisplayKey.find("Annotator")); + GlobalInspectionTool tool = new HighlightVisitorBasedInspection().setRunAnnotators(true); + enableInspectionTool(tool); + assertNotNull(HighlightDisplayKey.find(tool.getShortName())); configureFromFileText("foo.txt", "hello"); DisabledQuickFixAnnotator.FIX_ENABLED = true; assertEmpty(doHighlighting()); diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/RedundantSuppressTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/RedundantSuppressTest.java index 99415553139d..111741a05ba3 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/RedundantSuppressTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/RedundantSuppressTest.java @@ -1,7 +1,7 @@ // Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.java.codeInspection; -import com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitorBasedInspection; +import com.intellij.codeInsight.daemon.impl.HighlightVisitorBasedInspection; import com.intellij.codeInspection.InspectionProfile; import com.intellij.codeInspection.PossibleHeapPollutionVarargsInspection; import com.intellij.codeInspection.RedundantSuppressInspection; @@ -42,7 +42,7 @@ public class RedundantSuppressTest extends JavaInspectionTestCase { new LocalInspectionToolWrapper(new UnnecessaryUnicodeEscapeInspection()), new LocalInspectionToolWrapper(new RefusedBequestInspection()), new GlobalInspectionToolWrapper(new EmptyMethodInspection()), - new GlobalInspectionToolWrapper(new DefaultHighlightVisitorBasedInspection.AnnotatorBasedInspection()), + new GlobalInspectionToolWrapper(new HighlightVisitorBasedInspection().setRunAnnotators(true)), new GlobalInspectionToolWrapper(new UnusedDeclarationInspection())); myWrapper = new GlobalInspectionToolWrapper(new RedundantSuppressInspection() { diff --git a/platform/analysis-api/resources/messages/InspectionsBundle.properties b/platform/analysis-api/resources/messages/InspectionsBundle.properties index 61ba21f8a060..618b21da6ec3 100644 --- a/platform/analysis-api/resources/messages/InspectionsBundle.properties +++ b/platform/analysis-api/resources/messages/InspectionsBundle.properties @@ -346,4 +346,9 @@ inspection.mismatch.javadoc.reason.boolean=Method is specified to return ''{0}'' inspection.mismatch.javadoc.reason.different.type=Method is specified to return {0} but the return type is {1} inspection.mismatch.javadoc.reason.single.collection=Method is specified to return a single {0} but the return type is a collection -js.inspection.group.path=JavaScript and TypeScript \ No newline at end of file +js.inspection.group.path=JavaScript and TypeScript + +inspection.annotator.display.name=Annotator +inspection.annotator.option.highlight.syntax=Highlight syntax errors +inspection.annotator.option.run.annotators=Run language annotators +inspection.annotator.option.run.highlight.visitors=Run language-specific highlight visitors \ No newline at end of file diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightVisitorBasedInspection.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightVisitorBasedInspection.java deleted file mode 100644 index 4fde5e2f7a31..000000000000 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightVisitorBasedInspection.java +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.codeInsight.daemon.impl; - -import com.intellij.analysis.AnalysisBundle; -import com.intellij.codeHighlighting.HighlightDisplayLevel; -import com.intellij.codeHighlighting.TextEditorHighlightingPass; -import com.intellij.codeInspection.*; -import com.intellij.codeInspection.ex.GlobalInspectionContextBase; -import com.intellij.diagnostic.telemetry.IJTracer; -import com.intellij.diagnostic.telemetry.TraceManager; -import com.intellij.lang.annotation.HighlightSeverity; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.ProperTextRange; -import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiDocumentManager; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiElementVisitor; -import com.intellij.psi.PsiFile; -import com.intellij.util.containers.ContainerUtil; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static com.intellij.diagnostic.telemetry.TraceKt.runWithSpan; - -public abstract class DefaultHighlightVisitorBasedInspection extends GlobalSimpleInspectionTool { - private final boolean highlightErrorElements; - private final boolean runAnnotators; - private boolean replaceVisitors; - - protected DefaultHighlightVisitorBasedInspection(boolean highlightErrorElements, boolean runAnnotators, boolean visitors) { - this.highlightErrorElements = highlightErrorElements; - this.runAnnotators = runAnnotators; - replaceVisitors = visitors; - } - - public static class AnnotatorBasedInspection extends DefaultHighlightVisitorBasedInspection { - static final @NonNls String ANNOTATOR_SHORT_NAME = "Annotator"; - - public AnnotatorBasedInspection() { - super(false, true, true); - } - - @Override - public @Nls @NotNull String getDisplayName() { - return AnalysisBundle.message("inspection.display.name.annotator"); - } - - @Override - public @NotNull String getShortName() { - return ANNOTATOR_SHORT_NAME; - } - - } - public static class SyntaxErrorInspection extends DefaultHighlightVisitorBasedInspection { - public SyntaxErrorInspection() { - super(true, false, true); - } - @Nls - @NotNull - @Override - public String getDisplayName() { - return AnalysisBundle.message("inspection.display.name.syntax.error"); - } - - @NotNull - @Override - public String getShortName() { - return "SyntaxError"; - } - } - - public static class GenericErrorInspection extends DefaultHighlightVisitorBasedInspection { - public GenericErrorInspection() { - super(true, true, false); - } - @Nls - @NotNull - @Override - public String getDisplayName() { - return AnalysisBundle.message("inspection.display.name.generic.error"); - } - - @NotNull - @Override - public String getShortName() { - return "GenericError"; - } - } - - @NotNull - @Override - public HighlightDisplayLevel getDefaultLevel() { - return HighlightDisplayLevel.ERROR; - } - - @Override - public void checkFile(@NotNull PsiFile originalFile, - @NotNull InspectionManager manager, - @NotNull ProblemsHolder problemsHolder, - @NotNull GlobalInspectionContext globalContext, - @NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) { - for (Pair pair : runAnnotatorsInGeneralHighlighting(originalFile, highlightErrorElements, runAnnotators, - replaceVisitors)) { - PsiFile file = pair.first; - HighlightInfo info = pair.second; - TextRange range = new TextRange(info.startOffset, info.endOffset); - PsiElement element = file.findElementAt(info.startOffset); - - while (element != null && !element.getTextRange().contains(range)) { - element = element.getParent(); - } - - if (element == null) { - element = file; - } - - GlobalInspectionUtil.createProblem(element, info, range.shiftRight(-element.getNode().getStartOffset()), - info.getProblemGroup(), manager, problemDescriptionsProcessor, globalContext); - } - } - - @NotNull - public static List> runAnnotatorsInGeneralHighlighting(@NotNull PsiFile file, - boolean highlightErrorElements, - boolean runAnnotators, - boolean replaceVisitors) { - ProgressIndicator indicator = ProgressManager.getGlobalProgressIndicator(); - MyPsiElementVisitor visitor = new MyPsiElementVisitor(highlightErrorElements, runAnnotators, replaceVisitors); - if (indicator instanceof DaemonProgressIndicator) { - file.accept(visitor); - } - else { - DaemonProgressIndicator progress = new DaemonProgressIndicator(); - HighlightingSessionImpl.createHighlightingSession(file, progress, null, ProperTextRange.create(file.getTextRange()), CanISilentlyChange.Result.UH_UH); - ProgressManager.getInstance().runProcess(() -> file.accept(visitor), progress); - } - return visitor.result; - } - - @Nls - @NotNull - @Override - public String getGroupDisplayName() { - return getGeneralGroupName(); - } - - private static class MyPsiElementVisitor extends PsiElementVisitor { - private final boolean highlightErrorElements; - private final boolean runAnnotators; - private final List> result = new ArrayList<>(); - private boolean replaceVisitors; - - MyPsiElementVisitor(boolean highlightErrorElements, boolean runAnnotators, boolean replaceVisitors) { - this.highlightErrorElements = highlightErrorElements; - this.runAnnotators = runAnnotators; - this.replaceVisitors = replaceVisitors; - } - - @Override - public void visitFile(@NotNull PsiFile file) { - VirtualFile virtualFile = file.getVirtualFile(); - if (virtualFile == null) { - return; - } - - result.addAll(runAnnotatorsInGeneralHighlightingPass(file, highlightErrorElements, runAnnotators, replaceVisitors)); - } - } - - @NotNull - private static List> runAnnotatorsInGeneralHighlightingPass(@NotNull PsiFile file, - boolean highlightErrorElements, - boolean runAnnotators, - boolean replaceVisitors) { - Project project = file.getProject(); - Document document = PsiDocumentManager.getInstance(project).getDocument(file); - if (document == null) return Collections.emptyList(); - ProgressIndicator progress = ProgressManager.getGlobalProgressIndicator(); - DaemonProgressIndicator daemonProgressIndicator = GlobalInspectionContextBase.assertUnderDaemonProgress(); - HighlightingSessionImpl.getOrCreateHighlightingSession(file, daemonProgressIndicator, ProperTextRange.create(file.getTextRange())); - TextEditorHighlightingPassRegistrarEx passRegistrarEx = TextEditorHighlightingPassRegistrarEx.getInstanceEx(project); - List passes = passRegistrarEx.instantiateMainPasses(file, document, HighlightInfoProcessor.getEmpty()); - List gpasses = ContainerUtil.filterIsInstance(passes, GeneralHighlightingPass.class); - if (replaceVisitors) { - for (GeneralHighlightingPass gpass : gpasses) { - gpass.setHighlightVisitorProducer(() -> { - gpass.incVisitorUsageCount(1); - - HighlightVisitor visitor = new DefaultHighlightVisitor(project, highlightErrorElements, runAnnotators, true); - return new HighlightVisitor[]{visitor}; - }); - } - } - - String fileName = file.getName(); - List> result = new ArrayList<>(); - IJTracer tracer = TraceManager.INSTANCE.getTracer("highlightVisitor", true); - - for (TextEditorHighlightingPass pass : gpasses) { - runWithSpan(tracer, pass.getClass().getSimpleName(), span -> { - span.setAttribute("file", fileName); - - pass.doCollectInformation(progress); - List infos = pass.getInfos(); - for (HighlightInfo info : infos) { - if (info != null && info.getSeverity().compareTo(HighlightSeverity.INFORMATION) > 0) { - result.add(Pair.create(file, info)); - } - } - }); - } - - return result; - } -} diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java index f3cc525c3200..2ab2e55b0f7d 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java @@ -4,7 +4,6 @@ package com.intellij.codeInsight.daemon.impl; import com.intellij.codeHighlighting.Pass; import com.intellij.codeInsight.daemon.GutterMark; import com.intellij.codeInsight.daemon.HighlightDisplayKey; -import com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitorBasedInspection.AnnotatorBasedInspection; import com.intellij.codeInsight.daemon.impl.actions.DisableHighlightingIntentionAction; import com.intellij.codeInsight.daemon.impl.actions.IntentionActionWithFixAllOption; import com.intellij.codeInsight.intention.*; @@ -609,7 +608,7 @@ public class HighlightInfo implements Segment { for (Annotation.QuickFixInfo quickFixInfo : fixes) { TextRange range = quickFixInfo.textRange; HighlightDisplayKey k = quickFixInfo.key != null ? quickFixInfo.key - : HighlightDisplayKey.find(AnnotatorBasedInspection.ANNOTATOR_SHORT_NAME); + : HighlightDisplayKey.find(HighlightVisitorBasedInspection.SHORT_NAME); info.registerFix(quickFixInfo.quickFix, null, HighlightDisplayKey.getDisplayNameByKey(k), range, k); } } @@ -707,7 +706,7 @@ public class HighlightInfo implements Segment { } @Nullable IntentionActionDescriptor copyWithEmptyAction() { - if (myKey == null || myKey.getID().equals(AnnotatorBasedInspection.ANNOTATOR_SHORT_NAME)) { + if (myKey == null || myKey.getID().equals(HighlightVisitorBasedInspection.SHORT_NAME)) { // No need to show "Inspection 'Annotator' options" quick fix, it wouldn't be actionable. return null; } @@ -794,7 +793,7 @@ public class HighlightInfo implements Segment { InspectionProfileEntry wrappedTool = toolWrapper instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)toolWrapper).getTool() : ((GlobalInspectionToolWrapper)toolWrapper).getTool(); - if (wrappedTool instanceof DefaultHighlightVisitorBasedInspection.AnnotatorBasedInspection) { + if (wrappedTool instanceof HighlightVisitorBasedInspection) { List actions = Collections.emptyList(); if (myProblemGroup instanceof SuppressableProblemGroup) { actions = Arrays.asList(((SuppressableProblemGroup)myProblemGroup).getSuppressActions(element)); diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightVisitorBasedInspection.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightVisitorBasedInspection.java new file mode 100644 index 000000000000..04b6d66f1260 --- /dev/null +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightVisitorBasedInspection.java @@ -0,0 +1,150 @@ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + +package com.intellij.codeInsight.daemon.impl; + +import com.intellij.codeHighlighting.HighlightDisplayLevel; +import com.intellij.codeHighlighting.TextEditorHighlightingPass; +import com.intellij.codeInspection.*; +import com.intellij.codeInspection.ex.GlobalInspectionContextBase; +import com.intellij.codeInspection.options.OptPane; +import com.intellij.diagnostic.telemetry.IJTracer; +import com.intellij.diagnostic.telemetry.TraceManager; +import com.intellij.lang.annotation.HighlightSeverity; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.ProperTextRange; +import com.intellij.openapi.util.TextRange; +import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static com.intellij.codeInspection.options.OptPane.checkbox; +import static com.intellij.diagnostic.telemetry.TraceKt.runWithSpan; + +public class HighlightVisitorBasedInspection extends GlobalSimpleInspectionTool { + public static final String SHORT_NAME = "Annotator"; + public boolean highlightErrorElements = true; + public boolean runAnnotators = false; + public boolean runVisitors = false; + + @Override + public @NotNull OptPane getOptionsPane() { + return OptPane.pane( + checkbox("highlightErrorElements", InspectionsBundle.message("inspection.annotator.option.highlight.syntax")), + checkbox("runAnnotators", InspectionsBundle.message("inspection.annotator.option.run.annotators")), + checkbox("runVisitors", InspectionsBundle.message("inspection.annotator.option.run.highlight.visitors")) + ); + } + + @NotNull + public HighlightVisitorBasedInspection setHighlightErrorElements(boolean value) { + highlightErrorElements = value; + return this; + } + @NotNull + public HighlightVisitorBasedInspection setRunAnnotators(boolean value) { + runAnnotators = value; + return this; + } + @NotNull + public HighlightVisitorBasedInspection setRunVisitors(boolean value) { + runVisitors = value; + return this; + } + + @Override + public @NotNull String getShortName() { + return SHORT_NAME; + } + + @NotNull + @Override + public HighlightDisplayLevel getDefaultLevel() { + return HighlightDisplayLevel.ERROR; + } + + @Override + public void checkFile(@NotNull PsiFile psiFile, + @NotNull InspectionManager manager, + @NotNull ProblemsHolder problemsHolder, + @NotNull GlobalInspectionContext globalContext, + @NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) { + for (HighlightInfo info : runAnnotatorsInGeneralHighlighting(psiFile, highlightErrorElements, runAnnotators, runVisitors)) { + TextRange range = new TextRange(info.startOffset, info.endOffset); + PsiElement element = psiFile.findElementAt(info.startOffset); + + while (element != null && !element.getTextRange().contains(range)) { + element = element.getParent(); + } + + if (element == null) { + element = psiFile; + } + + GlobalInspectionUtil.createProblem(element, info, range.shiftRight(-element.getNode().getStartOffset()), + info.getProblemGroup(), manager, problemDescriptionsProcessor, globalContext); + } + } + + @Nls + @NotNull + @Override + public String getGroupDisplayName() { + return getGeneralGroupName(); + } + + @NotNull + private static List runAnnotatorsInGeneralHighlighting(@NotNull PsiFile file, + boolean highlightErrorElements, + boolean runAnnotators, + boolean runVisitors) { + Project project = file.getProject(); + Document document = PsiDocumentManager.getInstance(project).getDocument(file); + if (document == null) return Collections.emptyList(); + ProgressIndicator progress = ProgressManager.getGlobalProgressIndicator(); + DaemonProgressIndicator daemonProgressIndicator = GlobalInspectionContextBase.assertUnderDaemonProgress(); + HighlightingSessionImpl.getOrCreateHighlightingSession(file, daemonProgressIndicator, ProperTextRange.create(file.getTextRange())); + TextEditorHighlightingPassRegistrarEx passRegistrarEx = TextEditorHighlightingPassRegistrarEx.getInstanceEx(project); + List passes = passRegistrarEx.instantiateMainPasses(file, document, HighlightInfoProcessor.getEmpty()); + List gpasses = ContainerUtil.filterIsInstance(passes, GeneralHighlightingPass.class); + if (!runVisitors) { + for (GeneralHighlightingPass gpass : gpasses) { + gpass.setHighlightVisitorProducer(() -> { + gpass.incVisitorUsageCount(1); + + HighlightVisitor visitor = new DefaultHighlightVisitor(project, highlightErrorElements, runAnnotators, true); + return new HighlightVisitor[]{visitor}; + }); + } + } + + String fileName = file.getName(); + List result = new ArrayList<>(); + IJTracer tracer = TraceManager.INSTANCE.getTracer("highlightVisitor", true); + + for (TextEditorHighlightingPass pass : gpasses) { + runWithSpan(tracer, pass.getClass().getSimpleName(), span -> { + span.setAttribute("file", fileName); + + pass.doCollectInformation(progress); + List infos = pass.getInfos(); + for (HighlightInfo info : infos) { + if (info != null && info.getSeverity().compareTo(HighlightSeverity.INFORMATION) > 0) { + result.add(info); + } + } + }); + } + + return result; + } +} diff --git a/platform/platform-resources-en/src/inspectionDescriptions/Annotator.html b/platform/platform-resources-en/src/inspectionDescriptions/Annotator.html index e66be0bbd04f..c9ce9fc0dc42 100644 --- a/platform/platform-resources-en/src/inspectionDescriptions/Annotator.html +++ b/platform/platform-resources-en/src/inspectionDescriptions/Annotator.html @@ -1,5 +1,14 @@ -Reports problems that are found by language annotators in the result of a batch code inspection run. +Reports issues essential to this file (e.g., syntax errors) in the result of a batch code inspection run. +These kinds of issues are usually always highlighted when you open the file in the editor and can't be configured (unlike inspections). +The options below are controlling the analysis level of this inspection: +
    +
  • Option "Highlight syntax errors" allows to report parser-related issues.
  • +
  • Option "Run language annotators" allows to report issues found by annotators configured for this language. + See Custom Language Support: Annotators for details.
  • +
  • Option "Run language-specific highlight visitors" allows to report issues inherent to this file language (e.g., type mismatches or unreported exceptions etc.). + See Custom Language Support: Highlighting for details.
  • +
\ No newline at end of file diff --git a/platform/platform-resources-en/src/inspectionDescriptions/GenericError.html b/platform/platform-resources-en/src/inspectionDescriptions/GenericError.html deleted file mode 100644 index 6aaca82705a5..000000000000 --- a/platform/platform-resources-en/src/inspectionDescriptions/GenericError.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Reports generic errors that have been found in the result of a batch code inspection run. - - \ No newline at end of file diff --git a/platform/platform-resources-en/src/inspectionDescriptions/SyntaxError.html b/platform/platform-resources-en/src/inspectionDescriptions/SyntaxError.html deleted file mode 100644 index 962f74642068..000000000000 --- a/platform/platform-resources-en/src/inspectionDescriptions/SyntaxError.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Reports syntax errors that have been found in the result of a batch code inspection run. - - \ No newline at end of file diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 71ebe8262779..80af1b520ab8 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -1073,17 +1073,9 @@ - - + bundle="messages.InspectionsBundle" key="inspection.annotator.display.name" + implementationClass="com.intellij.codeInsight.daemon.impl.HighlightVisitorBasedInspection"/> )() -> { Stopwatch timer = Stopwatch.createStarted(); TraceUtil.runWithSpanThrows(PerformanceTestSpan.TRACER, SPAN_NAME, span -> { - DefaultHighlightVisitorBasedInspection.runAnnotatorsInGeneralHighlighting(psiFile, highlightErrorElements, runAnnotators,true); + GlobalInspectionTool tool = new HighlightVisitorBasedInspection() + .setHighlightErrorElements(highlightErrorElements).setRunAnnotators(runAnnotators).setRunVisitors(false); + InspectionManager inspectionManager = InspectionManager.getInstance(project); + GlobalInspectionContext globalContext = inspectionManager.createNewGlobalContext(); + InspectionEngine.runInspectionOnFile(psiFile, new GlobalInspectionToolWrapper(tool), globalContext); + span.setAttribute("lines", editor.getDocument().getLineCount()); span.setAttribute("timeToLines", timer.stop().elapsed(TimeUnit.MILLISECONDS) / (Math.max(1, editor.getDocument().getLineCount()))); });