use of org.eclipse.lsp4j.SemanticTokens in project magik-tools by StevenLooman.
the class SemanticTokenProviderTest method testDocCommentParamCombinedType.
@Test
void testDocCommentParamCombinedType() {
final String code = " ## @param {sw:float|sw:integer} p1 Description of p1";
final SemanticTokens semanticTokens = this.getSemanticTokens(code);
final int docModifier = SemanticToken.Modifier.DOCUMENTATION.getModifierType();
assertThat(semanticTokens.getData()).containsExactly(0, 1, "##".length(), SemanticToken.Type.COMMENT.getTokenType(), docModifier, 0, 3, "@param".length(), SemanticToken.Type.KEYWORD.getTokenType(), docModifier, 0, 8, "sw:float".length(), SemanticToken.Type.CLASS.getTokenType(), docModifier, 0, 9, "sw:integer".length(), SemanticToken.Type.CLASS.getTokenType(), docModifier, 0, 12, "p1".length(), SemanticToken.Type.PARAMETER.getTokenType(), docModifier, 0, 3, "Description of p1".length(), SemanticToken.Type.COMMENT.getTokenType(), docModifier);
}
use of org.eclipse.lsp4j.SemanticTokens in project magik-tools by StevenLooman.
the class SemanticTokenProviderTest method testComment.
@Test
void testComment() {
final String code = " # comment";
final SemanticTokens semanticTokens = this.getSemanticTokens(code);
assertThat(semanticTokens.getData()).containsExactly(0, 1, "# comment".length(), SemanticToken.Type.COMMENT.getTokenType(), 0);
}
use of org.eclipse.lsp4j.SemanticTokens in project magik-tools by StevenLooman.
the class SemanticTokenProvider method provideSemanticTokensFull.
/**
* Build SemanticTokens.
* @param magikFile Magik file.
* @return SemanticTokens.
* @throws IOException -
*/
public SemanticTokens provideSemanticTokensFull(final MagikTypedFile magikFile) {
LOGGER.debug("Providing semantic tokens full");
// Walk AST, building SemanticTokens.
final SemanticTokenWalker walker = new SemanticTokenWalker(magikFile);
final AstNode topNode = magikFile.getTopNode();
walker.walkAst(topNode);
// Build data list.
final List<SemanticToken> walkedSemanticTokens = walker.getSemanticTokens();
if (walkedSemanticTokens.isEmpty()) {
return new SemanticTokens(Collections.emptyList());
}
final ArrayList<Integer> data = new ArrayList<>((walkedSemanticTokens.size() - 1) * SIZE_PER_TOKEN);
final SemanticToken startSemanticToken = this.createStartSemanticToken();
Stream.concat(Stream.of(startSemanticToken), walkedSemanticTokens.stream()).reduce((s1, s2) -> {
s2.dataToPrevious(s1).collect(Collectors.toCollection(() -> data));
return s2;
});
return new SemanticTokens(data);
}
use of org.eclipse.lsp4j.SemanticTokens in project magik-tools by StevenLooman.
the class SemanticTokenProviderTest method testOperator.
@Test
void testOperator() {
final String code = "a + b";
final SemanticTokens semanticTokens = this.getSemanticTokens(code);
final int varGlobalModifier = SemanticToken.Modifier.VARIABLE_GLOBAL.getModifierType();
assertThat(semanticTokens.getData()).containsExactly(0, 0, "a".length(), SemanticToken.Type.VARIABLE.getTokenType(), varGlobalModifier, 0, 2, "+".length(), SemanticToken.Type.OPERATOR.getTokenType(), 0, 0, 2, "b".length(), SemanticToken.Type.VARIABLE.getTokenType(), varGlobalModifier);
}
use of org.eclipse.lsp4j.SemanticTokens in project magik-tools by StevenLooman.
the class SemanticTokenProviderTest method testMethodInvocation.
@Test
void testMethodInvocation() {
final String code = "a.method()";
final SemanticTokens semanticTokens = this.getSemanticTokens(code);
final int varGlobalModifier = SemanticToken.Modifier.VARIABLE_GLOBAL.getModifierType();
assertThat(semanticTokens.getData()).containsExactly(0, 0, "a".length(), SemanticToken.Type.VARIABLE.getTokenType(), varGlobalModifier, 0, 2, "method".length(), SemanticToken.Type.METHOD.getTokenType(), 0);
}
Aggregations