Skip to content

Support textDocument/willSave and textDocument/willSaveWaitUntil, which the client capabilities already advertise #1743

Closed

Description

@lagergren

Feature request. Could a maintainer give it the enhancement label and the Feature type? I can't set them on this repository.

LSP4IJ advertises both save hooks in its client capabilities, textDocument.synchronization.willSave and willSaveWaitUntil, but sends neither. ClientCapabilitiesFactory creates new SynchronizationCapabilities(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE), whose parameters are willSave, willSaveWaitUntil and didSave, and only textDocument/didSave is implemented. A server that relies on them, for example to format the document or organize its imports before it is saved, gets nothing, and can't tell.

What LSP specifies

  • textDocument/willSave is a notification: "The document will save notification is sent from the client to the server before the document is actually saved." Its params carry the document and the reason: Manual, AfterDelay or FocusOut.
  • textDocument/willSaveWaitUntil is a request: "The document will save request is sent from the client to the server before the document is actually saved. The request can return an array of TextEdits which will be applied to the text document before it is saved. Please note that clients might drop results if computing the text edits took too long or if a server constantly fails on this request. This is done to keep the save fast and reliable."
  • A server asks for them with willSave and willSaveWaitUntil in its TextDocumentSyncOptions.

A possible implementation

  • willSave: send it from FileDocumentManagerListener.beforeDocumentSaving, for an opened document whose server asks for it, through the wrapper's notification queue, so that it precedes the didSave of that save. The open question is the reason: IntelliJ doesn't say whether a save is explicit, an autosave, or caused by leaving the window. It could send Manual for every save, or approximate the reason from what triggers the save.
  • willSaveWaitUntil: its edits have to be applied before the document is written. But beforeDocumentSaving runs in a write action on the UI thread, where waiting for the server would freeze the IDE. IntelliJ's Actions on Save (the actionOnSave extension point) run before the save. A bounded, cancellable wait there would follow LSP's allowance to drop slow results: the edits would be applied only if the document hasn't changed since the request, like other version-checked edits. VS Code limits the time its save participants may take, too.
  • Until then: LSP4IJ could stop advertising the hooks it doesn't send, so that a server knows to do without them. Our IntelliJ client, for Ecstasy, does this today: it sets willSave and willSaveWaitUntil to false in its client capabilities.

I'd be glad to help with a pull request once the approach is agreed.

Activity

  1. added this to the 0.21.1 milestone on Oct 20, 2026
  2. moved this to In Progress in Java Toolingon Oct 20, 2026
  3. added
    enhancement
    on Oct 20, 2026
  4. angelozerr commented on Oct 20, 2026

    @angelozerr
    Contributor

    Fixed with #1746

  5. moved this from In Progress to Done in Java Toolingon Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions