Search in sources :

Example 6 with TextAttributesKey

use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.

the class PythonHighlightingTest method testMagicMethods.

// PY-19927
public void testMagicMethods() {
    EditorColorsManager manager = EditorColorsManager.getInstance();
    EditorColorsScheme scheme = (EditorColorsScheme) manager.getGlobalScheme().clone();
    manager.addColorsScheme(scheme);
    EditorColorsManager.getInstance().setGlobalScheme(scheme);
    TextAttributesKey xKey = TextAttributesKey.find("PY.PREDEFINED_DEFINITION");
    TextAttributes xAttributes = new TextAttributes(Color.green, Color.black, Color.white, EffectType.BOXED, Font.BOLD);
    scheme.setAttributes(xKey, xAttributes);
    doTest();
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey)

Example 7 with TextAttributesKey

use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.

the class PythonHighlightingTest method testBuiltins.

public void testBuiltins() {
    EditorColorsManager manager = EditorColorsManager.getInstance();
    EditorColorsScheme scheme = (EditorColorsScheme) manager.getGlobalScheme().clone();
    manager.addColorsScheme(scheme);
    EditorColorsManager.getInstance().setGlobalScheme(scheme);
    TextAttributesKey xKey;
    TextAttributes xAttributes;
    xKey = TextAttributesKey.find("PY.BUILTIN_NAME");
    xAttributes = new TextAttributes(Color.green, Color.black, Color.white, EffectType.BOXED, Font.BOLD);
    scheme.setAttributes(xKey, xAttributes);
    xKey = TextAttributesKey.find("PY.PREDEFINED_USAGE");
    xAttributes = new TextAttributes(Color.yellow, Color.black, Color.white, EffectType.BOXED, Font.BOLD);
    scheme.setAttributes(xKey, xAttributes);
    doTest();
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey)

Example 8 with TextAttributesKey

use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.

the class PythonHighlightingTest method testYieldInNestedFunction.

public void testYieldInNestedFunction() {
    // highlight func declaration first, lest we get an "Extra fragment highlighted" error.
    EditorColorsManager manager = EditorColorsManager.getInstance();
    EditorColorsScheme scheme = (EditorColorsScheme) manager.getGlobalScheme().clone();
    manager.addColorsScheme(scheme);
    EditorColorsManager.getInstance().setGlobalScheme(scheme);
    TextAttributesKey xKey = TextAttributesKey.find("PY.FUNC_DEFINITION");
    TextAttributes xAttributes = new TextAttributes(Color.red, Color.black, Color.white, EffectType.BOXED, Font.BOLD);
    scheme.setAttributes(xKey, xAttributes);
    doTest();
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey)

Example 9 with TextAttributesKey

use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.

the class ChameleonSyntaxHighlightingPass method collectHighlights.

private void collectHighlights(@NotNull PsiElement element, @NotNull List<HighlightInfo> inside, @NotNull List<HighlightInfo> outside, @NotNull ProperTextRange priorityRange) {
    EditorColorsScheme scheme = ObjectUtils.notNull(getColorsScheme(), EditorColorsManager.getInstance().getGlobalScheme());
    TextAttributes defaultAttrs = scheme.getAttributes(HighlighterColors.TEXT);
    Language language = ILazyParseableElementType.LANGUAGE_KEY.get(element.getNode());
    if (language == null)
        return;
    SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, myProject, myFile.getVirtualFile());
    for (PsiElement token : psiTraverser(element).traverse(TreeTraversal.LEAVES_DFS)) {
        TextRange tr = token.getTextRange();
        if (tr.isEmpty())
            continue;
        IElementType type = PsiUtilCore.getElementType(token);
        TextAttributesKey[] keys = syntaxHighlighter.getTokenHighlights(type);
        // force attribute colors to override host' ones
        TextAttributes attributes = null;
        for (TextAttributesKey key : keys) {
            TextAttributes attrs2 = scheme.getAttributes(key);
            if (attrs2 != null) {
                attributes = attributes == null ? attrs2 : TextAttributes.merge(attributes, attrs2);
            }
        }
        TextAttributes forcedAttributes;
        if (attributes == null || attributes.isEmpty() || attributes.equals(defaultAttrs)) {
            forcedAttributes = TextAttributes.ERASE_MARKER;
        } else {
            HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(tr).textAttributes(TextAttributes.ERASE_MARKER).createUnconditionally();
            (priorityRange.contains(tr) ? inside : outside).add(info);
            forcedAttributes = new TextAttributes(attributes.getForegroundColor(), attributes.getBackgroundColor(), attributes.getEffectColor(), attributes.getEffectType(), attributes.getFontType());
        }
        HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(tr).textAttributes(forcedAttributes).createUnconditionally();
        (priorityRange.contains(tr) ? inside : outside).add(info);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Language(com.intellij.lang.Language) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) PsiElement(com.intellij.psi.PsiElement)

Example 10 with TextAttributesKey

use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.

the class SeverityEditorDialog method doOKAction.

@Override
protected void doOKAction() {
    apply((SeverityBasedTextAttributes) myOptionsList.getSelectedValue());
    final Collection<SeverityBasedTextAttributes> infoTypes = new HashSet<>(SeverityUtil.getRegisteredHighlightingInfoTypes(mySeverityRegistrar));
    final ListModel listModel = myOptionsList.getModel();
    final List<HighlightSeverity> order = new ArrayList<>();
    for (int i = listModel.getSize() - 1; i >= 0; i--) {
        SeverityBasedTextAttributes info = (SeverityBasedTextAttributes) listModel.getElementAt(i);
        order.add(info.getSeverity());
        if (!mySeverityRegistrar.isDefaultSeverity(info.getSeverity())) {
            infoTypes.remove(info);
            final Color stripeColor = info.getAttributes().getErrorStripeColor();
            final boolean exists = mySeverityRegistrar.getSeverity(info.getSeverity().getName()) != null;
            if (exists) {
                info.getType().getAttributesKey().getDefaultAttributes().setErrorStripeColor(stripeColor);
            } else {
                HighlightInfoType.HighlightInfoTypeImpl type = info.getType();
                TextAttributesKey key = type.getAttributesKey();
                final TextAttributes defaultAttributes = key.getDefaultAttributes().clone();
                defaultAttributes.setErrorStripeColor(stripeColor);
                key = TextAttributesKey.createTextAttributesKey(key.getExternalName(), defaultAttributes);
                type = new HighlightInfoType.HighlightInfoTypeImpl(type.getSeverity(null), key);
                info = new SeverityBasedTextAttributes(info.getAttributes(), type);
            }
            mySeverityRegistrar.registerSeverity(info, stripeColor != null ? stripeColor : LightColors.YELLOW);
        }
    }
    for (SeverityBasedTextAttributes info : infoTypes) {
        mySeverityRegistrar.unregisterSeverity(info.getSeverity());
    }
    mySeverityRegistrar.setOrder(order);
    super.doOKAction();
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) SeverityBasedTextAttributes(com.intellij.codeInsight.daemon.impl.SeverityRegistrar.SeverityBasedTextAttributes) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SeverityBasedTextAttributes(com.intellij.codeInsight.daemon.impl.SeverityRegistrar.SeverityBasedTextAttributes)

Aggregations

TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)49 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)28 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)12 NotNull (org.jetbrains.annotations.NotNull)9 IElementType (com.intellij.psi.tree.IElementType)8 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)7 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)6 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)6 TextRange (com.intellij.openapi.util.TextRange)5 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)4 HighlightData (com.intellij.application.options.colors.highlighting.HighlightData)3 PresentationData (com.intellij.ide.projectView.PresentationData)3 Language (com.intellij.lang.Language)3 Lexer (com.intellij.lexer.Lexer)3 SyntaxHighlighter (com.intellij.openapi.fileTypes.SyntaxHighlighter)3 AttributesDescriptor (com.intellij.openapi.options.colors.AttributesDescriptor)3 Project (com.intellij.openapi.project.Project)3 Pair (com.intellij.openapi.util.Pair)3 PsiElement (com.intellij.psi.PsiElement)3 NamedScope (com.intellij.psi.search.scope.packageSet.NamedScope)3