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);
}
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;
});
}
Aggregations