diff --git a/src/main/java/com/leinardi/pycharm/mypy/MypyAnnotator.java b/src/main/java/com/leinardi/pycharm/mypy/MypyAnnotator.java index d0ace6c..2b7eb48 100644 --- a/src/main/java/com/leinardi/pycharm/mypy/MypyAnnotator.java +++ b/src/main/java/com/leinardi/pycharm/mypy/MypyAnnotator.java @@ -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; @@ -49,6 +53,11 @@ * `ExternalAnnotator` cancels the previous running check (if any) before running the next one. *

* Modeled after `com.jetbrains.python.validation.Pep8ExternalAnnotator` + *

+ * 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 { /* Inner classes storing intermediate results */ @@ -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); }