added cancel handling to highlight requests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018, 2020 Pivotal, Inc.
|
||||
* Copyright (c) 2018, 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.DocumentHighlight;
|
||||
import org.eclipse.lsp4j.DocumentHighlightParams;
|
||||
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface DocumentHighlightHandler {
|
||||
|
||||
List<? extends DocumentHighlight> handle(DocumentHighlightParams highligtParams);
|
||||
List<? extends DocumentHighlight> handle(CancelChecker cancelToken, DocumentHighlightParams highligtParams);
|
||||
|
||||
}
|
||||
|
||||
@@ -473,7 +473,7 @@ public class SimpleTextDocumentService implements TextDocumentService, DocumentE
|
||||
DocumentHighlightHandler handler = this.documentHighlightHandler;
|
||||
if (handler != null) {
|
||||
return CompletableFutures.computeAsync(cancelToken -> {
|
||||
return handler.handle(highlightParams);
|
||||
return handler.handle(cancelToken, highlightParams);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.List;
|
||||
import org.eclipse.lsp4j.DocumentHighlight;
|
||||
import org.eclipse.lsp4j.DocumentHighlightParams;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents;
|
||||
@@ -40,7 +41,7 @@ public class BootJavaDocumentHighlightEngine implements DocumentHighlightHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DocumentHighlight> handle(DocumentHighlightParams params) {
|
||||
public List<DocumentHighlight> handle(CancelChecker cancelToken, DocumentHighlightParams params) {
|
||||
SimpleTextDocumentService documents = server.getTextDocumentService();
|
||||
TextDocument doc = documents.getLatestSnapshot(params);
|
||||
|
||||
@@ -48,7 +49,7 @@ public class BootJavaDocumentHighlightEngine implements DocumentHighlightHandler
|
||||
// Spring Boot LS get events from boot properties files as well, so filter them out
|
||||
if (doc != null && server.getInterestingLanguages().contains(doc.getLanguageId())) {
|
||||
try {
|
||||
return provideDocumentHighlights(doc, params.getPosition());
|
||||
return provideDocumentHighlights(cancelToken, doc, params.getPosition());
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("", e);
|
||||
@@ -59,10 +60,10 @@ public class BootJavaDocumentHighlightEngine implements DocumentHighlightHandler
|
||||
return SimpleTextDocumentService.NO_HIGHLIGHTS;
|
||||
}
|
||||
|
||||
private List<DocumentHighlight> provideDocumentHighlights(TextDocument document, Position position) {
|
||||
private List<DocumentHighlight> provideDocumentHighlights(CancelChecker cancelToken, TextDocument document, Position position) {
|
||||
List<DocumentHighlight> result = new ArrayList<>();
|
||||
for (HighlightProvider highlightProvider : highlightProviders) {
|
||||
highlightProvider.provideHighlights(document, position, result);
|
||||
highlightProvider.provideHighlights(cancelToken, document, position, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2018, 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,6 +14,7 @@ import java.util.List;
|
||||
|
||||
import org.eclipse.lsp4j.DocumentHighlight;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
/**
|
||||
@@ -21,6 +22,6 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
*/
|
||||
public interface HighlightProvider {
|
||||
|
||||
public void provideHighlights(TextDocument document, Position position, List<DocumentHighlight> resultAccumulator);
|
||||
public void provideHighlights(CancelChecker cancelToken, TextDocument document, Position position, List<DocumentHighlight> resultAccumulator);
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.List;
|
||||
|
||||
import org.eclipse.lsp4j.DocumentHighlight;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
|
||||
@@ -35,8 +36,10 @@ public class WebfluxRouteHighlightProdivder implements HighlightProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideHighlights(TextDocument document, Position position, List<DocumentHighlight> resultAccumulator) {
|
||||
public void provideHighlights(CancelChecker cancelToken, TextDocument document, Position position, List<DocumentHighlight> resultAccumulator) {
|
||||
log.info("PROVIDE HIGHLIGHTS: {} / {}", position.getLine(), position.getCharacter());
|
||||
|
||||
cancelToken.checkCanceled();
|
||||
|
||||
this.springIndexer.getAdditonalInformation(document.getUri())
|
||||
.stream()
|
||||
|
||||
Reference in New Issue
Block a user