InspectionSuppressor only receives elements of type KtFile

I am developing a plugin that ignores suppressions for a particular kind of Kotlin constructor.

I added a dependency `on org.jetbrains.kotlin` in the plugin.xml file, and have a class that implements com.intellij.codeInspection.InspectionSuppressor. The class is registered in plugin.xml:

<extensions defaultExtensionNs="com.intellij">
    <lang.inspectionSuppressor language="kotlin" implementationClass="my.full.ClassName"/>
</extensions>

However, when I launch the plugin, the only kind of PsiElement my implementation ever receives is KtFile. Is there anything I'm missing?

5 comments
Comment actions Permalink

Added a breakpoint to spot where the calls to my implementation come from, seems they're all from:

isSuppressedFor:12, MyInspectionSuppressor (my.full.ClassName)
isSuppressed:154, InspectionProfileEntry (com.intellij.codeInspection)
isSuppressedFor:69, InspectionProfileEntry (com.intellij.codeInspection)
inspectionResultSuppressed:179, SuppressionUtil (com.intellij.codeInspection)
inspectionResultSuppressed:175, SuppressionUtil (com.intellij.codeInspection)
getInspectionTools:700, LocalInspectionsPass (com.intellij.codeInsight.daemon.impl)
getInspectionTools:93, WholeFileLocalInspectionsPassFactory$2 (com.intellij.codeInsight.daemon.impl)
collectInformationWithProgress:115, LocalInspectionsPass (com.intellij.codeInsight.daemon.impl)
doCollectInformation:84, ProgressableTextEditorHighlightingPass (com.intellij.codeInsight.daemon.impl)
collectInformation:69, TextEditorHighlightingPass (com.intellij.codeHighlighting)
lambda$null$1:423, PassExecutorService$ScheduledPass (com.intellij.codeInsight.daemon.impl)
run:-1, 1023706571 (com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass$$Lambda$1769)
tryRunReadAction:1168, ApplicationImpl (com.intellij.openapi.application.impl)
lambda$doRun$2:416, PassExecutorService$ScheduledPass (com.intellij.codeInsight.daemon.impl)
run:-1, 1017753594 (com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass$$Lambda$1768)
registerIndicatorAndRun:582, CoreProgressManager (com.intellij.openapi.progress.impl)
executeProcessUnderProgress:532, CoreProgressManager (com.intellij.openapi.progress.impl)
executeProcessUnderProgress:87, ProgressManagerImpl (com.intellij.openapi.progress.impl)
doRun:415, PassExecutorService$ScheduledPass (com.intellij.codeInsight.daemon.impl)
lambda$run$0:391, PassExecutorService$ScheduledPass (com.intellij.codeInsight.daemon.impl)
run:-1, 78319482 (com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass$$Lambda$1763)
executeByImpatientReader:147, ReadMostlyRWLock (com.intellij.openapi.application.impl)
executeByImpatientReader:222, ApplicationImpl (com.intellij.openapi.application.impl)
run:389, PassExecutorService$ScheduledPass (com.intellij.codeInsight.daemon.impl)
exec:161, JobLauncherImpl$VoidForkJoinTask$1 (com.intellij.concurrency)
doExec:289, ForkJoinTask (java.util.concurrent)
runTask:1056, ForkJoinPool$WorkQueue (java.util.concurrent)
runWorker:1692, ForkJoinPool (java.util.concurrent)
run:157, ForkJoinWorkerThread (java.util.concurrent)
0
Comment actions Permalink

Please try adding 'order="first"' to inspectionSuppressor registration in your plugin.xml

0
Comment actions Permalink

This did not seem to make any difference unfortunately.

My plugin.xml looks as follows:

<idea-plugin>
...
<idea-version since-build="173.0"/>

<depends>org.jetbrains.kotlin</depends>

<extensions defaultExtensionNs="com.intellij">
<lang.inspectionSuppressor language="kotlin" implementationClass="MySuppressor" order="first" />
</extensions>
</idea-plugin>

My implementation:

import com.intellij.codeInspection.InspectionSuppressor
import com.intellij.codeInspection.SuppressQuickFix
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.psi.KtFile

class MySuppressor : InspectionSuppressor {

override fun isSuppressedFor(element: PsiElement, toolId: String): Boolean {
if (element !is KtFile) {
throw RuntimeException("el: $element")
}
return false
}

override fun getSuppressActions(p0: PsiElement?, p1: String): Array<SuppressQuickFix> = SuppressQuickFix.EMPTY_ARRAY

}
// Test file
class
Foo {

constructor() {
}

}
0
Comment actions Permalink

Does any *enabled* inspection produce problems on given code snippet for you?

0
Comment actions Permalink

Hey Dmitry, sorry for the late reply. Just got back to this again.

Yes, inspection providers outside my plugin do, for instance the "Convert to primary constructor" one.

I changed the suppressor's language to UAST in plugin.xml, and receive all sorts of PsiElements from Java files, and was able to make it all work with Java.

Kotlin doesn't work however, as I still only get KtFile!

class UnusedConstructorInspectionSuppressor : InspectionSuppressor {

override fun isSuppressedFor(element: PsiElement, toolId: String): Boolean {
if (element !is PsiIdentifier) {
return false
}
if (toolId != UNUSED_TOOL_ID) {
return false
}
return MyPsiUtil.isExpectedConstructor(element)
}

override fun getSuppressActions(p0: PsiElement?, p1: String): Array<SuppressQuickFix> {
return SuppressQuickFix.EMPTY_ARRAY
}

companion object {
private const val UNUSED_TOOL_ID = "unused"
}

}
0

Please sign in to leave a comment.