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 ?