Skip to content

Commit

Permalink
Use severity level from inspection profile
Browse files Browse the repository at this point in the history
  • Loading branch information
intgr committed Dec 4, 2021
1 parent ce8e226 commit 0df2c86
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
12 changes: 11 additions & 1 deletion src/main/java/com/leinardi/pycharm/mypy/MypyAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@

package com.leinardi.pycharm.mypy;

import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.lang.annotation.ExternalAnnotator;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.Project;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.psi.PsiFile;
import com.leinardi.pycharm.mypy.checker.Problem;
import com.leinardi.pycharm.mypy.checker.ScanFiles;
Expand Down Expand Up @@ -160,9 +164,15 @@ public void apply(@NotNull PsiFile file, Results results, @NotNull AnnotationHol

LOG.debug("Applying " + results.issues.size() + " annotations for " + file.getName());

// Get severity from inspection profile
final InspectionProfile profile =
InspectionProjectProfileManager.getInstance(file.getProject()).getCurrentProfile();
final HighlightDisplayKey key = HighlightDisplayKey.find(MypyBatchInspection.INSPECTION_SHORT_NAME);
HighlightSeverity severity = profile.getErrorLevel(key, file).getSeverity();

for (Problem problem : results.issues) {
LOG.debug(" " + problem.getLine() + ": " + problem.getMessage());
problem.createAnnotation(holder);
problem.createAnnotation(holder, severity);
}
}

Expand Down
18 changes: 2 additions & 16 deletions src/main/java/com/leinardi/pycharm/mypy/checker/Problem.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public Problem(final PsiElement target,
this.suppressErrors = suppressErrors;
}

public void createAnnotation(@NotNull AnnotationHolder holder) {
public void createAnnotation(@NotNull AnnotationHolder holder, @NotNull HighlightSeverity severity) {
String message = MypyBundle.message("inspection.message", getMessage());
AnnotationBuilder annotation = holder
.newAnnotation(getHighlightSeverity(), message)
.newAnnotation(severity, message)
.range(target.getTextRange());
if (isAfterEndOfLine()) {
annotation = annotation.afterEndOfLine();
Expand All @@ -67,20 +67,6 @@ public SeverityLevel getSeverityLevel() {
return severityLevel;
}

@NotNull
public HighlightSeverity getHighlightSeverity() {
switch (severityLevel) {
case ERROR:
return HighlightSeverity.ERROR;
case WARNING:
case NOTE: // WEAK_WARNING can be a bit difficult to see, use WARNING instead
return HighlightSeverity.WARNING;
default:
assert false : "Unhandled SeverityLevel: " + severityLevel;
}
return null;
}

public int getLine() {
return line;
}
Expand Down

0 comments on commit 0df2c86

Please sign in to comment.