added cancel handling to definition requests

This commit is contained in:
Martin Lippert
2021-02-26 12:16:33 +01:00
parent 28aea97b71
commit 607781779e
9 changed files with 87 additions and 19 deletions

View File

@@ -17,6 +17,7 @@ import java.util.stream.Collectors;
import org.eclipse.lsp4j.DefinitionParams;
import org.eclipse.lsp4j.LocationLink;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -61,23 +62,32 @@ public class PropertiesJavaDefinitionHandler implements DefinitionHandler, Langu
private BootLanguageServerParams params;
@Override
public List<LocationLink> handle(DefinitionParams definitionParams) {
public List<LocationLink> handle(CancelChecker cancelToken, DefinitionParams definitionParams) {
try {
TextDocument doc = documents.getLatestSnapshot(definitionParams);
TypeUtil typeUtil = params.typeUtilProvider.getTypeUtil(sourceLinks, doc);
cancelToken.checkCanceled();
FuzzyMap<PropertyInfo> index = params.indexProvider.getIndex(doc).getProperties();
int offset;
offset = doc.toOffset(definitionParams.getPosition());
return getDefinitions(index, typeUtil, doc, offset);
cancelToken.checkCanceled();
return getDefinitions(cancelToken, index, typeUtil, doc, offset);
} catch (BadLocationException e) {
return ImmutableList.of();
}
}
private List<LocationLink> getDefinitions(FuzzyMap<PropertyInfo> index, TypeUtil typeUtil, TextDocument doc, int offset) {
private List<LocationLink> getDefinitions(CancelChecker cancelToken, FuzzyMap<PropertyInfo> index, TypeUtil typeUtil, TextDocument doc, int offset) {
IJavaProject project = typeUtil.getJavaProject();
PropertyFinder propertyFinder = new PropertyFinder(index, typeUtil, doc, offset);
Node node = propertyFinder.findNode();
cancelToken.checkCanceled();
try {
Range selectionRange = doc.toRange(node.getOffset(), node.getLength());
if (node instanceof Key) {

View File

@@ -46,6 +46,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CancellationException;
import org.eclipse.lemminx.dom.DOMAttr;
import org.eclipse.lemminx.dom.DOMDocument;
@@ -57,6 +58,7 @@ import org.eclipse.lemminx.dom.parser.XMLScanner;
import org.eclipse.lsp4j.DefinitionParams;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.LocationLink;
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.java.links.JavaElementLocationProvider;
@@ -140,17 +142,22 @@ public class XmlBeansConfigDefinitionHandler implements DefinitionHandler, Langu
}
@Override
public List<LocationLink> handle(DefinitionParams params) {
public List<LocationLink> handle(CancelChecker cancelToken, DefinitionParams params) {
try {
if (config.isSpringXMLSupportEnabled() && config.areXmlHyperlinksEnabled()) {
TextDocument doc = documents.getLatestSnapshot(params);
if (doc != null) {
cancelToken.checkCanceled();
String content = doc.get();
DOMParser parser = DOMParser.getInstance();
DOMDocument dom = parser.parse(content, "", null);
int offset = doc.toOffset(params.getPosition());
cancelToken.checkCanceled();
DOMNode node = dom.findNodeBefore(offset);
@@ -159,6 +166,7 @@ public class XmlBeansConfigDefinitionHandler implements DefinitionHandler, Langu
Scanner scanner = XMLScanner.createScanner(content, node.getStart(), false);
TokenType token = scanner.scan();
while (token != TokenType.EOS && scanner.getTokenOffset() <= offset) {
switch (token) {
case AttributeValue:
@@ -200,6 +208,8 @@ public class XmlBeansConfigDefinitionHandler implements DefinitionHandler, Langu
}
}
}
} catch (CancellationException e) {
throw e;
} catch (Exception e) {
log.error("{}", e);
}

View File

@@ -12,12 +12,14 @@ package org.springframework.ide.vscode.boot.app;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.stream.Collectors;
import org.eclipse.lsp4j.DefinitionParams;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.LocationLink;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -68,18 +70,26 @@ public class YamlPropertiesJavaDefinitionHandler implements DefinitionHandler, L
}
@Override
public List<LocationLink> handle(DefinitionParams definitionParams) {
public List<LocationLink> handle(CancelChecker cancelToken, DefinitionParams definitionParams) {
try {
TextDocument doc = documents.getLatestSnapshot(definitionParams);
int offset = doc.toOffset(definitionParams.getPosition());
cancelToken.checkCanceled();
YamlFileAST ast = getAst(doc);
if (ast != null) {
YamlDocument ymlDoc = new YamlDocument(doc, structureProvider);
YamlAssistContext assistContext = assistContextProvider.getGlobalAssistContext(ymlDoc);
if (assistContext != null) {
List<NodeRef<?>> astPath = ast.findPath(offset);
final YamlPath path = YamlPath.fromASTPath(astPath);
if (path != null) {
cancelToken.checkCanceled();
YamlPath assistPath = path;
if (assistPath.pointsAtKey()) {
// When a path points at a key we must tramsform it to a
@@ -119,6 +129,8 @@ public class YamlPropertiesJavaDefinitionHandler implements DefinitionHandler, L
}
}
}
} catch (CancellationException e) {
throw e;
} catch (Exception e) {
log.error("", e);
}