mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fd5e6319a3
commit
7bf24ac4f3
+2
-2
@@ -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();
|
||||
}
|
||||
|
||||
+4
-6
@@ -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<caret>");
|
||||
DisabledQuickFixAnnotator.FIX_ENABLED = true;
|
||||
assertEmpty(doHighlighting());
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
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
|
||||
-226
@@ -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<PsiFile, HighlightInfo> 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<Pair<PsiFile,HighlightInfo>> 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<Pair<PsiFile, HighlightInfo>> 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<Pair<PsiFile, HighlightInfo>> 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<TextEditorHighlightingPass> passes = passRegistrarEx.instantiateMainPasses(file, document, HighlightInfoProcessor.getEmpty());
|
||||
List<GeneralHighlightingPass> 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<Pair<PsiFile, HighlightInfo>> 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<HighlightInfo> infos = pass.getInfos();
|
||||
for (HighlightInfo info : infos) {
|
||||
if (info != null && info.getSeverity().compareTo(HighlightSeverity.INFORMATION) > 0) {
|
||||
result.add(Pair.create(file, info));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -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<IntentionAction> actions = Collections.emptyList();
|
||||
if (myProblemGroup instanceof SuppressableProblemGroup) {
|
||||
actions = Arrays.asList(((SuppressableProblemGroup)myProblemGroup).getSuppressActions(element));
|
||||
|
||||
+150
@@ -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<HighlightInfo> 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<TextEditorHighlightingPass> passes = passRegistrarEx.instantiateMainPasses(file, document, HighlightInfoProcessor.getEmpty());
|
||||
List<GeneralHighlightingPass> 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<HighlightInfo> 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<HighlightInfo> infos = pass.getInfos();
|
||||
for (HighlightInfo info : infos) {
|
||||
if (info != null && info.getSeverity().compareTo(HighlightSeverity.INFORMATION) > 0) {
|
||||
result.add(info);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,14 @@
|
||||
<html>
|
||||
<body>
|
||||
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:
|
||||
<ul>
|
||||
<li>Option "<b>Highlight syntax errors</b>" allows to report parser-related issues.</li>
|
||||
<li>Option "<b>Run language annotators</b>" allows to report issues found by annotators configured for this language.
|
||||
See <a href="https://plugins.jetbrains.com/docs/intellij/annotator.html">Custom Language Support: Annotators</a> for details.</li>
|
||||
<li>Option "<b>Run language-specific highlight visitors</b>" allows to report issues inherent to this file language (e.g., type mismatches or unreported exceptions etc.).
|
||||
See <a href="https://plugins.jetbrains.com/docs/intellij/syntax-highlighting-and-error-highlighting.html#semantic-highlighting">Custom Language Support: Highlighting</a> for details.</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,5 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports generic errors that have been found in the result of a batch code inspection run.
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,5 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports syntax errors that have been found in the result of a batch code inspection run.
|
||||
</body>
|
||||
</html>
|
||||
@@ -1073,17 +1073,9 @@
|
||||
<applicationService serviceImplementation="com.intellij.ui.debugger.extensions.PlaybackDebugger$PlaybackDebuggerState"/>
|
||||
|
||||
<globalInspection shortName="Annotator" groupKey="inspection.general.tools.group.name" groupBundle="messages.InspectionsBundle"
|
||||
enabledByDefault="true" level="ERROR"
|
||||
bundle="messages.LangBundle" key="display.name.annotator"
|
||||
implementationClass="com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitorBasedInspection$AnnotatorBasedInspection"/>
|
||||
<globalInspection shortName="SyntaxError" groupKey="inspection.general.tools.group.name" groupBundle="messages.InspectionsBundle"
|
||||
enabledByDefault="true" level="ERROR"
|
||||
bundle="messages.LangBundle" key="display.name.syntax.error"
|
||||
implementationClass="com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitorBasedInspection$SyntaxErrorInspection"/>
|
||||
<globalInspection shortName="GenericError" groupKey="inspection.general.tools.group.name" groupBundle="messages.InspectionsBundle"
|
||||
enabledByDefault="false" level="ERROR"
|
||||
bundle="messages.LangBundle" key="display.name.generic.error"
|
||||
implementationClass="com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitorBasedInspection$GenericErrorInspection"/>
|
||||
bundle="messages.InspectionsBundle" key="inspection.annotator.display.name"
|
||||
implementationClass="com.intellij.codeInsight.daemon.impl.HighlightVisitorBasedInspection"/>
|
||||
<localInspection shortName="LossyEncoding" bundle="messages.LangBundle" key="lossy.encoding"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.internationalization.issues" enabledByDefault="true"
|
||||
level="WARNING"
|
||||
|
||||
+12
-2
@@ -1,7 +1,12 @@
|
||||
package com.jetbrains.performancePlugin.commands;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitorBasedInspection;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightVisitorBasedInspection;
|
||||
import com.intellij.codeInspection.GlobalInspectionContext;
|
||||
import com.intellij.codeInspection.GlobalInspectionTool;
|
||||
import com.intellij.codeInspection.InspectionEngine;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper;
|
||||
import com.intellij.diagnostic.telemetry.TraceUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
@@ -62,7 +67,12 @@ public final class DoHighlighting extends PerformanceCommand {
|
||||
ReadAction.nonBlocking(Context.current().wrap((Callable<Void>)() -> {
|
||||
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())));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user