Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cancel willSaveWaitUntil if the result will no longer be used #1170

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextEdit>> edits = languageServerWrapper.executeImpl(ls -> ls.getTextDocumentService().willSaveWaitUntil(params));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember whether the return value of "executeImpl" is actually cancellable.
The best way to check that is to enable the log, get into a case where cancellation happens, and then check is the $cancel request was send from LSP4E to the LS. Did you verify it that way?
IIRC there is also a test case somewhere about cancellation that intercept those cancellation request between client and LS to verify them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not though about that. Thanks for the hint. I will check.

try {
List<TextEdit> 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 ?
Expand Down
Loading