diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/FileNode.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/FileNode.kt index 9a5f33bcd3b2..8cc25b0bd416 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/FileNode.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/FileNode.kt @@ -27,14 +27,8 @@ internal class FileNode(parent: Node, val file: VirtualFile) : Node(parent) { presentation.addText(" ${getLocationRelativeToUserHome(url)}", GRAYED_ATTRIBUTES) } val root = findAncestor(Root::class.java) - if (root != null) { - val errors = root.getProblemsCount(file, Severity.ERROR) - if (errors > 0) presentation.addText(" $errors errors", GRAYED_ATTRIBUTES) - val warnings = root.getProblemsCount(file, Severity.WARNING) - if (warnings > 0) presentation.addText(" $warnings warnings", GRAYED_ATTRIBUTES) - val info = root.getProblemsCount(file, Severity.INFORMATION) - if (info > 0) presentation.addText(" $warnings info", GRAYED_ATTRIBUTES) - } + val count = root?.getProblemsCount(file) ?: 0 + if (count > 0) presentation.addText(" $count problems", GRAYED_ATTRIBUTES) } override fun getChildren(): Collection { diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/FileProblems.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/FileProblems.kt index fca32b5839c9..f21e48890377 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/FileProblems.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/FileProblems.kt @@ -55,6 +55,4 @@ internal class FileProblems(val file: VirtualFile) { } fun count() = problems.size - - fun count(severity: Severity) = problems.count { it.severity == severity } } diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingFileRoot.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingFileRoot.kt index 8d8ba4cbd3ba..c4a71a4e7faf 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingFileRoot.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingFileRoot.kt @@ -30,7 +30,7 @@ internal class HighlightingFileRoot(panel: ProblemsViewPanel, val file: VirtualF override fun getProblemsCount() = synchronized(problems) { problems.count() } - override fun getProblemsCount(file: VirtualFile, severity: Severity) = synchronized(problems) { problems.count(severity) } + override fun getProblemsCount(file: VirtualFile) = synchronized(problems) { problems.count() } override fun addProblem(file: VirtualFile, problem: Problem) { synchronized(problems) { problems.add(problem) } diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingProblem.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingProblem.kt index bd45513c3dcd..aa636aabb2f4 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingProblem.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingProblem.kt @@ -1,11 +1,11 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.analysis.problemsView.toolWindow +import com.intellij.codeHighlighting.HighlightDisplayLevel import com.intellij.codeInsight.daemon.impl.HighlightInfo import com.intellij.codeInsight.intention.IntentionAction import com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.chooseActionAndInvoke -import com.intellij.icons.AllIcons.Actions.IntentionBulb -import com.intellij.lang.annotation.HighlightSeverity +import com.intellij.icons.AllIcons import com.intellij.lang.injection.InjectedLanguageManager import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent @@ -13,18 +13,23 @@ import com.intellij.openapi.editor.RangeMarker import com.intellij.openapi.util.text.StringUtil.isEmpty import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiFile +import javax.swing.Icon internal class HighlightingProblem(val info: HighlightInfo) : Problem { + private fun getIcon(level: HighlightDisplayLevel) = if (severity >= level.severity.myVal) level.icon else null + + override val icon: Icon + get() = HighlightDisplayLevel.find(info.severity)?.icon + ?: getIcon(HighlightDisplayLevel.ERROR) + ?: getIcon(HighlightDisplayLevel.WARNING) + ?: HighlightDisplayLevel.WEAK_WARNING.icon + override val description: String get() = info.description - override val severity: Severity - get() = when (info.severity) { - HighlightSeverity.ERROR -> Severity.ERROR - HighlightSeverity.WARNING -> Severity.WARNING - else -> Severity.INFORMATION - } + override val severity: Int + get() = info.severity.myVal override val offset: Int get() = info.actualStartOffset @@ -45,7 +50,7 @@ internal class HighlightingProblem(val info: HighlightInfo) : Problem { } private class QuickFixAction(val action: IntentionAction, val marker: RangeMarker) - : AnAction(action.text, action.text, IntentionBulb) { + : AnAction(action.text, action.text, AllIcons.Actions.IntentionBulb) { override fun update(event: AnActionEvent) { event.presentation.isEnabledAndVisible = getTopLevelFile(event) != null diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/NodeComparator.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/NodeComparator.kt index c1fc0e205fbd..58204515c057 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/NodeComparator.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/NodeComparator.kt @@ -25,7 +25,7 @@ internal data class NodeComparator( private fun compare(problem1: Problem, problem2: Problem): Int { if (sortBySeverity) { - val result = problem1.severity.compareTo(problem2.severity) + val result = problem2.severity.compareTo(problem1.severity) if (result != 0) return result } return if (sortByName) { diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/NodeFilter.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/NodeFilter.kt index d19737686d89..a53b48291489 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/NodeFilter.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/NodeFilter.kt @@ -1,6 +1,7 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.analysis.problemsView.toolWindow +import com.intellij.lang.annotation.HighlightSeverity import java.util.function.Predicate internal data class NodeFilter( @@ -10,11 +11,12 @@ internal data class NodeFilter( : Predicate { override fun test(node: Node?): Boolean { - return if (node !is ProblemNode) true - else when (node.problem.severity) { - Severity.ERROR -> showErrors - Severity.WARNING -> showWarnings - Severity.INFORMATION -> showInformation + // TODO: update filter + return when { + node !is ProblemNode -> true + node.problem.severity < HighlightSeverity.WARNING.myVal -> showInformation + node.problem.severity < HighlightSeverity.ERROR.myVal -> showWarnings + else -> showErrors } } } diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/Problem.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/Problem.kt index ddc025ba658c..a8fb22bcfd3e 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/Problem.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/Problem.kt @@ -2,10 +2,12 @@ package com.intellij.analysis.problemsView.toolWindow import com.intellij.openapi.actionSystem.AnAction +import javax.swing.Icon interface Problem { + val icon: Icon val description: String - val severity: Severity + val severity: Int val offset: Int fun hasQuickFixActions() = false diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProblemNode.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProblemNode.kt index a8335c246195..6d34761e1251 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProblemNode.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProblemNode.kt @@ -16,7 +16,7 @@ internal class ProblemNode(parent: FileNode, val problem: Problem) : Node(parent override fun getName() = problem.description override fun update(project: Project, presentation: PresentationData) { - presentation.setIcon(problem.severity.icon) + presentation.setIcon(problem.icon) val document = ProblemsView.getDocument(project, file) ?: return // add nothing if no document if (!isValidOffset(problem.offset, document)) return val line = document.getLineNumber(problem.offset) + 1 diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/Root.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/Root.kt index 7760705fe862..a94e600297fd 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/Root.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/Root.kt @@ -32,8 +32,8 @@ internal open class Root(val panel: ProblemsViewPanel) : Node(panel.project), Di allProblems.values.sumBy { it.count() } } - open fun getProblemsCount(file: VirtualFile, severity: Severity): Int = synchronized(allProblems) { - allProblems[file]?.count(severity) ?: 0 + open fun getProblemsCount(file: VirtualFile): Int = synchronized(allProblems) { + allProblems[file]?.count() ?: 0 } open fun addProblem(file: VirtualFile, problem: Problem) { diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/Severity.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/Severity.kt deleted file mode 100644 index 3ae929b172d9..000000000000 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/Severity.kt +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.analysis.problemsView.toolWindow - -import com.intellij.icons.AllIcons.General -import javax.swing.Icon - -enum class Severity(val icon: Icon) { - ERROR(General.Error), - WARNING(General.Warning), - INFORMATION(General.Information), -}