FIR IDE: do not report suppressed diagnostics

This commit is contained in:
Ilya Kirillov
2021-03-25 16:04:25 +01:00
parent fd082b1574
commit ce62348709
3 changed files with 17 additions and 10 deletions
@@ -5,7 +5,9 @@
package org.jetbrains.kotlin.fir.analysis.checkers.context
import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.expressions.FirGetClassCall
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess
@@ -39,6 +41,18 @@ abstract class CheckerContext {
allWarningsSuppressed: Boolean,
allErrorsSuppressed: Boolean
): PersistentCheckerContext
fun isDiagnosticSuppressed(diagnostic: FirDiagnostic<*>): Boolean {
val factory = diagnostic.factory
val name = factory.name
val suppressedByAll = when (factory.severity) {
Severity.INFO -> allInfosSuppressed
Severity.WARNING -> allWarningsSuppressed
Severity.ERROR -> allErrorsSuppressed
}
return suppressedByAll || name in suppressedDiagnostics
}
}
/**
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.fir.analysis.diagnostics.impl
import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic
@@ -16,15 +15,8 @@ class DiagnosticReporterWithSuppress : BaseDiagnosticReporter() {
override fun report(diagnostic: FirDiagnostic<*>?, context: CheckerContext) {
if (diagnostic == null) return
val factory = diagnostic.factory
val name = factory.name
val suppressedByAll = when (factory.severity) {
Severity.INFO -> context.allInfosSuppressed
Severity.WARNING -> context.allWarningsSuppressed
Severity.ERROR -> context.allErrorsSuppressed
if (!context.isDiagnosticSuppressed(diagnostic)) {
_diagnostics += diagnostic
}
if (suppressedByAll || name in context.suppressedDiagnostics) return
_diagnostics += diagnostic
}
}
@@ -54,6 +54,7 @@ internal abstract class AbstractFirIdeDiagnosticsCollector(
private inner class Reporter : DiagnosticReporter() {
override fun report(diagnostic: FirDiagnostic<*>?, context: CheckerContext) {
if (diagnostic !is FirPsiDiagnostic<*>) return
if (context.isDiagnosticSuppressed(diagnostic)) return
onDiagnostic(diagnostic)
}
}