my class base
class HurlSyntaxHighlighter : SyntaxHighlighterBase() {
override fun getHighlightingLexer(): Lexer {
return SimpleHurlAdapter()
}
override fun getTokenHighlights(p0: IElementType?): Array<out TextAttributesKey?> {
return when (p0) {
HurlElementTypes.GET, HurlElementTypes.POST, HurlElementTypes.PUT, HurlElementTypes.PATCH, HurlElementTypes.DELETE, HurlElementTypes.HEAD,
HurlElementTypes.OPTIONS, HurlElementTypes.TRACE, HurlElementTypes.CONNECT -> {
return METHOD_KEYS
}
HurlElementTypes.TEMP -> {
return VARIABLE_KEYS
}
HurlElementTypes.VARIABLE_START, HurlElementTypes.VARIABLE_END -> {
return DOTS_KEYS
}
HurlElementTypes.IDENTIFIER -> {
return IDENTIFIER_KEYS
}
TokenType.BAD_CHARACTER -> {
return BAD_CHARACTER_KEYS
}
HurlElementTypes.STRING,HurlElementTypes.URL_OR_TEMP -> {
return STRING_KEYS
}
else -> emptyArray()
}
}
companion object {
val METHOD = createTextAttributesKey("HURL_METHOD", DefaultLanguageHighlighterColors.KEYWORD)
val VARIABLE = createTextAttributesKey("HURL_VARIABLE", DefaultLanguageHighlighterColors.GLOBAL_VARIABLE)
val DOTS = createTextAttributesKey("HURL_DOT", DefaultLanguageHighlighterColors.OPERATION_SIGN)
val IDENTIFIER = createTextAttributesKey("HURL_IDENTIFIER", DefaultLanguageHighlighterColors.IDENTIFIER)
val BAD_CHARACTER = createTextAttributesKey("HURL_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER)
val STRING = createTextAttributesKey("HURL_STRING", DefaultLanguageHighlighterColors.STRING)
val METHOD_KEYS = arrayOf(METHOD)
val VARIABLE_KEYS = arrayOf(VARIABLE)
val DOTS_KEYS = arrayOf(DOTS)
val IDENTIFIER_KEYS = arrayOf(IDENTIFIER)
val BAD_CHARACTER_KEYS = arrayOf(BAD_CHARACTER)
val STRING_KEYS = arrayOf(STRING)
}
}
It only highlights the Method, the others are not effective
my types
public interface HurlElementTypes {
IElementType HTTP_REQUEST_LINE = new HurlElementType("HTTP_REQUEST_LINE");
IElementType METHOD = new HurlElementType("METHOD");
IElementType TEMP = new HurlElementType("TEMP");
IElementType URL_OR_TEMP = new HurlElementType("URL_OR_TEMP");
IElementType VARIABLE = new HurlElementType("VARIABLE");
IElementType AND = new HurlTokenType("&");
IElementType BACKSLASH = new HurlTokenType("\\");
IElementType COMMENT = new HurlTokenType("COMMENT");
IElementType CONNECT = new HurlTokenType("CONNECT");
IElementType DELETE = new HurlTokenType("DELETE");
IElementType DOT = new HurlTokenType(".");
IElementType EQ = new HurlTokenType("=");
IElementType GET = new HurlTokenType("GET");
IElementType HEAD = new HurlTokenType("HEAD");
IElementType IDENTIFIER = new HurlTokenType("IDENTIFIER");
IElementType MINUS = new HurlTokenType("-");
IElementType NUMBER = new HurlTokenType("NUMBER");
IElementType OPTIONS = new HurlTokenType("OPTIONS");
IElementType PATCH = new HurlTokenType("PATCH");
IElementType POST = new HurlTokenType("POST");
IElementType PUT = new HurlTokenType("PUT");
IElementType QUESTION = new HurlTokenType("?");
IElementType SLASH = new HurlTokenType("/");
IElementType SPACE = new HurlTokenType(" ");
IElementType STRING = new HurlTokenType("STRING");
IElementType TRACE = new HurlTokenType("TRACE");
IElementType UNDERSCORE = new HurlTokenType("_");
IElementType URL = new HurlTokenType("URL");
IElementType VARIABLE_END = new HurlTokenType("}}");
IElementType VARIABLE_START = new HurlTokenType("{{");
class Factory {
public static PsiElement createElement(ASTNode node) {
IElementType type = node.getElementType();
if (type == HTTP_REQUEST_LINE) {
return new HurlHttpRequestLineImpl(node);
}
else if (type == METHOD) {
return new HurlMethodImpl(node);
}
else if (type == TEMP) {
return new HurlTempImpl(node);
}
else if (type == URL_OR_TEMP) {
return new HurlUrlOrTempImpl(node);
}
else if (type == VARIABLE) {
return new HurlVariableImpl(node);
}
throw new AssertionError("Unknown element type: " + type);
}
}
}