return Registry.is("editor.rainbow.identifiers", false);
}
+ public static void setRainbowEnabled(boolean enabled) {
+ Registry.get("editor.rainbow.identifiers").setValue(enabled);
+ }
+
@NotNull
- public Color calculateForeground(int colorIndex) {
- return myRainbowColors.get(Math.abs(colorIndex) % myRainbowColors.size());
+ private Color calculateForeground(int colorIndex) {
+ return myRainbowColors[colorIndex];
}
public int getColorsCount() {
}
public HighlightInfo getInfo(int colorIndex, @Nullable PsiElement id, @Nullable TextAttributesKey colorKey) {
- if (id == null) {
- return null;
- }
+ return id == null ? null : getInfoBuilder(colorIndex, colorKey).range(id).create();
+ }
+
+ public HighlightInfo getInfo(int colorIndex, int start, int end, @Nullable TextAttributesKey colorKey) {
+ return getInfoBuilder(colorIndex, colorKey).range(start, end).create();
+ }
+
- public int getColorIndex(HashMap<String, Integer> id2index, @NotNull String id, int idHash) {
- Integer colorIndex = id2index.get(id);
- if (colorIndex == null) {
- colorIndex = Math.abs(idHash);
-
- Map<Integer, Integer> index2usage = new HashMap<Integer, Integer>();
- id2index.values().forEach(i -> {
- Integer useCount = index2usage.get(i);
- index2usage.put(i, useCount == null ? 1 : ++useCount);
- });
-
- int colorsCount = getColorsCount();
- out:
- for (int cutoff = 0; ; ++cutoff) {
- for (int i = 0; i < colorsCount; ++i) {
- colorIndex %= colorsCount;
- Integer useCount = index2usage.get(colorIndex % colorsCount);
- if (useCount == null) useCount = 0;
- if (useCount == cutoff) break out;
- ++colorIndex;
- }
- }
- id2index.put(id, colorIndex);
- }
- return colorIndex;
- }
-
+ @NotNull
+ protected HighlightInfo.Builder getInfoBuilder(int colorIndex, @Nullable TextAttributesKey colorKey) {
if (colorKey == null) {
colorKey = DefaultLanguageHighlighterColors.LOCAL_VARIABLE;
}