Repository navigation
fix: save the documents a workspace edit changes that are not open in an editor - #1726
Merged
angelozerr merged 2 commits intoOct 19, 2026
Conversation
… an editor LSPIJUtils.applyWorkspaceEdit changed documents in memory only. For a document with no editor, no didOpen gave the server its content, so the server read the old text from disk until auto-save. This is redhat-developer#1225, fixed by redhat-developer#1235 and kept by 54bfc7a for workspace edits, and back since 0c90519 switched every workspace edit to not saving. That commit added the will* file operations, which apply their edits during a VFS event. applyWorkspaceEdit(edit, label) now saves, once the whole edit is applied, the documents it changed that have no editor and had no unsaved changes before it. A new internal overload takes saveDocumentsWithoutEditor; AbstractLSPFileListener passes false for the will* edits it applies in beforeVfsChange(). Validation: - New WorkspaceEditSaveTest on real files: a changes edit and a documentChanges edit to a file without an editor are saved (both fail on main: unsaved, old text on disk); an edit to a file in an editor and to a file with earlier unsaved changes stays unsaved (passes on main too); with saveDocumentsWithoutEditor false the file stays unsaved. - ./gradlew check: 585 tests, 0 failures, the 3 existing skips. Not included: saving after Undo and Redo of such an edit, and saving the will* edits applied during a VFS event.
Contributor
|
What about Undo and Redo ? |
Collaborator
Author
Sorry - They were in my original fix, but I managed to drop them when rebasing. I'll put them back and I need to write some unit tests for them. |
…f a workspace edit Review of redhat-developer#1726 asked about Undo and Redo. Undo of such an edit reverted the documents without an editor in memory only, and Redo applied it again in memory only, so the server again read a file that did not match them until auto-save. Inside a command, applyWorkspaceEdit now registers two undoable actions around the changes to documents without an editor. The first is registered before the first change to such a document and saves them on Undo, which reverts the changes after it first. The second is registered after the edit and saves them on Redo, which re-applies the changes before it. Both save only the documents saved on apply, and are global, since the documents have no editor to undo them from. An edit that changes only documents in editors registers neither. Validation: - New testUndoAndRedoSaveAFileWithoutAnEditor: after Undo the file has the old text and the document is saved; after Redo the new text. Without the actions it fails: global Undo does not reach the edit ("Following files affected by this action have been already changed", on main too). With the actions registered but not saving, it fails because the document stays unsaved after Undo. - ./gradlew check: 586 tests, 0 failures, the 3 existing skips.
Collaborator
Author
|
Added in e195517: the documents without an editor are now saved again after Undo and Redo of the edit.
New |
angelozerr
reviewed
Oct 19, 2026
angelozerr
pushed a commit
that referenced
this pull request
Oct 19, 2026
…dits change #1726 made applyWorkspaceEdit save the documents without an editor that a workspace edit changes, except for the edits of willRenameFiles, willCreateFiles and willDeleteFiles: AbstractLSPFileListener applies those in beforeVfsChange(), during the VFS event, where a document cannot be saved. They stayed unsaved until auto-save, so after a rename whose server edits other files, the server kept reading the old text of every closed file it edited. The internal applyWorkspaceEdit(edit, label, saveDocumentsWithoutEditor) now returns the documents without an editor it changed that had no unsaved changes before, also when it does not save them, and saveDocumentsWithoutEditor(documents) becomes internal API. AbstractLSPFileListener collects them in beforeVfsChange() and saves them in afterVfsChange() with invokeLater, after the write action the VFS event runs in. Validation: - New FileOperationEditSaveTest: renaming a connected file whose server answers willRenameFiles with an edit to another file without an editor saves that file with the new text. On main it fails ("the edited file without an editor must be saved"); with the fix it passes. - WorkspaceEditSaveTest: one lambda becomes a block, since the overload now returns a value. - ./gradlew check: 592 tests, 0 failures, the 3 existing skips. Not included: Undo and Redo of the rename do not save these documents; #1726's undoable actions are registered only where the edit itself is saved.
lagergren
added a commit
to xtclang/xvm
that referenced
this pull request
Nov 27, 2026
…changes, which LSP4IJ 0.30.1 does (UP21) ClosedRefactoringDocuments saved the closed documents that XtcRenameEdit's edit changed, after the edit and after its Undo and Redo, because LSP4IJ 0.21.0 left them unsaved and the server, which reads closed files from disk, proved and compiled stale text (UP21). LSP4IJ 0.30.1 saves them itself (redhat-developer/lsp4ij#1726, #1731), and on 2026-11-23 the save stayed only for a rename that also moves its directory, X116 having then failed 4 of 10 runs without it. It doesn't now: with the save turned off, X109-X116 passed 10 runs of 10 and X116, X161-X163 and X169 (the closed consumers' disk text after a rename, its Undo and its Redo) 3 of 3, on errs f3c5684 with LSP4IJ 0.30.1 (throwaway runs, 2026-11-27). What it kept is its guard, now UnsavedClosedTargets: a rename that reaches a closed document with unsaved changes, or a target IntelliJ cannot resolve, is refused, since the server proved it against the files on disk. Validated: :lang:intellij-plugin:test, 249 tests, 0 failures, 0 skipped; integrationTestClasses without warnings; :lang:spotlessCheck and :lang:detekt clean. In the container, on this commit: X109-X116, X161-X163 and X169, with START 13 of 13 passed (run-9127043804915393586). Limits: the 10 and 3 runs bound the failure rate the bridge once guarded against, not prove it zero; a run that loses a closed consumer's edit again shows in X116 or X169.
lagergren
added a commit
to xtclang/xvm
that referenced
this pull request
Nov 27, 2026
…changes, which LSP4IJ 0.30.1 does (UP21) ClosedRefactoringDocuments saved the closed documents that XtcRenameEdit's edit changed, after the edit and after its Undo and Redo, because LSP4IJ 0.21.0 left them unsaved and the server, which reads closed files from disk, proved and compiled stale text (UP21). LSP4IJ 0.30.1 saves them itself (redhat-developer/lsp4ij#1726, #1731), and on 2026-11-23 the save stayed only for a rename that also moves its directory, X116 having then failed 4 of 10 runs without it. It doesn't now: with the save turned off, X109-X116 passed 10 runs of 10 and X116, X161-X163 and X169 (the closed consumers' disk text after a rename, its Undo and its Redo) 3 of 3, on errs f3c5684 with LSP4IJ 0.30.1 (throwaway runs, 2026-11-27). What it kept is its guard, now UnsavedClosedTargets: a rename that reaches a closed document with unsaved changes, or a target IntelliJ cannot resolve, is refused, since the server proved it against the files on disk. Validated: :lang:intellij-plugin:test, 249 tests, 0 failures, 0 skipped; integrationTestClasses without warnings; :lang:spotlessCheck and :lang:detekt clean. In the container, on this commit: X109-X116, X161-X163 and X169, with START 13 of 13 passed (run-9127043804915393586). Limits: the 10 and 3 runs bound the failure rate the bridge once guarded against, not prove it zero; a run that loses a closed consumer's edit again shows in X116 or X169.
lagergren
added a commit
to xtclang/xvm
that referenced
this pull request
Nov 27, 2026
…changes, which LSP4IJ 0.30.1 does (UP21) ClosedRefactoringDocuments saved the closed documents that XtcRenameEdit's edit changed, after the edit and after its Undo and Redo, because LSP4IJ 0.21.0 left them unsaved and the server, which reads closed files from disk, proved and compiled stale text (UP21). LSP4IJ 0.30.1 saves them itself (redhat-developer/lsp4ij#1726, #1731), and on 2026-11-23 the save stayed only for a rename that also moves its directory, X116 having then failed 4 of 10 runs without it. It doesn't now: with the save turned off, X109-X116 passed 10 runs of 10 and X116, X161-X163 and X169 (the closed consumers' disk text after a rename, its Undo and its Redo) 3 of 3, on errs f3c5684 with LSP4IJ 0.30.1 (throwaway runs, 2026-11-27). What it kept is its guard, now UnsavedClosedTargets: a rename that reaches a closed document with unsaved changes, or a target IntelliJ cannot resolve, is refused, since the server proved it against the files on disk. Validated: :lang:intellij-plugin:test, 249 tests, 0 failures, 0 skipped; integrationTestClasses without warnings; :lang:spotlessCheck and :lang:detekt clean. In the container, on this commit: X109-X116, X161-X163 and X169, with START 13 of 13 passed (run-9127043804915393586). Limits: the 10 and 3 runs bound the failure rate the bridge once guarded against, not prove it zero; a run that loses a closed consumer's edit again shows in X116 or X169.
lagergren
added a commit
to xtclang/xvm
that referenced
this pull request
Nov 27, 2026
…changes, which LSP4IJ 0.30.1 does (UP21) ClosedRefactoringDocuments saved the closed documents that XtcRenameEdit's edit changed, after the edit and after its Undo and Redo, because LSP4IJ 0.21.0 left them unsaved and the server, which reads closed files from disk, proved and compiled stale text (UP21). LSP4IJ 0.30.1 saves them itself (redhat-developer/lsp4ij#1726, #1731), and on 2026-11-23 the save stayed only for a rename that also moves its directory, X116 having then failed 4 of 10 runs without it. It doesn't now: with the save turned off, X109-X116 passed 10 runs of 10 and X116, X161-X163 and X169 (the closed consumers' disk text after a rename, its Undo and its Redo) 3 of 3, on errs f3c5684 with LSP4IJ 0.30.1 (throwaway runs, 2026-11-27). What it kept is its guard, now UnsavedClosedTargets: a rename that reaches a closed document with unsaved changes, or a target IntelliJ cannot resolve, is refused, since the server proved it against the files on disk. Validated: :lang:intellij-plugin:test, 249 tests, 0 failures, 0 skipped; integrationTestClasses without warnings; :lang:spotlessCheck and :lang:detekt clean. In the container, on this commit: X109-X116, X161-X163 and X169, with START 13 of 13 passed (run-9127043804915393586). Limits: the 10 and 3 runs bound the failure rate the bridge once guarded against, not prove it zero; a run that loses a closed consumer's edit again shows in X116 or X169.
lagergren
added a commit
to xtclang/xvm
that referenced
this pull request
Nov 28, 2026
…changes, which LSP4IJ 0.30.1 does (UP21) ClosedRefactoringDocuments saved the closed documents that XtcRenameEdit's edit changed, after the edit and after its Undo and Redo, because LSP4IJ 0.21.0 left them unsaved and the server, which reads closed files from disk, proved and compiled stale text (UP21). LSP4IJ 0.30.1 saves them itself (redhat-developer/lsp4ij#1726, #1731), and on 2026-11-23 the save stayed only for a rename that also moves its directory, X116 having then failed 4 of 10 runs without it. It doesn't now: with the save turned off, X109-X116 passed 10 runs of 10 and X116, X161-X163 and X169 (the closed consumers' disk text after a rename, its Undo and its Redo) 3 of 3, on errs f3c5684 with LSP4IJ 0.30.1 (throwaway runs, 2026-11-27). What it kept is its guard, now UnsavedClosedTargets: a rename that reaches a closed document with unsaved changes, or a target IntelliJ cannot resolve, is refused, since the server proved it against the files on disk. Validated: :lang:intellij-plugin:test, 249 tests, 0 failures, 0 skipped; integrationTestClasses without warnings; :lang:spotlessCheck and :lang:detekt clean. In the container, on this commit: X109-X116, X161-X163 and X169, with START 13 of 13 passed (run-9127043804915393586). Limits: the 10 and 3 runs bound the failure rate the bridge once guarded against, not prove it zero; a run that loses a closed consumer's edit again shows in X116 or X169.
lagergren
added a commit
to xtclang/xvm
that referenced
this pull request
Nov 28, 2026
…changes, which LSP4IJ 0.30.1 does (UP21) ClosedRefactoringDocuments saved the closed documents that XtcRenameEdit's edit changed, after the edit and after its Undo and Redo, because LSP4IJ 0.21.0 left them unsaved and the server, which reads closed files from disk, proved and compiled stale text (UP21). LSP4IJ 0.30.1 saves them itself (redhat-developer/lsp4ij#1726, #1731), and on 2026-11-23 the save stayed only for a rename that also moves its directory, X116 having then failed 4 of 10 runs without it. It doesn't now: with the save turned off, X109-X116 passed 10 runs of 10 and X116, X161-X163 and X169 (the closed consumers' disk text after a rename, its Undo and its Redo) 3 of 3, on errs f3c5684 with LSP4IJ 0.30.1 (throwaway runs, 2026-11-27). What it kept is its guard, now UnsavedClosedTargets: a rename that reaches a closed document with unsaved changes, or a target IntelliJ cannot resolve, is refused, since the server proved it against the files on disk. Validated: :lang:intellij-plugin:test, 249 tests, 0 failures, 0 skipped; integrationTestClasses without warnings; :lang:spotlessCheck and :lang:detekt clean. In the container, on this commit: X109-X116, X161-X163 and X169, with START 13 of 13 passed (run-9127043804915393586). Limits: the 10 and 3 runs bound the failure rate the bridge once guarded against, not prove it zero; a run that loses a closed consumer's edit again shows in X116 or X169.
lagergren
added a commit
to xtclang/xvm
that referenced
this pull request
Nov 29, 2026
…changes, which LSP4IJ 0.30.1 does (UP21) ClosedRefactoringDocuments saved the closed documents that XtcRenameEdit's edit changed, after the edit and after its Undo and Redo, because LSP4IJ 0.21.0 left them unsaved and the server, which reads closed files from disk, proved and compiled stale text (UP21). LSP4IJ 0.30.1 saves them itself (redhat-developer/lsp4ij#1726, #1731), and on 2026-11-23 the save stayed only for a rename that also moves its directory, X116 having then failed 4 of 10 runs without it. It doesn't now: with the save turned off, X109-X116 passed 10 runs of 10 and X116, X161-X163 and X169 (the closed consumers' disk text after a rename, its Undo and its Redo) 3 of 3, on errs f3c5684 with LSP4IJ 0.30.1 (throwaway runs, 2026-11-27). What it kept is its guard, now UnsavedClosedTargets: a rename that reaches a closed document with unsaved changes, or a target IntelliJ cannot resolve, is refused, since the server proved it against the files on disk. Validated: :lang:intellij-plugin:test, 249 tests, 0 failures, 0 skipped; integrationTestClasses without warnings; :lang:spotlessCheck and :lang:detekt clean. In the container, on this commit: X109-X116, X161-X163 and X169, with START 13 of 13 passed (run-9127043804915393586). Limits: the 10 and 3 runs bound the failure rate the bridge once guarded against, not prove it zero; a run that loses a closed consumer's edit again shows in X116 or X169.
lagergren
added a commit
to xtclang/xvm
that referenced
this pull request
Nov 29, 2026
…changes, which LSP4IJ 0.30.1 does (UP21) ClosedRefactoringDocuments saved the closed documents that XtcRenameEdit's edit changed, after the edit and after its Undo and Redo, because LSP4IJ 0.21.0 left them unsaved and the server, which reads closed files from disk, proved and compiled stale text (UP21). LSP4IJ 0.30.1 saves them itself (redhat-developer/lsp4ij#1726, #1731), and on 2026-11-23 the save stayed only for a rename that also moves its directory, X116 having then failed 4 of 10 runs without it. It doesn't now: with the save turned off, X109-X116 passed 10 runs of 10 and X116, X161-X163 and X169 (the closed consumers' disk text after a rename, its Undo and its Redo) 3 of 3, on errs f3c5684 with LSP4IJ 0.30.1 (throwaway runs, 2026-11-27). What it kept is its guard, now UnsavedClosedTargets: a rename that reaches a closed document with unsaved changes, or a target IntelliJ cannot resolve, is refused, since the server proved it against the files on disk. Validated: :lang:intellij-plugin:test, 249 tests, 0 failures, 0 skipped; integrationTestClasses without warnings; :lang:spotlessCheck and :lang:detekt clean. In the container, on this commit: X109-X116, X161-X163 and X169, with START 13 of 13 passed (run-9127043804915393586). Limits: the 10 and 3 runs bound the failure rate the bridge once guarded against, not prove it zero; a run that loses a closed consumer's edit again shows in X116 or X169.
lagergren
added a commit
to xtclang/xvm
that referenced
this pull request
Nov 30, 2026
…changes, which LSP4IJ 0.30.1 does (UP21) ClosedRefactoringDocuments saved the closed documents that XtcRenameEdit's edit changed, after the edit and after its Undo and Redo, because LSP4IJ 0.21.0 left them unsaved and the server, which reads closed files from disk, proved and compiled stale text (UP21). LSP4IJ 0.30.1 saves them itself (redhat-developer/lsp4ij#1726, #1731), and on 2026-11-23 the save stayed only for a rename that also moves its directory, X116 having then failed 4 of 10 runs without it. It doesn't now: with the save turned off, X109-X116 passed 10 runs of 10 and X116, X161-X163 and X169 (the closed consumers' disk text after a rename, its Undo and its Redo) 3 of 3, on errs f3c5684 with LSP4IJ 0.30.1 (throwaway runs, 2026-11-27). What it kept is its guard, now UnsavedClosedTargets: a rename that reaches a closed document with unsaved changes, or a target IntelliJ cannot resolve, is refused, since the server proved it against the files on disk. Validated: :lang:intellij-plugin:test, 249 tests, 0 failures, 0 skipped; integrationTestClasses without warnings; :lang:spotlessCheck and :lang:detekt clean. In the container, on this commit: X109-X116, X161-X163 and X169, with START 13 of 13 passed (run-9127043804915393586). Limits: the 10 and 3 runs bound the failure rate the bridge once guarded against, not prove it zero; a run that loses a closed consumer's edit again shows in X116 or X169.
lagergren
added a commit
to xtclang/xvm
that referenced
this pull request
Nov 30, 2026
…changes, which LSP4IJ 0.30.1 does (UP21) ClosedRefactoringDocuments saved the closed documents that XtcRenameEdit's edit changed, after the edit and after its Undo and Redo, because LSP4IJ 0.21.0 left them unsaved and the server, which reads closed files from disk, proved and compiled stale text (UP21). LSP4IJ 0.30.1 saves them itself (redhat-developer/lsp4ij#1726, #1731), and on 2026-11-23 the save stayed only for a rename that also moves its directory, X116 having then failed 4 of 10 runs without it. It doesn't now: with the save turned off, X109-X116 passed 10 runs of 10 and X116, X161-X163 and X169 (the closed consumers' disk text after a rename, its Undo and its Redo) 3 of 3, on errs f3c5684 with LSP4IJ 0.30.1 (throwaway runs, 2026-11-27). What it kept is its guard, now UnsavedClosedTargets: a rename that reaches a closed document with unsaved changes, or a target IntelliJ cannot resolve, is refused, since the server proved it against the files on disk. Validated: :lang:intellij-plugin:test, 249 tests, 0 failures, 0 skipped; integrationTestClasses without warnings; :lang:spotlessCheck and :lang:detekt clean. In the container, on this commit: X109-X116, X161-X163 and X169, with START 13 of 13 passed (run-9127043804915393586). Limits: the 10 and 3 runs bound the failure rate the bridge once guarded against, not prove it zero; a run that loses a closed consumer's edit again shows in X116 or X169.
lagergren
added a commit
to xtclang/xvm
that referenced
this pull request
Dec 1, 2026
…changes, which LSP4IJ 0.30.1 does (UP21) ClosedRefactoringDocuments saved the closed documents that XtcRenameEdit's edit changed, after the edit and after its Undo and Redo, because LSP4IJ 0.21.0 left them unsaved and the server, which reads closed files from disk, proved and compiled stale text (UP21). LSP4IJ 0.30.1 saves them itself (redhat-developer/lsp4ij#1726, #1731), and on 2026-11-23 the save stayed only for a rename that also moves its directory, X116 having then failed 4 of 10 runs without it. It doesn't now: with the save turned off, X109-X116 passed 10 runs of 10 and X116, X161-X163 and X169 (the closed consumers' disk text after a rename, its Undo and its Redo) 3 of 3, on errs f3c5684 with LSP4IJ 0.30.1 (throwaway runs, 2026-11-27). What it kept is its guard, now UnsavedClosedTargets: a rename that reaches a closed document with unsaved changes, or a target IntelliJ cannot resolve, is refused, since the server proved it against the files on disk. Validated: :lang:intellij-plugin:test, 249 tests, 0 failures, 0 skipped; integrationTestClasses without warnings; :lang:spotlessCheck and :lang:detekt clean. In the container, on this commit: X109-X116, X161-X163 and X169, with START 13 of 13 passed (run-9127043804915393586). Limits: the 10 and 3 runs bound the failure rate the bridge once guarded against, not prove it zero; a run that loses a closed consumer's edit again shows in X116 or X169.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Documents that a workspace edit changes but that are not open in an editor are saved again once the edit is applied, so a language server, which reads them from disk, sees the change. This restores the fix of #1225 for renames, code actions, commands and
workspace/applyEdit.Problem
LSPIJUtils.applyWorkspaceEditchanges each document in memory and does not save it. For a document open in an editor,didChangegives the server the new text. For a document with no editor, nothing does. NodidOpenwas sent for it, so the server reads the file from disk, which keeps the old text until IntelliJ's auto-save writes it. After a rename across files, Find Usages and diagnostics then describe the old code of every closed file. #1225 reported exactly this: after a rename, Find Usages missed the closed files for about 60 seconds.How it came back:
applyEdits: on (true) for workspace edits, off for completion.willRenameFilesand the other file operations, switched workspace edits tofalse. Those operations apply their edits inAbstractLSPFileListener.beforeVfsChange(), during a VFS event, where saving a document would write to the VFS while it is being changed. I assume that is why saving was switched off, but the commit does not say. The switch applies to every workspace edit, not only to those. @angelozerr, was that the reason, or did saving cause another problem I should account for?Why this is a fix
For a document the client has not opened, the server's copy is the file. didClose: "The document’s master now exists where the document’s Uri points to (e.g. if the document’s Uri is a file Uri the master now exists on disk)." didOpen is what hands the content to the client: "The document’s content is now managed by the client and the server must not try to read the document’s content using the document’s Uri."
So an edit that changes only the in-memory copy of a document that is not open leaves the client and the server with different text. Saving it makes the file the server reads match.
Change
applyWorkspaceEdit(edit, label)saves the documents it changed that have no editor and had no unsaved changes before the edit.didChangeand stays unsaved, as before.saveDocumentsWithoutEditor.AbstractLSPFileListenerpassesfalse, so thewill*edits applied during a VFS event stay unsaved, as now.Validation
New
WorkspaceEditSaveTest, on real files:mainchangesedit to a file without an editor is saveddocumentChangesedit to a file without an editor is savedsaveDocumentsWithoutEditorfalse, the file stays unsaved./gradlew check: 586 tests, 0 failures, the 3 existing skips.Not included
will*edits applied during a VFS event are still not saved.