From a8cd25e773316f13f9543f2e84f18ec04ba0de4d Mon Sep 17 00:00:00 2001 From: Victor Rubezhny Date: Sat, 5 Aug 2023 05:12:25 +0200 Subject: [PATCH] Completion "hangs" with no response #743 Getting rid of infinite waiting in LSContentAssistProcessor Issue: #743 --- .../operations/completion/LSContentAssistProcessor.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/completion/LSContentAssistProcessor.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/completion/LSContentAssistProcessor.java index a046e2230..85ac908c3 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/completion/LSContentAssistProcessor.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/completion/LSContentAssistProcessor.java @@ -64,6 +64,7 @@ public class LSContentAssistProcessor implements IContentAssistProcessor { private static final long TRIGGERS_TIMEOUT = 50; + private static final long GET_TIMEOUT = 1000; private static final long CONTEXT_INFORMATION_TIMEOUT = 1000; private IDocument currentDocument; private String errorMessage; @@ -111,7 +112,7 @@ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int .withFilter(capabilities -> capabilities.getCompletionProvider() != null) .collectAll((w, ls) -> ls.getTextDocumentService().completion(param) .thenAccept(completion -> proposals.addAll(toProposals(document, offset, completion, w)))); - this.completionLanguageServersFuture.get(); + this.completionLanguageServersFuture.get(GET_TIMEOUT, TimeUnit.MILLISECONDS); } catch (ResponseErrorException | ExecutionException e) { if (!CancellationUtil.isRequestCancelledException(e)) { // do not report error if the server has cancelled the request LanguageServerPlugin.logError(e); @@ -123,6 +124,8 @@ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int this.errorMessage = createErrorMessage(offset, e); Thread.currentThread().interrupt(); return createErrorProposal(offset, e); + } catch (TimeoutException e) { + LanguageServerPlugin.logWarning("Could not get completions due to timeout after " + GET_TIMEOUT + " milliseconds", e); //$NON-NLS-1$ //$NON-NLS-2$ } final var completeProposals = new LSCompletionProposal[proposals.size()]; @@ -255,7 +258,7 @@ public IContextInformation[] computeContextInformation(ITextViewer viewer, int o Thread.currentThread().interrupt(); return new IContextInformation[] { /* TODO? show error in context information */ }; } catch (TimeoutException e) { - LanguageServerPlugin.logWarning("Could not compute context information due to timeout after " + CONTEXT_INFORMATION_TIMEOUT + " milliseconds", e); //$NON-NLS-1$//$NON-NLS-2$ + LanguageServerPlugin.logWarning("Could not compute context information due to timeout after " + CONTEXT_INFORMATION_TIMEOUT + " milliseconds", e); //$NON-NLS-1$//$NON-NLS-2$ return new IContextInformation[] { /* TODO? show error in context information */ }; } return contextInformations.toArray(new IContextInformation[0]);