From 85e85f05b1b5a184b6529effb4d2a2100d20e1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Porras=20Campo?= Date: Mon, 6 Jan 2025 15:38:26 +0100 Subject: [PATCH] feat: cancel willSaveWaitUntil if the result will no longer be used --- .../eclipse/lsp4e/DocumentContentSynchronizer.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/DocumentContentSynchronizer.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/DocumentContentSynchronizer.java index fca1800bc..a3b7b4cd7 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/DocumentContentSynchronizer.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/DocumentContentSynchronizer.java @@ -259,18 +259,13 @@ public void documentAboutToBeSaved() { // Use @link{TextDocumentSaveReason.Manual} as the platform does not give enough information to be accurate final var params = new WillSaveTextDocumentParams(identifier, TextDocumentSaveReason.Manual); - + CompletableFuture<@Nullable List> edits = languageServerWrapper.executeImpl(ls -> ls.getTextDocumentService().willSaveWaitUntil(params)); try { - List edits = languageServerWrapper.executeImpl(ls -> ls.getTextDocumentService().willSaveWaitUntil(params)) - .get(lsToWillSaveWaitUntilTimeout(), TimeUnit.SECONDS); - try { - LSPEclipseUtils.applyEdits(document, edits); - } catch (BadLocationException e) { - LanguageServerPlugin.logError(e); - } - } catch (ExecutionException e) { + LSPEclipseUtils.applyEdits(document, edits.get(lsToWillSaveWaitUntilTimeout(), TimeUnit.SECONDS)); + } catch (ExecutionException | BadLocationException e) { LanguageServerPlugin.logError(e); } catch (TimeoutException e) { + edits.cancel(true); Integer timeoutCount = castNonNull(WILL_SAVE_WAIT_UNTIL_TIMEOUT_MAP.compute(identifier.getUri(), (k, v) -> v == null ? 1 : Integer.valueOf(v + 1))); String message = timeoutCount > WILL_SAVE_WAIT_UNTIL_COUNT_THRESHOLD ?