diff --git a/platform/platform-impl/src/com/intellij/application/options/colors/RainbowCollector.kt b/platform/platform-impl/src/com/intellij/application/options/colors/RainbowCollector.kt new file mode 100644 index 000000000000..22dd44948a0a --- /dev/null +++ b/platform/platform-impl/src/com/intellij/application/options/colors/RainbowCollector.kt @@ -0,0 +1,26 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.application.options.colors + +import com.intellij.internal.statistic.eventLog.EventLogGroup +import com.intellij.internal.statistic.eventLog.events.EventFields +import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector +import com.intellij.lang.Language + + +internal object RainbowCollector : CounterUsagesCollector() { + @JvmStatic + private val RAINBOW_GROUP = EventLogGroup("rainbow.highlighter", 1) + private val KNOWN_LANGUAGE_IDS = Language + .getRegisteredLanguages() + .map { it.id } // we have an empty string in the list as the ANY language representation + .plus(RainbowColorsInSchemeState.DEFAULT_LANGUAGE_NAME) + .sorted() + + @JvmStatic + val RAINBOW_HIGHLIGHTER_CHANGED_EVENT = RAINBOW_GROUP.registerEvent( + "rainbow.highlighter.changed", + EventFields.StringList("rainbowOnLanguageIDs", KNOWN_LANGUAGE_IDS), + ) + + override fun getGroup(): EventLogGroup = RAINBOW_GROUP +} diff --git a/platform/platform-impl/src/com/intellij/application/options/colors/RainbowColorsInSchemeState.java b/platform/platform-impl/src/com/intellij/application/options/colors/RainbowColorsInSchemeState.java index 26cbe84a3c44..7837f136f99e 100644 --- a/platform/platform-impl/src/com/intellij/application/options/colors/RainbowColorsInSchemeState.java +++ b/platform/platform-impl/src/com/intellij/application/options/colors/RainbowColorsInSchemeState.java @@ -9,6 +9,8 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.TextAttributesKey; +import com.intellij.openapi.options.colors.ColorSettingsPage; +import com.intellij.openapi.options.colors.RainbowColorSettingsPage; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; @@ -16,8 +18,12 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.awt.*; +import java.util.Collections; +import java.util.Set; +import java.util.TreeSet; public final class RainbowColorsInSchemeState { + public static final String DEFAULT_LANGUAGE_NAME = "Default"; private final EditorColorsScheme myEditedScheme; private final EditorColorsScheme myOriginalScheme; @@ -41,8 +47,15 @@ public final class RainbowColorsInSchemeState { } private static void updateRainbowMarkup(@NotNull EditorColorsScheme scheme) { + Set languagesWithRainbowHighlighting = getRainbowOnLanguageIds(scheme); + RainbowCollector.getRAINBOW_HIGHLIGHTER_CHANGED_EVENT().log(languagesWithRainbowHighlighting.stream().toList()); + RainbowHighlighter.resetRainbowGeneratedColors(scheme); - ApplicationManager.getApplication().getMessageBus().syncPublisher(RainbowStateChangeListener.getTOPIC()).onRainbowStateChanged(scheme); + ApplicationManager + .getApplication() + .getMessageBus() + .syncPublisher(RainbowStateChangeListener.getTOPIC()) + .onRainbowStateChanged(scheme, languagesWithRainbowHighlighting); Editor[] allEditors = EditorFactory.getInstance().getAllEditors(); for (Editor editor : allEditors) { @@ -56,6 +69,27 @@ public final class RainbowColorsInSchemeState { } } + @NotNull + private static Set getRainbowOnLanguageIds(@NotNull EditorColorsScheme scheme) { + TreeSet rainbowOnLanguages = new TreeSet<>(); + ColorSettingsPage.EP_NAME.forEachExtensionSafe( + it -> { + if (it instanceof RainbowColorSettingsPage rcp && RainbowHighlighter.isRainbowEnabledWithInheritance(scheme, rcp.getLanguage())) { + Language language = rcp.getLanguage(); + if (language != Language.ANY) { + // Here we skip [Language.ANY] as the language that has no frontend representation + // Instead, the [null] language is the Default language + // See the [com.jetbrains.rdclient.colorSchemes.ProtocolRainbowColorSettingsPage.getLanguage] implementation + rainbowOnLanguages.add(language != null + ? language.getID() + : DEFAULT_LANGUAGE_NAME); + } + } + } + ); + return Collections.unmodifiableSet(rainbowOnLanguages); + } + public boolean isModified(@Nullable Language language) { return (language == null && isRainbowColorsModified()) || RainbowHighlighter.isRainbowEnabled(myEditedScheme, language) != RainbowHighlighter.isRainbowEnabled(myOriginalScheme, language); diff --git a/platform/platform-impl/src/com/intellij/application/options/colors/RainbowStateChangeListener.kt b/platform/platform-impl/src/com/intellij/application/options/colors/RainbowStateChangeListener.kt index 078d745f60b7..b6e13e64968d 100644 --- a/platform/platform-impl/src/com/intellij/application/options/colors/RainbowStateChangeListener.kt +++ b/platform/platform-impl/src/com/intellij/application/options/colors/RainbowStateChangeListener.kt @@ -18,7 +18,9 @@ interface RainbowStateChangeListener { /** * Notifies the subscribers that the global editor colors scheme has changes in the semantic markup state. - * @param scheme the scheme with the new semantic markup state + * + * @param scheme the scheme with the new semantic markup state. + * @param rainbowOnLanguages The set of languages that have rainbow highlighting enabled. */ - fun onRainbowStateChanged(scheme: EditorColorsScheme) + fun onRainbowStateChanged(scheme: EditorColorsScheme, rainbowOnLanguages: Set) } \ No newline at end of file diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index 690b132ee296..01c779f43061 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -968,6 +968,7 @@ +