forked from redhat-developer/lsp4ij
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support for
textDocument/semanticTokens
Fixes redhat-developer#238 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
c521ff9
commit 6511cf4
Showing
18 changed files
with
752 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
...m/redhat/devtools/lsp4ij/features/semanticTokens/DefaultSemanticTokensColorsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package com.redhat.devtools.lsp4ij.features.semanticTokens; | ||
|
||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors; | ||
import com.intellij.openapi.editor.colors.TextAttributesKey; | ||
import com.intellij.psi.PsiFile; | ||
import org.eclipse.lsp4j.SemanticTokenModifiers; | ||
import org.eclipse.lsp4j.SemanticTokenTypes; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class DefaultSemanticTokensColorsProvider implements SemanticTokensColorsProvider { | ||
|
||
|
||
@Override | ||
public @Nullable TextAttributesKey getTextAttributesKey(@NotNull String tokenType, | ||
@NotNull List<String> tokenModifiers, | ||
@NotNull PsiFile file) { | ||
switch (tokenType) { | ||
|
||
// class | ||
case SemanticTokenTypes.Class: | ||
return SemanticTokensHighlightingColors.CLASS; | ||
|
||
// comment | ||
case SemanticTokenTypes.Comment: | ||
return SemanticTokensHighlightingColors.COMMENT; | ||
|
||
// decorator | ||
case SemanticTokenTypes.Decorator: | ||
return SemanticTokensHighlightingColors.DECORATOR; | ||
|
||
// enum | ||
case SemanticTokenTypes.Enum: | ||
return SemanticTokensHighlightingColors.ENUM; | ||
|
||
// enum member | ||
case SemanticTokenTypes.EnumMember: | ||
return SemanticTokensHighlightingColors.ENUM_MEMBER; | ||
|
||
// event | ||
case SemanticTokenTypes.Event: | ||
return SemanticTokensHighlightingColors.EVENT; | ||
|
||
// function | ||
case SemanticTokenTypes.Function: | ||
if (hasTokenModifiers(tokenModifiers, | ||
SemanticTokenModifiers.Declaration, | ||
SemanticTokenModifiers.Definition)) { | ||
// with declaration, definition modifiers | ||
return SemanticTokensHighlightingColors.FUNCTION_DECLARATION; | ||
} | ||
// with other modifiers | ||
return SemanticTokensHighlightingColors.FUNCTION_CALL; | ||
|
||
// interface | ||
case SemanticTokenTypes.Interface: | ||
return DefaultLanguageHighlighterColors.INTERFACE_NAME; | ||
|
||
// keyword | ||
case SemanticTokenTypes.Keyword: | ||
return SemanticTokensHighlightingColors.KEYWORD; | ||
|
||
// macro | ||
case SemanticTokenTypes.Macro: | ||
return SemanticTokensHighlightingColors.MACRO; | ||
|
||
// method | ||
case SemanticTokenTypes.Method: { | ||
if (hasTokenModifiers(tokenModifiers, | ||
SemanticTokenModifiers.Declaration, | ||
SemanticTokenModifiers.Definition)) { | ||
// with declaration, definition modifiers | ||
return SemanticTokensHighlightingColors.METHOD_DECLARATION; | ||
} | ||
// with other modifiers | ||
return SemanticTokensHighlightingColors.METHOD_CALL; | ||
} | ||
|
||
|
||
/*case "member": | ||
return SemanticTokensHighlightingColors.MEMBER_ATTRIBUTES; | ||
*/ | ||
|
||
// modifier | ||
case SemanticTokenTypes.Modifier: | ||
return SemanticTokensHighlightingColors.MODIFIER; | ||
|
||
// namespace | ||
case SemanticTokenTypes.Namespace: | ||
return DefaultLanguageHighlighterColors.METADATA; | ||
|
||
// Number | ||
case SemanticTokenTypes.Number: | ||
return SemanticTokensHighlightingColors.NUMBER; | ||
|
||
// Operator | ||
case SemanticTokenTypes.Operator: | ||
return DefaultLanguageHighlighterColors.OPERATION_SIGN; | ||
|
||
// Parameter | ||
case SemanticTokenTypes.Parameter: | ||
return DefaultLanguageHighlighterColors.PARAMETER; | ||
|
||
// Property | ||
case SemanticTokenTypes.Property: | ||
if (hasTokenModifiers(tokenModifiers, SemanticTokenModifiers.Static)) { | ||
if (hasTokenModifiers(tokenModifiers, SemanticTokenModifiers.Readonly)) { | ||
// with static, readonly modifiers | ||
return SemanticTokensHighlightingColors.STATIC_READONLY_PROPERTY; | ||
} | ||
// with static readonly modifiers | ||
return SemanticTokensHighlightingColors.STATIC_PROPERTY; | ||
} | ||
if (hasTokenModifiers(tokenModifiers, SemanticTokenModifiers.Readonly)) { | ||
// with readonly modifiers | ||
return SemanticTokensHighlightingColors.READONLY_PROPERTY; | ||
} | ||
// with other modifiers | ||
return SemanticTokensHighlightingColors.PROPERTY; | ||
|
||
case SemanticTokenTypes.Regexp: | ||
return DefaultLanguageHighlighterColors.REASSIGNED_LOCAL_VARIABLE; | ||
|
||
case SemanticTokenTypes.String: | ||
return SemanticTokensHighlightingColors.STRING; | ||
|
||
case SemanticTokenTypes.Struct: | ||
return DefaultLanguageHighlighterColors.VALID_STRING_ESCAPE; | ||
|
||
case SemanticTokenTypes.Type: | ||
return DefaultLanguageHighlighterColors.CLASS_REFERENCE; | ||
|
||
case SemanticTokenTypes.TypeParameter: | ||
return DefaultLanguageHighlighterColors.MARKUP_ATTRIBUTE; | ||
|
||
// variable | ||
case SemanticTokenTypes.Variable: | ||
return DefaultLanguageHighlighterColors.LOCAL_VARIABLE; | ||
} | ||
return null; | ||
} | ||
|
||
protected boolean hasTokenModifiers(List<String> tokenModifiers, String... checkedTokenModifiers) { | ||
if (tokenModifiers.isEmpty()) { | ||
return false; | ||
} | ||
for (var modifier : checkedTokenModifiers) { | ||
if (tokenModifiers.contains(modifier)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
protected boolean hasTokenModifiersOrEmpty(List<String> tokenModifiers, String... checkedTokenModifiers) { | ||
if (tokenModifiers.isEmpty()) { | ||
return true; | ||
} | ||
return hasTokenModifiers(tokenModifiers, checkedTokenModifiers); | ||
} | ||
} |
Oops, something went wrong.