Missing semantic tokens for Java
This commit is contained in:
@@ -23,6 +23,7 @@ import org.eclipse.lsp4j.SemanticTokensLegend;
|
||||
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;
|
||||
@@ -76,7 +77,8 @@ public class JdtSemanticTokensHandler implements SemanticTokensHandler {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.eclipse.jdt.core.dom.MethodInvocation;
|
||||
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;
|
||||
@@ -175,7 +176,22 @@ public class CompositeASTVisitor extends ASTVisitor {
|
||||
}
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user