From 4c9414fa3b066273150ac5b6bac18136da1a6b75 Mon Sep 17 00:00:00 2001 From: Scott Wells Date: Thu, 12 Dec 2024 12:00:32 -0600 Subject: [PATCH] I'd noticed that "static" JavaScript/TypeScript methods were not being syntax-highlighted properly. After digging in, it's because they're being reported as non-standard token type "member" instead of "method". This addresses that omission and also creates a more formal way to add non-standard token types. --- .../DefaultSemanticTokensColorsProvider.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/redhat/devtools/lsp4ij/features/semanticTokens/DefaultSemanticTokensColorsProvider.java b/src/main/java/com/redhat/devtools/lsp4ij/features/semanticTokens/DefaultSemanticTokensColorsProvider.java index 55cf68852..89a15c945 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/features/semanticTokens/DefaultSemanticTokensColorsProvider.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/features/semanticTokens/DefaultSemanticTokensColorsProvider.java @@ -24,6 +24,14 @@ */ public class DefaultSemanticTokensColorsProvider implements SemanticTokensColorsProvider { + // Observed token types that aren't included in LSP4J's token types constants + private interface AdditionalSemanticTokenTypes { + // At a minimum, the TypeScript language server reports class members as "member" + String Member = "member"; + // LSP doesn't define "label", but vscode defines it + // See https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#standard-token-types-and-modifiers + String Label = "label"; + } @Override public @Nullable TextAttributesKey getTextAttributesKey(@NotNull String tokenType, @@ -139,7 +147,8 @@ public class DefaultSemanticTokensColorsProvider implements SemanticTokensColors // with other modifiers return SemanticTokensHighlightingColors.FUNCTION; - // method: for identifiers that declare a member function or method. + // method and member: for identifiers that declare a member function or method. + case AdditionalSemanticTokenTypes.Member: case SemanticTokenTypes.Method: { if (hasTokenModifiers(tokenModifiers, SemanticTokenModifiers.Declaration, @@ -161,9 +170,7 @@ public class DefaultSemanticTokensColorsProvider implements SemanticTokensColors return SemanticTokensHighlightingColors.MACRO; // label: for identifiers that declare a label. - case "label": - // LSP doesn't define "label", but vscode defines it - // See https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#standard-token-types-and-modifiers + case AdditionalSemanticTokenTypes.Label: return SemanticTokensHighlightingColors.LABEL; // comment: for tokens that represent a comment.