Skip to content

Commit

Permalink
Impl. color settings page for Expression Language Syntax Highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwojs committed Jun 5, 2021
1 parent 3501738 commit efc97a8
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package fr.adrienbrault.idea.symfony2plugin.expressionLanguage;

import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.options.colors.AttributesDescriptor;
import com.intellij.openapi.options.colors.ColorDescriptor;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.Map;

public class ExpressionLanguageColorSettingsPage implements ColorSettingsPage {

private static final AttributesDescriptor[] ATTRIBUTE_DESCRIPTORS = new AttributesDescriptor[]{
new AttributesDescriptor("Number", ExpressionLanguageSyntaxHighlighter.NUMBER),
new AttributesDescriptor("String", ExpressionLanguageSyntaxHighlighter.STRING),
new AttributesDescriptor("Identifier", ExpressionLanguageSyntaxHighlighter.IDENTIFIER),
new AttributesDescriptor("Keyword", ExpressionLanguageSyntaxHighlighter.KEYWORD),
};

@Nullable
@Override
public Icon getIcon() {
return Symfony2Icons.SYMFONY;
}

@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
return new ExpressionLanguageSyntaxHighlighter();
}

@NotNull
@Override
public String getDemoText() {
return "article.getCommentCount(true) > 100 and article.category not in [\"misc\", null, true] === false";
}

@NotNull
@Override
public String getDisplayName() {
return "Symfony Expression Language";
}

@NotNull
@Override
public AttributesDescriptor[] getAttributeDescriptors() {
return ATTRIBUTE_DESCRIPTORS;
}

@NotNull
@Override
public ColorDescriptor[] getColorDescriptors() {
return ColorDescriptor.EMPTY_ARRAY;
}

@Override
public @Nullable
Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() {
return null;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.java.IKeywordElementType;
import fr.adrienbrault.idea.symfony2plugin.expressionLanguage.psi.ExpressionLanguageTypes;
import org.jetbrains.annotations.NotNull;

Expand All @@ -14,15 +15,13 @@ public class ExpressionLanguageSyntaxHighlighter extends SyntaxHighlighterBase {

public static final TextAttributesKey NUMBER = createTextAttributesKey("NUMBER", DefaultLanguageHighlighterColors.NUMBER);
public static final TextAttributesKey STRING = createTextAttributesKey("STRING", DefaultLanguageHighlighterColors.STRING);
public static final TextAttributesKey ID = createTextAttributesKey("ID", DefaultLanguageHighlighterColors.IDENTIFIER);
public static final TextAttributesKey IDENTIFIER = createTextAttributesKey("IDENTIFIER", DefaultLanguageHighlighterColors.IDENTIFIER);
public static final TextAttributesKey FUNCTION_CALL = createTextAttributesKey("FUNCTION_CALL", DefaultLanguageHighlighterColors.FUNCTION_CALL);
public static final TextAttributesKey KEYWORD = createTextAttributesKey("KEYWORD", DefaultLanguageHighlighterColors.KEYWORD);

private static final TextAttributesKey[] NUMBER_KEYS = new TextAttributesKey[]{NUMBER};
private static final TextAttributesKey[] STRING_KEYS = new TextAttributesKey[]{STRING};
private static final TextAttributesKey[] ID_KEYS = new TextAttributesKey[]{ID};
private static final TextAttributesKey[] IDENTIFIER_KEYS = new TextAttributesKey[]{IDENTIFIER};
private static final TextAttributesKey[] FUNCTION_CALL_KEYS = new TextAttributesKey[]{FUNCTION_CALL};
private static final TextAttributesKey[] KEYWORD_KEYS = new TextAttributesKey[]{KEYWORD};
private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0];

@NotNull
Expand All @@ -39,13 +38,21 @@ public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
} else if (tokenType.equals(ExpressionLanguageTypes.STRING)) {
return STRING_KEYS;
} else if (tokenType.equals(ExpressionLanguageTypes.ID)) {
return ID_KEYS;
} else if (tokenType.equals(ExpressionLanguageTypes.IDENTIFIER)) {
return IDENTIFIER_KEYS;
} else if (tokenType.equals(ExpressionLanguageTypes.CALL_EXPR)) {
return FUNCTION_CALL_KEYS;
} else {
return EMPTY_KEYS;
} else if (tokenType.equals(ExpressionLanguageTypes.TRUE)) {
return KEYWORD_KEYS;
} else if (tokenType.equals(ExpressionLanguageTypes.FALSE)) {
return KEYWORD_KEYS;
} else if (tokenType.equals(ExpressionLanguageTypes.NULL)) {
return KEYWORD_KEYS;
} else if (tokenType.equals(ExpressionLanguageTypes.OP_IN)) {
return KEYWORD_KEYS;
} else if (tokenType.equals(ExpressionLanguageTypes.OP_NOT_IN)) {
return KEYWORD_KEYS;
} else if (tokenType.equals(ExpressionLanguageTypes.OP_MATCHES)) {
return KEYWORD_KEYS;
}

return EMPTY_KEYS;
}
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
<lang.parserDefinition language="Symfony Expression Language" implementationClass="fr.adrienbrault.idea.symfony2plugin.expressionLanguage.ExpressionLanguageParserDefinition" />
<lang.syntaxHighlighterFactory language="Symfony Expression Language" implementationClass="fr.adrienbrault.idea.symfony2plugin.expressionLanguage.ExpressionLanguageSyntaxHighlighterFactory" />
<lang.braceMatcher language="Symfony Expression Language" implementationClass="fr.adrienbrault.idea.symfony2plugin.expressionLanguage.ExpressionLanguageBraceMatcher" />
<colorSettingsPage implementation="fr.adrienbrault.idea.symfony2plugin.expressionLanguage.ExpressionLanguageColorSettingsPage"/>

<codeInsight.lineMarkerProvider language="PHP" implementationClass="fr.adrienbrault.idea.symfony2plugin.config.ServiceLineMarkerProvider"/>
<codeInsight.lineMarkerProvider language="PHP" implementationClass="fr.adrienbrault.idea.symfony2plugin.dic.ControllerMethodLineMarkerProvider"/>
Expand Down

0 comments on commit efc97a8

Please sign in to comment.