added cancel handling to references requests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2021 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -14,10 +14,11 @@ import java.util.List;
|
||||
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.ReferenceParams;
|
||||
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ReferencesHandler {
|
||||
|
||||
List<? extends Location> handle(ReferenceParams params);
|
||||
List<? extends Location> handle(CancelChecker cancelToken, ReferenceParams params);
|
||||
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ public class SimpleTextDocumentService implements TextDocumentService, DocumentE
|
||||
if (h != null) {
|
||||
|
||||
return CompletableFutures.computeAsync(cancelToken -> {
|
||||
List<? extends Location> list = h.handle(params);
|
||||
List<? extends Location> list = h.handle(cancelToken, params);
|
||||
return list != null && list.isEmpty() ? null : list;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ package org.springframework.ide.vscode.boot.java.handlers;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jdt.core.JavaCore;
|
||||
@@ -26,6 +27,7 @@ import org.eclipse.jdt.core.dom.NodeFinder;
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.ReferenceParams;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
|
||||
import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspathUtil;
|
||||
@@ -52,7 +54,7 @@ public class BootJavaReferencesHandler implements ReferencesHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Location> handle(ReferenceParams params) {
|
||||
public List<? extends Location> handle(CancelChecker cancelToken, ReferenceParams params) {
|
||||
SimpleTextDocumentService documents = server.getTextDocumentService();
|
||||
TextDocument doc = documents.getLatestSnapshot(params);
|
||||
|
||||
@@ -61,11 +63,17 @@ public class BootJavaReferencesHandler implements ReferencesHandler {
|
||||
if (server.getInterestingLanguages().contains(doc.getLanguageId())) {
|
||||
try {
|
||||
int offset = doc.toOffset(params.getPosition());
|
||||
List<? extends Location> referencesResult = provideReferences(doc, offset);
|
||||
|
||||
cancelToken.checkCanceled();
|
||||
|
||||
List<? extends Location> referencesResult = provideReferences(cancelToken, doc, offset);
|
||||
if (referencesResult != null) {
|
||||
return referencesResult;
|
||||
}
|
||||
}
|
||||
catch (CancellationException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
@@ -74,7 +82,7 @@ public class BootJavaReferencesHandler implements ReferencesHandler {
|
||||
return SimpleTextDocumentService.NO_REFERENCES;
|
||||
}
|
||||
|
||||
private List<? extends Location> provideReferences(TextDocument document, int offset) throws Exception {
|
||||
private List<? extends Location> provideReferences(CancelChecker cancelToken, TextDocument document, int offset) throws Exception {
|
||||
ASTParser parser = ASTParser.newParser(AST.JLS15);
|
||||
Map<String, String> options = JavaCore.getOptions();
|
||||
JavaCore.setComplianceOptions(JavaCore.VERSION_15, options);
|
||||
@@ -92,18 +100,21 @@ public class BootJavaReferencesHandler implements ReferencesHandler {
|
||||
String unitName = docURI.substring(docURI.lastIndexOf("/"));
|
||||
parser.setUnitName(unitName);
|
||||
parser.setSource(document.get(0, document.getLength()).toCharArray());
|
||||
|
||||
cancelToken.checkCanceled();
|
||||
|
||||
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
|
||||
ASTNode node = NodeFinder.perform(cu, offset, 0);
|
||||
|
||||
if (node != null) {
|
||||
return provideReferencesForAnnotation(node, offset, document);
|
||||
cancelToken.checkCanceled();
|
||||
return provideReferencesForAnnotation(cancelToken, node, offset, document);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<? extends Location> provideReferencesForAnnotation(ASTNode node, int offset, TextDocument doc) {
|
||||
private List<? extends Location> provideReferencesForAnnotation(CancelChecker cancelToken, ASTNode node, int offset, TextDocument doc) {
|
||||
Annotation annotation = null;
|
||||
|
||||
while (node != null && !(node instanceof Annotation)) {
|
||||
@@ -114,11 +125,12 @@ public class BootJavaReferencesHandler implements ReferencesHandler {
|
||||
annotation = (Annotation) node;
|
||||
ITypeBinding type = annotation.resolveTypeBinding();
|
||||
if (type != null) {
|
||||
|
||||
String qualifiedName = type.getQualifiedName();
|
||||
if (qualifiedName != null) {
|
||||
ReferenceProvider provider = this.referenceProviders.get(qualifiedName);
|
||||
if (provider != null) {
|
||||
return provider.provideReferences(node, annotation, type, offset, doc);
|
||||
return provider.provideReferences(cancelToken, node, annotation, type, offset, doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2021 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -16,6 +16,7 @@ import org.eclipse.jdt.core.dom.ASTNode;
|
||||
import org.eclipse.jdt.core.dom.Annotation;
|
||||
import org.eclipse.jdt.core.dom.ITypeBinding;
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
/**
|
||||
@@ -23,7 +24,7 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
*/
|
||||
public interface ReferenceProvider {
|
||||
|
||||
List<? extends Location> provideReferences(ASTNode node, Annotation annotation,
|
||||
List<? extends Location> provideReferences(CancelChecker cancelToken, ASTNode node, Annotation annotation,
|
||||
ITypeBinding type, int offset, TextDocument doc);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2021 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -20,7 +20,6 @@ import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -34,6 +33,7 @@ import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.WorkspaceFolder;
|
||||
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.ReferenceProvider;
|
||||
import org.springframework.ide.vscode.boot.properties.BootPropertiesLanguageServerComponents;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
@@ -46,7 +46,6 @@ import org.springframework.ide.vscode.java.properties.antlr.parser.AntlrParser;
|
||||
import org.springframework.ide.vscode.java.properties.parser.ParseResults;
|
||||
import org.springframework.ide.vscode.java.properties.parser.Parser;
|
||||
import org.springframework.ide.vscode.java.properties.parser.PropertiesAst.KeyValuePair;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.nodes.MappingNode;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
import org.yaml.snakeyaml.nodes.NodeId;
|
||||
@@ -64,8 +63,10 @@ public class ValuePropertyReferencesProvider implements ReferenceProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Location> provideReferences(ASTNode node, Annotation annotation,
|
||||
public List<? extends Location> provideReferences(CancelChecker cancelToken, ASTNode node, Annotation annotation,
|
||||
ITypeBinding type, int offset, TextDocument doc) {
|
||||
|
||||
cancelToken.checkCanceled();
|
||||
|
||||
try {
|
||||
// case: @Value("prefix<*>")
|
||||
|
||||
Reference in New Issue
Block a user