CPP-38168 Add FUS for 'Semantic highlighting' usages

GitOrigin-RevId: 7e284a7687dd235848307cf60e7aace4d7cabd29
This commit is contained in:
Alexey Utkin
2024-03-27 18:08:30 +00:00
committed by intellij-monorepo-bot
parent a8bf8a4094
commit 7b00d65430
4 changed files with 66 additions and 3 deletions
@@ -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
}
@@ -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<String> 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<String> getRainbowOnLanguageIds(@NotNull EditorColorsScheme scheme) {
TreeSet<String> 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);
@@ -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<String>)
}
@@ -968,6 +968,7 @@
<statistics.counterUsagesCollector implementationClass="com.intellij.internal.statistic.collectors.fus.ui.GotItUsageCollectorGroup"/>
<statistics.counterUsagesCollector implementationClass="com.intellij.internal.statistic.collectors.fus.ui.BalloonUsageCollector"/>
<statistics.counterUsagesCollector implementationClass="com.intellij.application.options.colors.ReaderModeStatsCollector"/>
<statistics.counterUsagesCollector implementationClass="com.intellij.application.options.colors.RainbowCollector"/>
<statistics.counterUsagesCollector implementationClass="com.intellij.diagnostic.IdeErrorDialogUsageCollector"/>
<statistics.counterUsagesCollector implementationClass="com.intellij.ide.util.projectWizard.LightweightNewProjectWizardCollector" />
<statistics.counterUsagesCollector implementationClass="com.intellij.ide.projectWizard.NewProjectWizardCollector"/>