Skip to content

Commit 309e012

Browse files
[lsp] LSP-204: Do not display diagnostics that shouldn't be shown
Merge-request: IJ-MR-171586 Merged-by: Pavel Mikhailovskii <[email protected]> GitOrigin-RevId: 578667568b54215b24b3254dfeceb4469fb6e73d
1 parent 1e935b0 commit 309e012

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

features-impl/common/src/com/jetbrains/ls/api/features/impl/common/diagnostics/inspections/LSInspectionDiagnosticProviderImpl.kt

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
22
package com.jetbrains.ls.api.features.impl.common.diagnostics.inspections
33

4+
import com.intellij.codeHighlighting.HighlightDisplayLevel
45
import com.intellij.codeInspection.*
56
import com.intellij.codeInspection.ex.InspectionManagerEx
67
import com.intellij.lang.Language
@@ -61,8 +62,6 @@ class LSInspectionDiagnosticProviderImpl(
6162
BlackListEntry.InspectionClass("org.jetbrains.kotlin.idea.k2.codeinsight.inspections.diagnosticBased.VariableNeverReadInspection", "very slow, uses extended checkers"),
6263
BlackListEntry.InspectionClass("org.jetbrains.kotlin.idea.k2.codeinsight.inspections.diagnosticBased.AssignedValueIsNeverReadInspection", "very slow, uses extended checkers"),
6364

64-
BlackListEntry.InspectionClass("org.jetbrains.kotlin.idea.k2.codeinsight.inspections.expressions.ExplicitThisInspection", "too noisy https://github.com/Kotlin/kotlin-lsp/issues/20"),
65-
BlackListEntry.InspectionClass("org.jetbrains.kotlin.idea.k2.codeinsight.inspections.ImplicitThisInspection", "too noisy https://github.com/Kotlin/kotlin-lsp/issues/20"),
6665
BlackListEntry.InspectionClass("org.jetbrains.kotlin.idea.k2.codeinsight.inspections.PublicApiImplicitTypeInspection", "too noisy https://github.com/Kotlin/kotlin-lsp/issues/4"),
6766

6867
BlackListEntry.InspectionSuperClass("org.jetbrains.kotlin.idea.codeinsight.api.applicable.inspections.KotlinKtDiagnosticBasedInspectionBase", "they are slow as calling additional diagnostic collection"),
@@ -109,6 +108,7 @@ class LSInspectionDiagnosticProviderImpl(
109108
return LocalInspectionEP.LOCAL_INSPECTION.extensionList
110109
.filter { it.language == language.id }
111110
.filter { it.enabledByDefault }
111+
.filter { HighlightDisplayLevel.find(it.level) != HighlightDisplayLevel.DO_NOT_SHOW }
112112
.filterNot { blacklist.containsImplementation(it.implementationClass) }
113113
.mapNotNull { inspection ->
114114
runCatching {
@@ -120,6 +120,8 @@ class LSInspectionDiagnosticProviderImpl(
120120
}
121121
.filterNot { blacklist.containsSuperClass(it) }
122122
.filterIsInstance<LocalInspectionTool>()
123+
.takeIf { it.isNotEmpty() }
124+
?: emptyList()
123125
}
124126

125127
private fun collectDiagnostics(
@@ -166,18 +168,20 @@ class LSInspectionDiagnosticProviderImpl(
166168
element: PsiElement
167169
): List<Diagnostic> {
168170
val document = file.findDocument() ?: return emptyList()
169-
return results.mapNotNull { result ->
170-
val data = result.createDiagnosticData(localInspectionTool, element, file)
171-
Diagnostic(
172-
range = result.range()?.toLspRange(document) ?: return@mapNotNull null,
173-
severity = result.highlightType.toLsp(),
174-
// todo handle markers from [com.intellij.codeInspection.CommonProblemDescriptor.getDescriptionTemplate]
175-
message = result.tooltipTemplate,
176-
code = StringOrInt.string(localInspectionTool.id),
177-
tags = result.highlightType.toLspTags(),
178-
data = LSP.json.encodeToJsonElement(data),
179-
)
180-
}
171+
return results
172+
.filter { it.highlightType != ProblemHighlightType.INFORMATION }
173+
.mapNotNull { result ->
174+
val data = result.createDiagnosticData(localInspectionTool, element, file)
175+
Diagnostic(
176+
range = result.range()?.toLspRange(document) ?: return@mapNotNull null,
177+
severity = result.highlightType.toLsp(),
178+
// todo handle markers from [com.intellij.codeInspection.CommonProblemDescriptor.getDescriptionTemplate]
179+
message = result.tooltipTemplate,
180+
code = StringOrInt.string(localInspectionTool.id),
181+
tags = result.highlightType.toLspTags(),
182+
data = LSP.json.encodeToJsonElement(data),
183+
)
184+
}
181185
}
182186

183187
private fun ProblemDescriptor.range(): TextRange? {

0 commit comments

Comments
 (0)