added cancel handling to code lens 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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
@@ -14,10 +14,11 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.eclipse.lsp4j.CodeLens;
|
import org.eclipse.lsp4j.CodeLens;
|
||||||
import org.eclipse.lsp4j.CodeLensParams;
|
import org.eclipse.lsp4j.CodeLensParams;
|
||||||
|
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface CodeLensHandler {
|
public interface CodeLensHandler {
|
||||||
|
|
||||||
List<? extends CodeLens> handle(CodeLensParams params);
|
List<? extends CodeLens> handle(CancelChecker cancelToken, CodeLensParams params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -422,7 +422,7 @@ public class SimpleTextDocumentService implements TextDocumentService, DocumentE
|
|||||||
|
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
return CompletableFutures.computeAsync(cancelToken -> {
|
return CompletableFutures.computeAsync(cancelToken -> {
|
||||||
return handler.handle(params);
|
return handler.handle(cancelToken, params);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||||
|
|||||||
@@ -13,10 +13,12 @@ package org.springframework.ide.vscode.boot.java.handlers;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import org.eclipse.lsp4j.CodeLens;
|
import org.eclipse.lsp4j.CodeLens;
|
||||||
import org.eclipse.lsp4j.CodeLensParams;
|
import org.eclipse.lsp4j.CodeLensParams;
|
||||||
|
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
|
||||||
import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents;
|
import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents;
|
||||||
import org.springframework.ide.vscode.commons.languageserver.util.CodeLensHandler;
|
import org.springframework.ide.vscode.commons.languageserver.util.CodeLensHandler;
|
||||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
|
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
|
||||||
@@ -36,7 +38,7 @@ public class BootJavaCodeLensEngine implements CodeLensHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends CodeLens> handle(CodeLensParams params) {
|
public List<? extends CodeLens> handle(CancelChecker cancelToken, CodeLensParams params) {
|
||||||
SimpleTextDocumentService documents = server.getTextDocumentService();
|
SimpleTextDocumentService documents = server.getTextDocumentService();
|
||||||
String docURI = params.getTextDocument().getUri();
|
String docURI = params.getTextDocument().getUri();
|
||||||
|
|
||||||
@@ -45,11 +47,14 @@ public class BootJavaCodeLensEngine implements CodeLensHandler {
|
|||||||
// Spring Boot LS get events from boot properties files as well, so filter them out
|
// Spring Boot LS get events from boot properties files as well, so filter them out
|
||||||
if (server.getInterestingLanguages().contains(doc.getLanguageId())) {
|
if (server.getInterestingLanguages().contains(doc.getLanguageId())) {
|
||||||
try {
|
try {
|
||||||
List<? extends CodeLens> codeLensesResult = provideCodeLenses(doc);
|
List<? extends CodeLens> codeLensesResult = provideCodeLenses(cancelToken, doc);
|
||||||
if (codeLensesResult != null) {
|
if (codeLensesResult != null) {
|
||||||
return codeLensesResult;
|
return codeLensesResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (CancellationException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,13 +63,13 @@ public class BootJavaCodeLensEngine implements CodeLensHandler {
|
|||||||
return SimpleTextDocumentService.NO_CODELENS;
|
return SimpleTextDocumentService.NO_CODELENS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<? extends CodeLens> provideCodeLenses(TextDocument document) {
|
private List<? extends CodeLens> provideCodeLenses(CancelChecker cancelToken, TextDocument document) {
|
||||||
return server.getCompilationUnitCache().withCompilationUnit(document, cu -> {
|
return server.getCompilationUnitCache().withCompilationUnit(document, cu -> {
|
||||||
|
|
||||||
if (cu != null) {
|
if (cu != null) {
|
||||||
List<CodeLens> result = new ArrayList<>();
|
List<CodeLens> result = new ArrayList<>();
|
||||||
for (CodeLensProvider codeLensProvider : codelensProviders) {
|
for (CodeLensProvider codeLensProvider : codelensProviders) {
|
||||||
codeLensProvider.provideCodeLenses(document, cu, result);
|
codeLensProvider.provideCodeLenses(cancelToken, document, cu, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.size() > 0) {
|
if (result.size() > 0) {
|
||||||
|
|||||||
@@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
@@ -14,6 +14,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.eclipse.jdt.core.dom.CompilationUnit;
|
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||||
import org.eclipse.lsp4j.CodeLens;
|
import org.eclipse.lsp4j.CodeLens;
|
||||||
|
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
|
||||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,6 +22,6 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
|||||||
*/
|
*/
|
||||||
public interface CodeLensProvider {
|
public interface CodeLensProvider {
|
||||||
|
|
||||||
public void provideCodeLenses(TextDocument document, CompilationUnit cu, List<CodeLens> resultAccumulator);
|
public void provideCodeLenses(CancelChecker cancelToken, TextDocument document, CompilationUnit cu, List<CodeLens> resultAccumulator);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2018, 2019 Pivotal, Inc.
|
* Copyright (c) 2018, 2021 Pivotal, Inc.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
@@ -18,6 +18,7 @@ import org.eclipse.jdt.core.dom.IMethodBinding;
|
|||||||
import org.eclipse.jdt.core.dom.MethodDeclaration;
|
import org.eclipse.jdt.core.dom.MethodDeclaration;
|
||||||
import org.eclipse.lsp4j.CodeLens;
|
import org.eclipse.lsp4j.CodeLens;
|
||||||
import org.eclipse.lsp4j.Command;
|
import org.eclipse.lsp4j.Command;
|
||||||
|
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
|
||||||
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
|
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
|
||||||
import org.springframework.ide.vscode.boot.java.handlers.CodeLensProvider;
|
import org.springframework.ide.vscode.boot.java.handlers.CodeLensProvider;
|
||||||
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
|
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
|
||||||
@@ -36,17 +37,19 @@ public class WebfluxHandlerCodeLensProvider implements CodeLensProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void provideCodeLenses(TextDocument document, CompilationUnit cu, List<CodeLens> resultAccumulator) {
|
public void provideCodeLenses(CancelChecker cancelToken, TextDocument document, CompilationUnit cu, List<CodeLens> resultAccumulator) {
|
||||||
cu.accept(new ASTVisitor() {
|
cu.accept(new ASTVisitor() {
|
||||||
@Override
|
@Override
|
||||||
public boolean visit(MethodDeclaration node) {
|
public boolean visit(MethodDeclaration node) {
|
||||||
provideCodeLens(node, document, resultAccumulator);
|
provideCodeLens(cancelToken, node, document, resultAccumulator);
|
||||||
return super.visit(node);
|
return super.visit(node);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void provideCodeLens(MethodDeclaration node, TextDocument document, List<CodeLens> resultAccumulator) {
|
protected void provideCodeLens(CancelChecker cancelToken, MethodDeclaration node, TextDocument document, List<CodeLens> resultAccumulator) {
|
||||||
|
cancelToken.checkCanceled();
|
||||||
|
|
||||||
IMethodBinding methodBinding = node.resolveBinding();
|
IMethodBinding methodBinding = node.resolveBinding();
|
||||||
|
|
||||||
if (methodBinding != null && methodBinding.getDeclaringClass() != null && methodBinding.getMethodDeclaration() != null
|
if (methodBinding != null && methodBinding.getDeclaringClass() != null && methodBinding.getMethodDeclaration() != null
|
||||||
@@ -54,6 +57,8 @@ public class WebfluxHandlerCodeLensProvider implements CodeLensProvider {
|
|||||||
|
|
||||||
final String handlerClass = methodBinding.getDeclaringClass().getBinaryName().trim();
|
final String handlerClass = methodBinding.getDeclaringClass().getBinaryName().trim();
|
||||||
final String handlerMethod = methodBinding.getMethodDeclaration().toString().trim();
|
final String handlerMethod = methodBinding.getMethodDeclaration().toString().trim();
|
||||||
|
|
||||||
|
cancelToken.checkCanceled();
|
||||||
|
|
||||||
List<SymbolAddOnInformation> handlerInfos = this.springIndexer.getAllAdditionalInformation((addon) -> {
|
List<SymbolAddOnInformation> handlerInfos = this.springIndexer.getAllAdditionalInformation((addon) -> {
|
||||||
if (addon instanceof WebfluxHandlerInformation) {
|
if (addon instanceof WebfluxHandlerInformation) {
|
||||||
|
|||||||
Reference in New Issue
Block a user