Skip to content

Commit

Permalink
Missing semantic tokens for Java
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Oct 15, 2024
1 parent 00d423a commit b6cb5d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.lsp4j.SemanticTokensWithRegistrationOptions;
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
import org.springframework.ide.vscode.boot.java.reconcilers.CompositeASTVisitor;
import org.springframework.ide.vscode.boot.java.semantictokens.JavaSemanticTokensProvider;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
Expand Down Expand Up @@ -76,7 +77,8 @@ private List<SemanticTokenData> semanticTokens(TextDocument doc, CancelChecker c
if (optProject.isPresent()) {
IJavaProject jp = optProject.get();
List<JdtSemanticTokensProvider> applicableTokenProviders = tokenProviders.stream().filter(tp -> tp.isApplicable(jp)).collect(Collectors.toList());
if (!applicableTokenProviders.isEmpty()) {
// If only the JavaSemanticTokensProvider going to compute tokens then don't compute tokens at all - let JDT LS compute them.
if (!applicableTokenProviders.isEmpty() && !(applicableTokenProviders.size() == 1 && applicableTokenProviders.get(0) instanceof JavaSemanticTokensProvider)) {
return cuCache.withCompilationUnit(jp, URI.create(doc.getUri()), cu -> computeTokens(applicableTokenProviders, jp, cu, r, doc));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.jdt.core.dom.NormalAnnotation;
import org.eclipse.jdt.core.dom.QualifiedName;
import org.eclipse.jdt.core.dom.ReturnStatement;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
import org.eclipse.jdt.core.dom.TypeDeclaration;
Expand Down Expand Up @@ -175,7 +176,22 @@ public boolean visit(ReturnStatement node) {
}
return result;
}


/*
* Needed for the JDT LS semantic tokens workaround
*/
@Override
public boolean visit(SimpleName node) {
boolean result = true;
if (!checkOffset(node)) {
return false;
}
for (ASTVisitor astVisitor : visitors) {
result |= astVisitor.visit(node);
}
return result;
}

private boolean checkOffset(ASTNode n) {
return (startOffset < 0 || n.getStartPosition() >= startOffset)
|| (endOffset <0 || n.getStartPosition() + n.getLength() < endOffset);
Expand Down

0 comments on commit b6cb5d0

Please sign in to comment.