Skip to content

Commit 7285ce0

Browse files
committed
improve highlight
1 parent cb4de7b commit 7285ce0

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

src/main/java/com/tang/intellij/lua/highlighting/LuaSyntaxHighlighter.java

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ public class LuaSyntaxHighlighter extends SyntaxHighlighterBase {
5757
LuaTypes.RETURN,
5858
LuaTypes.THEN,
5959
LuaTypes.UNTIL,
60-
LuaTypes.WHILE,
61-
62-
LuaTypes.SEMI,
63-
LuaTypes.COMMA
60+
LuaTypes.WHILE
6461
);
6562
public static final TokenSet PRIMITIVE_TYPE_SET = TokenSet.create(
6663
LuaTypes.FALSE,
@@ -102,6 +99,21 @@ public class LuaSyntaxHighlighter extends SyntaxHighlighterBase {
10299
ourMap1.put(idx, JavaHighlightingColors.DOC_COMMENT);
103100
ourMap2.put(idx, JavaHighlightingColors.DOC_COMMENT_MARKUP);
104101
}
102+
103+
//key words
104+
fillMap(ourMap1, KEYWORD_TOKENS, LuaHighlightingData.KEYWORD);
105+
fillMap(ourMap1, LuaHighlightingData.KEYWORD, LuaTypes.SEMI, LuaTypes.COMMA);
106+
fillMap(ourMap1, LuaHighlightingData.OPERATORS, LuaTypes.BINARY_OP, LuaTypes.UNARY_OP);
107+
fillMap(ourMap1, LuaHighlightingData.BRACKETS, LuaTypes.LBRACK, LuaTypes.LBRACK);
108+
fillMap(ourMap1, LuaHighlightingData.BRACES, LuaTypes.LCURLY, LuaTypes.RCURLY);
109+
//comment
110+
fillMap(ourMap1, LuaHighlightingData.LINE_COMMENT, LuaTypes.SHORT_COMMENT, LuaTypes.BLOCK_COMMENT);
111+
fillMap(ourMap1, LuaHighlightingData.DOC_COMMENT, LuaTypes.REGION, LuaTypes.ENDREGION);
112+
fillMap(ourMap1, DOC_KEYWORD_TOKENS, LuaHighlightingData.DOC_COMMENT_TAG);
113+
//primitive types
114+
fillMap(ourMap1, LuaHighlightingData.NUMBER, LuaTypes.NUMBER);
115+
fillMap(ourMap1, LuaHighlightingData.STRING, LuaTypes.STRING);
116+
fillMap(ourMap1, PRIMITIVE_TYPE_SET, LuaHighlightingData.PRIMITIVE_TYPE);
105117
}
106118

107119
@NotNull
@@ -113,29 +125,8 @@ public Lexer getHighlightingLexer() {
113125
@NotNull
114126
@Override
115127
public TextAttributesKey[] getTokenHighlights(IElementType type) {
116-
if (KEYWORD_TOKENS.contains(type))
117-
return pack(LuaHighlightingData.KEYWORD);
118-
else if (type == LuaTypes.NUMBER)
119-
return pack(LuaHighlightingData.NUMBER);
120-
else if (type == LuaTypes.STRING)
121-
return pack(LuaHighlightingData.STRING);
122-
else if (type == LuaTypes.BINARY_OP || type == LuaTypes.UNARY_OP)
123-
return pack(LuaHighlightingData.OPERATORS);
124-
else if (type == LuaTypes.LBRACK || type == LuaTypes.RBRACK)
125-
return pack(LuaHighlightingData.BRACKETS);
126-
else if (type == LuaTypes.LCURLY || type == LuaTypes.RCURLY)
127-
return pack(LuaHighlightingData.BRACES);
128-
else if (PRIMITIVE_TYPE_SET.contains(type))
129-
return pack(LuaHighlightingData.PRIMITIVE_TYPE);
130-
131-
// for comment
132-
else if (type == LuaTypes.SHORT_COMMENT || type == LuaTypes.BLOCK_COMMENT)
133-
return pack(LuaHighlightingData.LINE_COMMENT);
134-
else if (DOC_KEYWORD_TOKENS.contains(type))
135-
return pack(LuaHighlightingData.DOC_COMMENT_TAG);
136-
else if (type instanceof LuaDocTokenType || type == LuaTypes.REGION || type == LuaTypes.ENDREGION)
128+
if (type instanceof LuaDocTokenType)
137129
return pack(LuaHighlightingData.DOC_COMMENT);
138-
139130
//for string
140131
else if (type == LuaStringTypes.NEXT_LINE)
141132
return pack(JavaHighlightingColors.VALID_STRING_ESCAPE);

0 commit comments

Comments
 (0)