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

@@ -16,6 +16,7 @@ import java.util.List;
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.ide.vscode.commons.languageserver.util.DefinitionHandler;
@@ -39,7 +40,7 @@ public class SimpleDefinitionFinder implements DefinitionHandler {
}
@Override
public List<LocationLink> handle(DefinitionParams params) {
public List<LocationLink> handle(CancelChecker cancelToken, DefinitionParams params) {
try {
TextDocument doc = server.getTextDocumentService().getLatestSnapshot(params.getTextDocument().getUri());

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2020 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,8 +14,9 @@ import java.util.List;
import org.eclipse.lsp4j.DefinitionParams;
import org.eclipse.lsp4j.LocationLink;
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
@FunctionalInterface
public interface DefinitionHandler {
List<LocationLink> handle(DefinitionParams definitionParams);
List<LocationLink> handle(CancelChecker cancelToken, DefinitionParams definitionParams);
}

View File

@@ -319,7 +319,10 @@ public class SimpleTextDocumentService implements TextDocumentService, DocumentE
DefinitionHandler h = this.definitionHandler;
if (h != null) {
return CompletableFutures.computeAsync(cancelToken -> {
List<LocationLink> locations = h.handle(definitionParams);
cancelToken.checkCanceled();
List<LocationLink> locations = h.handle(cancelToken, definitionParams);
if (locations == null) {
// vscode client does not like to receive null result. See: https://github.com/spring-projects/sts4/issues/309
locations = ImmutableList.of();