Repository navigation
Closed
Description
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/willSaveis 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,AfterDelayorFocusOut.textDocument/willSaveWaitUntilis 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
willSaveandwillSaveWaitUntilin itsTextDocumentSyncOptions.
A possible implementation
willSave: send it fromFileDocumentManagerListener.beforeDocumentSaving, for an opened document whose server asks for it, through the wrapper's notification queue, so that it precedes thedidSaveof 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 sendManualfor every save, or approximate the reason from what triggers the save.willSaveWaitUntil: its edits have to be applied before the document is written. ButbeforeDocumentSavingruns in a write action on the UI thread, where waiting for the server would freeze the IDE. IntelliJ's Actions on Save (theactionOnSaveextension 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
willSaveandwillSaveWaitUntilto false in its client capabilities.
I'd be glad to help with a pull request once the approach is agreed.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Type
Projects
- StatusShow more project fieldsDone
Activity
feat: send textDocument/willSave and textDocument/willSaveWaitUntil, …
feat: send textDocument/willSave and textDocument/willSaveWaitUntil, …
feat: send textDocument/willSave and textDocument/willSaveWaitUntil, …
angelozerr commentedon Oct 20, 2026
Fixed with #1746