Skip to content

Commit

Permalink
Return null semantic tokens by default rather than empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed May 9, 2024
1 parent 5385c5f commit 8f691f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public interface SemanticTokensHandler {
SemanticTokensWithRegistrationOptions getCapability();

default SemanticTokens semanticTokensFull(SemanticTokensParams params, CancelChecker cancelChecker) {
return new SemanticTokens();
return null;
}

default Either<SemanticTokens, SemanticTokensDelta> semanticTokensFullDelta(SemanticTokensDeltaParams params, CancelChecker cancelChecker) {
return Either.forLeft(new SemanticTokens());
return null;
}

default SemanticTokens semanticTokensRange(SemanticTokensRangeParams params, CancelChecker cancelChecker) {
return new SemanticTokens();
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ public SemanticTokens semanticTokensFull(SemanticTokensParams params, CancelChec
return cuCache.withCompilationUnit(jp, URI.create(params.getTextDocument().getUri()), cu -> computeTokens(applicableTokenProviders, jp, cu));
}
}
return new SemanticTokens();
return null;
}

private SemanticTokens computeTokens(List<JdtSemanticTokensProvider> applicableTokenProviders, IJavaProject jp, CompilationUnit cu) {
if (cu == null) {
return new SemanticTokens();
return null;
}
List<SemanticTokenData> tokensData = applicableTokenProviders.stream().map(tp -> tp.computeTokens(jp, cu)).flatMap(t -> t.stream()).collect(Collectors.toList());
return new SemanticTokens(SemanticTokensUtils.mapTokensDataToLsp(tokensData, legend, offset -> cu.getLineNumber(offset) - 1, cu::getColumnNumber));
List<Integer> toLsp = SemanticTokensUtils.mapTokensDataToLsp(tokensData, legend, offset -> cu.getLineNumber(offset) - 1, cu::getColumnNumber);
return toLsp.isEmpty() ? null : new SemanticTokens(toLsp);
}

}

0 comments on commit 8f691f3

Please sign in to comment.