diff --git a/scala/scala-impl/resources/META-INF/scala-plugin-common.xml b/scala/scala-impl/resources/META-INF/scala-plugin-common.xml
index 967ea339881..26d2abca5c3 100644
--- a/scala/scala-impl/resources/META-INF/scala-plugin-common.xml
+++ b/scala/scala-impl/resources/META-INF/scala-plugin-common.xml
@@ -2047,6 +2047,9 @@
+
+
diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/actions/ToggleTypeAwareHighlightingAction.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/actions/ToggleTypeAwareHighlightingAction.scala
index a6a0e212265..63fe67e0955 100644
--- a/scala/scala-impl/src/org/jetbrains/plugins/scala/actions/ToggleTypeAwareHighlightingAction.scala
+++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/actions/ToggleTypeAwareHighlightingAction.scala
@@ -8,7 +8,7 @@ import com.intellij.openapi.project.Project
import com.intellij.util.FileContentUtil
import org.jetbrains.plugins.scala.ScalaBundle
import org.jetbrains.plugins.scala.actions.ToggleTypeAwareHighlightingAction.toggleSettingAndRehighlight
-import org.jetbrains.plugins.scala.components.TypeAwareWidgetFactory
+import org.jetbrains.plugins.scala.components.TypeAwareWidgetUpdater
import org.jetbrains.plugins.scala.extensions._
import org.jetbrains.plugins.scala.settings.ScalaProjectSettings
@@ -35,9 +35,7 @@ object ToggleTypeAwareHighlightingAction {
val settings = ScalaProjectSettings.getInstance(project)
settings.toggleTypeAwareHighlighting()
- project.getMessageBus
- .syncPublisher(TypeAwareWidgetFactory.Topic)
- .updateWidget()
+ TypeAwareWidgetUpdater.updateWidget(project)
invokeLater(ModalityState.nonModal()) {
reparseActiveFiles(project)
diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/components/TypeAwareWidget.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/components/TypeAwareWidget.scala
index f78703b04a0..f17275e309d 100644
--- a/scala/scala-impl/src/org/jetbrains/plugins/scala/components/TypeAwareWidget.scala
+++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/components/TypeAwareWidget.scala
@@ -3,43 +3,22 @@ package org.jetbrains.plugins.scala.components
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.keymap.KeymapUtil
import com.intellij.openapi.project.Project
+import com.intellij.openapi.wm.StatusBarWidget
import com.intellij.openapi.wm.StatusBarWidget.WidgetPresentation
-import com.intellij.openapi.wm.impl.status.widget.StatusBarWidgetsManager
-import com.intellij.openapi.wm.{StatusBar, StatusBarWidget}
import com.intellij.util.Consumer
-import com.intellij.util.messages.MessageBusConnection
import org.jetbrains.plugins.scala.ScalaBundle
import org.jetbrains.plugins.scala.actions.ToggleTypeAwareHighlightingAction
-import org.jetbrains.plugins.scala.extensions.invokeLater
import org.jetbrains.plugins.scala.icons.Icons
-import org.jetbrains.plugins.scala.project.ProjectExt
import org.jetbrains.plugins.scala.settings.ScalaProjectSettings
import java.awt.event.MouseEvent
import javax.swing.Icon
-private final class TypeAwareWidget(project: Project, factory: TypeAwareWidgetFactory)
- extends StatusBarWidget
- with StatusBarWidget.IconPresentation
- with TypeAwareWidgetFactory.UpdateListener {
-
- private var statusBar: StatusBar = _
- private val connection: MessageBusConnection = project.getMessageBus.connect()
- private val widgetsManager: StatusBarWidgetsManager = project.getService(classOf[StatusBarWidgetsManager])
+private final class TypeAwareWidget(project: Project)
+ extends StatusBarWidget with StatusBarWidget.IconPresentation {
override def ID(): String = TypeAwareWidgetFactory.ID
- override def install(statusBar: StatusBar): Unit = synchronized {
- this.statusBar = statusBar
- connection.subscribe(TypeAwareWidgetFactory.Topic, this)
- subscribeToRootsChange()
- }
-
- override def dispose(): Unit = synchronized {
- connection.dispose()
- statusBar = null
- }
-
override def getPresentation: WidgetPresentation = this
override def getIcon: Icon =
@@ -61,13 +40,6 @@ private final class TypeAwareWidget(project: Project, factory: TypeAwareWidgetFa
override def getClickConsumer: Consumer[MouseEvent] =
_ => ToggleTypeAwareHighlightingAction.toggleSettingAndRehighlight(project)
- override def updateWidget(): Unit = synchronized {
- if (statusBar ne null) {
- widgetsManager.updateWidget(factory)
- statusBar.updateWidget(ID())
- }
- }
-
private def isEnabled: Boolean =
ScalaProjectSettings.getInstance(project).isTypeAwareHighlightingEnabled
@@ -75,12 +47,4 @@ private final class TypeAwareWidget(project: Project, factory: TypeAwareWidgetFa
val action = ActionManager.getInstance().getAction("Scala.EnableErrors")
action.getShortcutSet.getShortcuts.headOption.map(KeymapUtil.getShortcutText)
}
-
- private def subscribeToRootsChange(): Unit = {
- project.subscribeToModuleRootChanged() { _ =>
- invokeLater {
- updateWidget()
- }
- }
- }
}
diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/components/TypeAwareWidgetFactory.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/components/TypeAwareWidgetFactory.scala
index 49c9d071d7a..1fe6b0d6808 100644
--- a/scala/scala-impl/src/org/jetbrains/plugins/scala/components/TypeAwareWidgetFactory.scala
+++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/components/TypeAwareWidgetFactory.scala
@@ -5,12 +5,9 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.wm.impl.status.widget.StatusBarWidgetsManager
import com.intellij.openapi.wm.{StatusBar, StatusBarWidget, StatusBarWidgetFactory}
-import com.intellij.util.messages.Topic
import org.jetbrains.plugins.scala.ScalaBundle
import org.jetbrains.plugins.scala.project.ProjectExt
-import scala.jdk.CollectionConverters._
-
private final class TypeAwareWidgetFactory extends StatusBarWidgetFactory {
override def getId: String = TypeAwareWidgetFactory.ID
@@ -18,7 +15,7 @@ private final class TypeAwareWidgetFactory extends StatusBarWidgetFactory {
override def isAvailable(project: Project): Boolean = project.isOpen && project.hasScala
- override def createWidget(project: Project): StatusBarWidget = new TypeAwareWidget(project, this)
+ override def createWidget(project: Project): StatusBarWidget = new TypeAwareWidget(project)
override def disposeWidget(widget: StatusBarWidget): Unit = {
Disposer.dispose(widget)
@@ -27,14 +24,8 @@ private final class TypeAwareWidgetFactory extends StatusBarWidgetFactory {
override def canBeEnabledOn(statusBar: StatusBar): Boolean = isAvailable(statusBar.getProject)
}
-private[scala] object TypeAwareWidgetFactory {
- private[components] val ID: String = "TypeAwareHighlighting"
-
- trait UpdateListener {
- def updateWidget(): Unit
- }
-
- val Topic: Topic[UpdateListener] = new Topic("TypeAwareHighlightingWidget update", classOf[UpdateListener])
+private object TypeAwareWidgetFactory {
+ val ID: String = "TypeAwareHighlighting"
final class Listener(project: Project) extends DumbModeListener {
@@ -55,7 +46,7 @@ private[scala] object TypeAwareWidgetFactory {
*/
override def exitDumbMode(): Unit = {
val service = project.getService(classOf[StatusBarWidgetsManager])
- service.getWidgetFactories.asScala.find(_.getId == ID).foreach(service.updateWidget)
+ service.updateWidget(classOf[TypeAwareWidgetFactory])
}
}
}
diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/components/TypeAwareWidgetModuleRootListener.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/components/TypeAwareWidgetModuleRootListener.scala
new file mode 100644
index 00000000000..3cd523d60f7
--- /dev/null
+++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/components/TypeAwareWidgetModuleRootListener.scala
@@ -0,0 +1,11 @@
+package org.jetbrains.plugins.scala.components
+
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.roots.{ModuleRootEvent, ModuleRootListener}
+
+private final class TypeAwareWidgetModuleRootListener(project: Project) extends ModuleRootListener {
+ override def rootsChanged(event: ModuleRootEvent): Unit = {
+ if (!event.isCausedByWorkspaceModelChangesOnly) return
+ TypeAwareWidgetUpdater.updateWidget(project)
+ }
+}
diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/components/TypeAwareWidgetUpdater.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/components/TypeAwareWidgetUpdater.scala
new file mode 100644
index 00000000000..3fb9c61b9f9
--- /dev/null
+++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/components/TypeAwareWidgetUpdater.scala
@@ -0,0 +1,15 @@
+package org.jetbrains.plugins.scala.components
+
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.wm.WindowManager
+import com.intellij.openapi.wm.impl.status.widget.StatusBarWidgetsManager
+
+object TypeAwareWidgetUpdater {
+ def updateWidget(project: Project): Unit = {
+ if (project.isDisposed) return
+ project.getService(classOf[StatusBarWidgetsManager]).updateWidget(classOf[TypeAwareWidgetFactory])
+ val statusBar = WindowManager.getInstance().getStatusBar(project)
+ if (statusBar eq null) return
+ statusBar.updateWidget(TypeAwareWidgetFactory.ID)
+ }
+}