Search in sources :

Example 26 with SemanticTokens

use of org.eclipse.lsp4j.SemanticTokens in project redmatch by aehrc.

the class SemanticTokeniserTest method testTokenise.

@Test
public void testTokenise() {
    String rule = "SCHEMA: 'src/test/resources/schema.json' (REDCAP)\n" + "\n" + "RULES: {\n" + "  TRUE { Patient<p-1>: *identifier[0].value = VALUE(record_id) }\n" + "}";
    printTokens(rule);
    // Encoded
    List<Integer> expectedTokens = Arrays.asList(0, 0, 6, 0, 0, 0, 8, 32, 2, 0, 0, 34, 6, 2, 0, 2, 0, 5, 0, 0, 1, 2, 4, 0, 0, 0, 7, 7, 7, 0, 0, 7, 1, 4, 0, 0, 1, 3, 7, 0, 0, 3, 1, 4, 0, 0, 3, 1, 5, 0, 0, 1, 10, 5, 0, 0, 11, 1, 3, 0, 0, 3, 5, 5, 0, 0, 6, 1, 4, 0, 0, 2, 5, 0, 0, 0, 6, 9, 7, 0);
    SemanticTokens semanticTokens = SemanticTokeniser.tokenise(rule);
    List<Integer> actualTokens = semanticTokens.getData();
    assertEquals(expectedTokens, actualTokens);
}
Also used : SemanticTokens(org.eclipse.lsp4j.SemanticTokens) Test(org.junit.jupiter.api.Test)

Example 27 with SemanticTokens

use of org.eclipse.lsp4j.SemanticTokens in project lxtk by lxtk-org.

the class DocumentSemanticTokensFeature method registerLanguageFeatureProvider.

@Override
Disposable registerLanguageFeatureProvider(String method, SemanticTokensWithRegistrationOptions options) {
    EventEmitter<Void> onDidChangeSemanticTokens = new EventEmitter<>();
    return SafeRun.runWithResult(rollback -> {
        Disposable registration = getLanguageService().getDocumentSemanticTokensProviders().add(new DocumentSemanticTokensProvider() {

            @Override
            public SemanticTokensWithRegistrationOptions getRegistrationOptions() {
                return options;
            }

            @Override
            public ProgressService getProgressService() {
                return getLanguageClient().getProgressService();
            }

            @Override
            public CompletableFuture<SemanticTokens> getDocumentSemanticTokens(SemanticTokensParams params) {
                Either<Boolean, SemanticTokensServerFull> full = options.getFull();
                if (full == null || !(full.isRight() || Boolean.TRUE.equals(full.getLeft())))
                    throw new UnsupportedOperationException();
                return getLanguageServer().getTextDocumentService().semanticTokensFull(params);
            }

            @Override
            public CompletableFuture<Either<SemanticTokens, SemanticTokensDelta>> getDocumentSemanticTokensDelta(SemanticTokensDeltaParams params) {
                Either<Boolean, SemanticTokensServerFull> full = options.getFull();
                if (full == null || !(full.isRight() && Boolean.TRUE.equals(full.getRight().getDelta())))
                    throw new UnsupportedOperationException();
                return getLanguageServer().getTextDocumentService().semanticTokensFullDelta(params);
            }

            @Override
            public CompletableFuture<SemanticTokens> getDocumentRangeSemanticTokens(SemanticTokensRangeParams params) {
                Either<Boolean, Object> range = options.getRange();
                if (range == null || !(range.isRight() || Boolean.TRUE.equals(range.getLeft())))
                    throw new UnsupportedOperationException();
                return getLanguageServer().getTextDocumentService().semanticTokensRange(params);
            }

            @Override
            public EventStream<Void> onDidChangeSemanticTokens() {
                return onDidChangeSemanticTokens;
            }
        });
        rollback.add(registration::dispose);
        Disposable subscription = getLanguageClient().onDidChangeSemanticTokens().subscribe(e -> onDidChangeSemanticTokens.emit(e, getLogger()));
        rollback.add(subscription::dispose);
        rollback.setLogger(getLogger());
        return rollback::run;
    });
}
Also used : Disposable(org.lxtk.util.Disposable) SemanticTokensParams(org.eclipse.lsp4j.SemanticTokensParams) DocumentSemanticTokensProvider(org.lxtk.DocumentSemanticTokensProvider) SemanticTokensDelta(org.eclipse.lsp4j.SemanticTokensDelta) SemanticTokensRangeParams(org.eclipse.lsp4j.SemanticTokensRangeParams) CompletableFuture(java.util.concurrent.CompletableFuture) EventEmitter(org.lxtk.util.EventEmitter) EventStream(org.lxtk.util.EventStream) ProgressService(org.lxtk.ProgressService) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) SemanticTokensDeltaParams(org.eclipse.lsp4j.SemanticTokensDeltaParams) SemanticTokensWithRegistrationOptions(org.eclipse.lsp4j.SemanticTokensWithRegistrationOptions) SemanticTokens(org.eclipse.lsp4j.SemanticTokens)

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