Search in sources :

Example 16 with SemanticTokens

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);
}
Also used : SemanticTokens(org.eclipse.lsp4j.SemanticTokens) Test(org.junit.jupiter.api.Test)

Example 17 with SemanticTokens

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);
}
Also used : SemanticTokens(org.eclipse.lsp4j.SemanticTokens) Test(org.junit.jupiter.api.Test)

Example 18 with SemanticTokens

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);
}
Also used : ArrayList(java.util.ArrayList) AstNode(com.sonar.sslr.api.AstNode) SemanticTokens(org.eclipse.lsp4j.SemanticTokens)

Example 19 with SemanticTokens

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);
}
Also used : SemanticTokens(org.eclipse.lsp4j.SemanticTokens) Test(org.junit.jupiter.api.Test)

Example 20 with SemanticTokens

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);
}
Also used : SemanticTokens(org.eclipse.lsp4j.SemanticTokens) Test(org.junit.jupiter.api.Test)

Aggregations

SemanticTokens (org.eclipse.lsp4j.SemanticTokens)27 Test (org.junit.jupiter.api.Test)21 ArrayList (java.util.ArrayList)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 SemanticTokensParams (org.eclipse.lsp4j.SemanticTokensParams)2 SemanticTokensWithRegistrationOptions (org.eclipse.lsp4j.SemanticTokensWithRegistrationOptions)2 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)2 RedmatchLexer (au.csiro.redmatch.grammar.RedmatchLexer)1 JsonArray (com.google.gson.JsonArray)1 AstNode (com.sonar.sslr.api.AstNode)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1