IDEA-CR-53528: WEB-25666 Add option to configure injected fragment background for each language separately

Added support for:
- JavaScript
- TypeScript
- XML
- HTML
- Pug/Jade

GitOrigin-RevId: 3fbec688920188fa2181aa8f85ec4dbef9d0bc2e
This commit is contained in:
Piotr Tomiak
2019-10-15 10:40:21 +02:00
committed by intellij-monorepo-bot
parent 2aaf87532d
commit 34ea833ed4
6 changed files with 43 additions and 8 deletions

View File

@@ -1,10 +1,14 @@
// Copyright 2000-2018 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.openapi.editor.colors;
import com.intellij.lang.Language;
import com.intellij.openapi.editor.markup.EffectType;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.ui.JBColor;
import com.intellij.util.containers.Stack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
@@ -69,7 +73,7 @@ public interface EditorColors {
ColorKey IGNORED_DELETED_LINES_BORDER_COLOR = ColorKey.createColorKey("IGNORED_DELETED_LINES_BORDER_COLOR");
TextAttributesKey INJECTED_LANGUAGE_FRAGMENT = TextAttributesKey.createTextAttributesKey("INJECTED_LANGUAGE_FRAGMENT");
TextAttributesKey BREADCRUMBS_DEFAULT = TextAttributesKey.createTextAttributesKey("BREADCRUMBS_DEFAULT");
TextAttributesKey BREADCRUMBS_HOVERED = TextAttributesKey.createTextAttributesKey("BREADCRUMBS_HOVERED");
TextAttributesKey BREADCRUMBS_CURRENT = TextAttributesKey.createTextAttributesKey("BREADCRUMBS_CURRENT");
@@ -80,4 +84,22 @@ public interface EditorColors {
ColorKey VISUAL_INDENT_GUIDE_COLOR = ColorKey.createColorKey("VISUAL_INDENT_GUIDE");
ColorKey DOCUMENTATION_COLOR = ColorKey.createColorKey("DOCUMENTATION_COLOR", new JBColor(new Color(0xf7f7f7), new Color(0x46484a)));
@NotNull
static TextAttributesKey createInjectedLanguageFragmentKey(@Nullable Language language) {
Stack<Language> languages = new Stack<>();
while (language != null && language != Language.ANY) {
languages.push(language);
language = language.getBaseLanguage();
}
TextAttributesKey currentKey = INJECTED_LANGUAGE_FRAGMENT;
while(!languages.empty()) {
Language current = languages.pop();
currentKey = TextAttributesKey.createTextAttributesKey(
current.getID() + ":INJECTED_LANGUAGE_FRAGMENT",
currentKey);
}
return currentKey;
}
}

View File

@@ -24,7 +24,6 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
@@ -52,6 +51,8 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
import static com.intellij.openapi.editor.colors.EditorColors.createInjectedLanguageFragmentKey;
public class InjectedGeneralHighlightingPass extends GeneralHighlightingPass {
private static final String PRESENTABLE_NAME = "Injected fragments";
@@ -178,7 +179,7 @@ public class InjectedGeneralHighlightingPass extends GeneralHighlightingPass {
outInjected.add(injectedPsi);
}
};
if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<>(hosts), progress,
if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<>(hosts), progress,
element -> {
ApplicationManager.getApplication().assertReadAccessAllowed();
InjectedLanguageManager.getInstance(myFile.getProject()).enumerateEx(
@@ -198,7 +199,7 @@ public class InjectedGeneralHighlightingPass extends GeneralHighlightingPass {
@NotNull final Collection<? super HighlightInfo> outInfos) {
if (injectedFiles.isEmpty()) return true;
final InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(myProject);
final TextAttributes injectedAttributes = myGlobalScheme.getAttributes(EditorColors.INJECTED_LANGUAGE_FRAGMENT);
final TextAttributes injectedAttributes = myGlobalScheme.getAttributes(createInjectedLanguageFragmentKey(myFile.getLanguage()));
return JobLauncher.getInstance()
.invokeConcurrentlyUnderProgress(new ArrayList<>(injectedFiles), progress,
@@ -213,7 +214,7 @@ public class InjectedGeneralHighlightingPass extends GeneralHighlightingPass {
}
private boolean addInjectedPsiHighlights(@NotNull PsiFile injectedPsi,
TextAttributes injectedAttributes,
@Nullable TextAttributes injectedAttributes,
@NotNull Collection<? super HighlightInfo> outInfos,
@NotNull InjectedLanguageManager injectedLanguageManager) {
DocumentWindow documentWindow = (DocumentWindow)PsiDocumentManager.getInstance(myProject).getCachedDocument(injectedPsi);
@@ -408,7 +409,7 @@ public class InjectedGeneralHighlightingPass extends GeneralHighlightingPass {
TextAttributes.ERASE_MARKER).createUnconditionally();
holder.add(info);
forcedAttributes = new TextAttributes(attributes.getForegroundColor(), attributes.getBackgroundColor(),
forcedAttributes = new TextAttributes(attributes.getForegroundColor(), attributes.getBackgroundColor(),
attributes.getEffectColor(), attributes.getEffectType(), attributes.getFontType());
}

View File

@@ -330,6 +330,7 @@ options.java.attribute.descriptor.server.duplicate=Errors and Warnings//Duplicat
options.general.color.descriptor.injected.language.fragment=Code//Injected language fragment
options.general.attribute.descriptior.identifier.under.caret=Code//Identifier under caret
options.general.attribute.descriptior.identifier.under.caret.write=Code//Identifier under caret (write)
options.any.color.descriptor.injected.language.fragment=Injected language fragment
# Console settings
color.settings.console.name=Console Colors

View File

@@ -41,6 +41,7 @@ public class HTMLColorsPage implements ColorSettingsPage {
new AttributesDescriptor(OptionsBundle.message("options.html.attribute.descriptor.attribute.name"), XmlHighlighterColors.HTML_ATTRIBUTE_NAME),
new AttributesDescriptor(OptionsBundle.message("options.html.attribute.descriptor.attribute.value"), XmlHighlighterColors.HTML_ATTRIBUTE_VALUE),
new AttributesDescriptor(OptionsBundle.message("options.html.attribute.descriptor.entity.reference"), XmlHighlighterColors.HTML_ENTITY_REFERENCE),
new AttributesDescriptor(OptionsBundle.message("options.any.color.descriptor.injected.language.fragment"), XmlHighlighterColors.HTML_INJECTED_LANGUAGE_FRAGMENT),
};
private static final String FULL_PRODUCT_NAME = ApplicationNamesInfo.getInstance().getFullProductName();
@@ -106,4 +107,4 @@ public class HTMLColorsPage implements ColorSettingsPage {
public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() {
return null;
}
}
}

View File

@@ -42,6 +42,7 @@ public class XMLColorsPage implements ColorSettingsPage {
new AttributesDescriptor(OptionsBundle.message("options.xml.attribute.descriptor.attribute.value"), XmlHighlighterColors.XML_ATTRIBUTE_VALUE),
new AttributesDescriptor(OptionsBundle.message("options.xml.attribute.descriptor.tag.data"), XmlHighlighterColors.XML_TAG_DATA),
new AttributesDescriptor(OptionsBundle.message("options.xml.attribute.descriptor.descriptor.entity,reference"), XmlHighlighterColors.XML_ENTITY_REFERENCE),
new AttributesDescriptor(OptionsBundle.message("options.any.color.descriptor.injected.language.fragment"), XmlHighlighterColors.XML_INJECTED_LANGUAGE_FRAGMENT),
};
@Override
@@ -101,4 +102,4 @@ public class XMLColorsPage implements ColorSettingsPage {
return ContainerUtil.newHashMap(Pair.create("np", XmlHighlighterColors.XML_NS_PREFIX),
Pair.create("bg", XmlHighlighterColors.XML_TAG));
}
}
}

View File

@@ -15,6 +15,9 @@
*/
package com.intellij.openapi.editor;
import com.intellij.lang.html.HTMLLanguage;
import com.intellij.lang.xml.XMLLanguage;
import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
/**
@@ -57,4 +60,10 @@ public class XmlHighlighterColors {
public static final TextAttributesKey HTML_CODE =
TextAttributesKey.createTextAttributesKey("HTML_CODE", HighlighterColors.TEXT);
public static final TextAttributesKey XML_INJECTED_LANGUAGE_FRAGMENT =
EditorColors.createInjectedLanguageFragmentKey(XMLLanguage.INSTANCE);
public static final TextAttributesKey HTML_INJECTED_LANGUAGE_FRAGMENT =
EditorColors.createInjectedLanguageFragmentKey(HTMLLanguage.INSTANCE);
}