diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/JdtSemanticTokensHandler.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/JdtSemanticTokensHandler.java index 1bc0020d53..5324e1d876 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/JdtSemanticTokensHandler.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/JdtSemanticTokensHandler.java @@ -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; @@ -76,7 +77,8 @@ private List semanticTokens(TextDocument doc, CancelChecker c if (optProject.isPresent()) { IJavaProject jp = optProject.get(); List 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)); } } diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/reconcilers/CompositeASTVisitor.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/reconcilers/CompositeASTVisitor.java index f1dc3fece6..5d40dde422 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/reconcilers/CompositeASTVisitor.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/reconcilers/CompositeASTVisitor.java @@ -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; @@ -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);