Skip to content

Commit

Permalink
Re-implement ability to disable Mypy inspections
Browse files Browse the repository at this point in the history
  • Loading branch information
intgr committed Dec 4, 2021
1 parent fc0e9bc commit 1b72306
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/java/com/leinardi/pycharm/mypy/MypyAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@

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.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.jetbrains.python.inspections.PyPep8Inspection;
import com.leinardi.pycharm.mypy.checker.Problem;
import com.leinardi.pycharm.mypy.checker.ScanFiles;
import com.leinardi.pycharm.mypy.checker.ScannableFile;
Expand Down Expand Up @@ -49,6 +53,11 @@
* `ExternalAnnotator` cancels the previous running check (if any) before running the next one.
* <p>
* Modeled after `com.jetbrains.python.validation.Pep8ExternalAnnotator`
* <p>
* IDE calls methods in three phases:
* 1. `State collectInformation(PsiFile)`: preparation
* 2. `Results doAnnotate(State)`: called in the background.
* 3. `void apply(PsiFile, State, AnnotationHolder)`: apply the annotations to the editor.
*/
public class MypyAnnotator extends ExternalAnnotator<MypyAnnotator.State, MypyAnnotator.Results> {
/* Inner classes storing intermediate results */
Expand Down Expand Up @@ -95,6 +104,15 @@ public State collectInformation(@NotNull PsiFile file) {
+ " modified=" + file.getModificationStamp()
+ " thread=" + Thread.currentThread().getName()
);

final InspectionProfile profile =
InspectionProjectProfileManager.getInstance(file.getProject()).getCurrentProfile();
final HighlightDisplayKey key = HighlightDisplayKey.find(PyPep8Inspection.INSPECTION_SHORT_NAME);
if (!profile.isToolEnabled(key, file)) {
LOG.debug("Mypy inspection disabled");
return null;
}

return new State(file);
}

Expand Down

0 comments on commit 1b72306

Please sign in to comment.