Skip to content

fix: adds immediate document saving after applying text edits to trig… - #1235

Merged
angelozerr merged 2 commits into
redhat-developer:mainfrom
sergeysavchuk:1225_immediate_document_save_after_lsp_edits
Aug 28, 2025
Merged

angelozerr merged 2 commits into
redhat-developer:mainfrom
sergeysavchuk:1225_immediate_document_save_after_lsp_edits

Conversation

@sergeysavchuk

Copy link
Copy Markdown
Contributor

Ensures immediate VFS events when LSPIJUtils.applyEdits is used on unopened files

Added document saving after applying text edits to trigger VFS events right away.

Tested on Clojure LSP plugin:

Before fix:

before.mov

After fix:

after.mov

Fixes #1225

@angelozerr

Copy link
Copy Markdown
Contributor

@sergeysavchuk thanks for your fix. I don't understand your demo, it seems, before/after demo are the same?

@sergeysavchuk

Copy link
Copy Markdown
Contributor Author

@angelozerr Please pay attention to the references result after renaming. Before the fix, didChangeWatchedFiles was not sent, and references were found only in opened files.
image

@angelozerr

Copy link
Copy Markdown
Contributor

Let me try it.

Could you add please a comment which explains your line code

@sergeysavchuk

Copy link
Copy Markdown
Contributor Author

@angelozerr I've added a comment, please review, e.g. before to trigger it, you can exec File -> "Save all" (cmd+S)

@angelozerr

Copy link
Copy Markdown
Contributor

LGTM, thanks!

@angelozerr
angelozerr merged commit d625e08 into redhat-developer:main Aug 28, 2025
@angelozerr angelozerr added the bug Something isn't working label Aug 28, 2025
@angelozerr angelozerr added this to the 0.16.0 milestone Aug 28, 2025
angelozerr pushed a commit that referenced this pull request Oct 19, 2026
… 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 #1225, fixed by #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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

didChangeWatchedFiles is not sent immediately to LS after applying edits from rename response

2 participants