diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/ProblemsCollector.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/ProblemsCollector.kt index a6a480199f5e..721cad5b202d 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/ProblemsCollector.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/ProblemsCollector.kt @@ -1,10 +1,17 @@ // 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 +import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile interface ProblemsCollector : ProblemsListener { + companion object { + @JvmStatic + fun getInstance(project: Project) = project.getService(ProblemsCollector::class.java)!! + } + fun getProblemCount(): Int + fun getProblemFiles(): Collection fun getFileProblemCount(file: VirtualFile): Int fun getFileProblems(file: VirtualFile): Collection diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/ProblemsListener.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/ProblemsListener.kt index 83f2f6b34965..92437cce0437 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/ProblemsListener.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/ProblemsListener.kt @@ -1,14 +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 -import com.intellij.openapi.project.Project - interface ProblemsListener { - companion object { - @JvmStatic - fun getInstance(project: Project) = project.getService(ProblemsListener::class.java)!! - } - fun problemAppeared(problem: Problem) fun problemDisappeared(problem: Problem) fun problemUpdated(problem: Problem) diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingErrorsProvider.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingErrorsProvider.kt index 998357b2d8f7..2998be8a639d 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingErrorsProvider.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/HighlightingErrorsProvider.kt @@ -1,7 +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.analysis.problemsView.ProblemsListener +import com.intellij.analysis.problemsView.ProblemsCollector import com.intellij.analysis.problemsView.ProblemsProvider import com.intellij.codeInsight.problems.WolfTheProblemSolverImpl import com.intellij.lang.annotation.HighlightSeverity.ERROR @@ -30,7 +30,7 @@ internal class HighlightingErrorsProvider(override val project: Project) : Probl override fun problemsAppeared(file: VirtualFile) { synchronized(watchers) { watchers.computeIfAbsent(file) { file -> - HighlightingWatcher(this, ProblemsListener.getInstance(project), file, ERROR.myVal).also { watcher -> + HighlightingWatcher(this, ProblemsCollector.getInstance(project), file, ERROR.myVal).also { watcher -> Disposer.register(this, watcher) } } diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProjectErrorsCollector.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProjectErrorsCollector.kt index 8759df9be1b2..38a9d47cf2ac 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProjectErrorsCollector.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProjectErrorsCollector.kt @@ -10,13 +10,17 @@ import com.intellij.openapi.vfs.VirtualFile import com.intellij.ui.AppUIUtil import java.util.concurrent.atomic.AtomicInteger -internal class ProjectErrorsCollector(val project: Project) : ProblemsCollector { +private class ProjectErrorsCollector(val project: Project) : ProblemsCollector { private val fileProblems = mutableMapOf>() private val otherProblems = mutableSetOf() private val problemCount = AtomicInteger() override fun getProblemCount() = problemCount.get() + override fun getProblemFiles() = synchronized(fileProblems) { + fileProblems.keys.toSet() + } + override fun getFileProblemCount(file: VirtualFile) = synchronized(fileProblems) { fileProblems[file]?.size ?: 0 } @@ -67,17 +71,17 @@ internal class ProjectErrorsCollector(val project: Project) : ProblemsCollector private fun notify(problem: Problem, state: SetUpdateState) { when (state) { SetUpdateState.ADDED -> { - getProjectErrors()?.addProblem(problem) + getProblemsListener()?.problemAppeared(problem) val emptyBefore = problemCount.getAndIncrement() == 0 if (emptyBefore) updateToolWindowIcon() } SetUpdateState.REMOVED -> { - getProjectErrors()?.removeProblem(problem) + getProblemsListener()?.problemDisappeared(problem) val emptyAfter = problemCount.decrementAndGet() == 0 if (emptyAfter) updateToolWindowIcon() } SetUpdateState.UPDATED -> { - getProjectErrors()?.updateProblem(problem) + getProblemsListener()?.problemUpdated(problem) } SetUpdateState.IGNORED -> { } @@ -94,7 +98,7 @@ internal class ProjectErrorsCollector(val project: Project) : ProblemsCollector else -> Toolwindows.ToolWindowProblems } - private fun getProjectErrors() = ProblemsView.getToolWindow(project) + private fun getProblemsListener() = ProblemsView.getToolWindow(project) ?.contentManagerIfCreated ?.contents ?.mapNotNull { it.component as? ProjectErrorsPanel } diff --git a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProjectErrorsPanel.kt b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProjectErrorsPanel.kt index b9c8e138ef8a..318f77b09d2d 100644 --- a/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProjectErrorsPanel.kt +++ b/platform/lang-impl/src/com/intellij/analysis/problemsView/toolWindow/ProjectErrorsPanel.kt @@ -3,11 +3,12 @@ package com.intellij.analysis.problemsView.toolWindow import com.intellij.analysis.problemsView.FileProblem import com.intellij.analysis.problemsView.Problem +import com.intellij.analysis.problemsView.ProblemsListener import com.intellij.openapi.actionSystem.ToggleOptionAction.Option import com.intellij.openapi.project.Project internal class ProjectErrorsPanel(project: Project, state: ProblemsViewState) - : ProblemsViewPanel(project, state) { + : ProblemsViewPanel(project, state), ProblemsListener { private val root = Root(this) @@ -20,15 +21,15 @@ internal class ProjectErrorsPanel(project: Project, state: ProblemsViewState) override fun getSortFoldersFirst(): Option? = null override fun getSortBySeverity(): Option? = null - fun addProblem(problem: Problem) { + override fun problemAppeared(problem: Problem) { if (problem is FileProblem) root.addProblems(problem.file, problem) } - fun removeProblem(problem: Problem) { + override fun problemDisappeared(problem: Problem) { if (problem is FileProblem) root.removeProblems(problem.file, problem) } - fun updateProblem(problem: Problem) { + override fun problemUpdated(problem: Problem) { if (problem is FileProblem) root.updateProblem(problem.file, problem) } } diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 29e51347e0cf..fbdb0fc82be9 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -945,7 +945,7 @@ serviceImplementation="com.intellij.codeInsight.template.TemplateBuilderFactoryImpl"/> -