Repository navigation
An edit made while a file connects to a starting language server never reaches the server #2126
Description
What happens
LSP4IJ opens a file at a language server with the text the file had when the connection was asked for, but listens to the file's document only once the server has initialized. An edit made in between never reaches the server:
- the server keeps the text without the edit;
- with incremental sync, every later change applies to text the server doesn't have, so the server's copy of the file stays wrong until the file is opened again;
- with full sync, the next edit sends the whole text and repairs it.
The window is the start of the language server, so it is widest after a restart, or when the server's process died and the next request starts it again. We hit it in a test that edits a file right after killing the server's process: the new server opened the file without the edit, never got it, and so reported nothing about it.
Steps
- Open a file of a language server that syncs incrementally (
TextDocumentSyncKind.Incremental) and is slow to start. - Kill the server's process. The next request in the file, such as a hover, makes LSP4IJ start the server again.
- Type in the file while the server starts.
- Look at the
didOpenanddidChangein the LSP console.
Expected
The server gets the edit: the didOpen carries the current text, or a didChange with the edit follows it.
Cause
On main (40c958d):
LanguageServiceAccessor.getFileConnectionInfoMapcaptures the document's text and modification stamp withcreateFileConnectionInfo(LanguageServiceAccessor.java:204), and then connects.LanguageServerWrapper.connectDocumentwaits for the server'sinitialize(initialized.thenComposeAsync, LanguageServerWrapper.java:1235). Only then does it create theDocumentContentSynchronizerand add it as the document's listener (LanguageServerWrapper.java:1317-1322).DocumentContentSynchronizer.getDidOpenFutureSyncsends the captured text (DocumentContentSynchronizer.java:164). No listener heard the edits made between the capture and the connection, so none of them is queued.isCurrentTextAssigned(DocumentContentSynchronizer.java:639) already sees the mismatch: the document's stamp differs from the didOpen's. Since fix: validate document versions before applying workspace edits #1698 a versioned workspace edit for that version is refused, but nothing sends the text.
The text is captured early on purpose (#878, 915ca20): a didOpen that reads the document needs read access, and must not wait for a write action, as for the move of a file. The move of a document captures its text the same way (LSPFileListener.java:265). Its window is shorter, as its server already runs.
Suggested fix
In getDidOpenFutureSync, use the captured text only while the document still has the captured stamp. Otherwise read the current text, as when no text was captured. The didOpen then reads only when the document changed after the capture.
That leaves a much smaller window of the same kind: a change that is under way while the listener is added, before it has updated the stamp. On 2024.2 and 2025.3 the listener hears only its documentChanged, which queues no incremental change. On 2026.3, which takes the listeners once for both events, it hears neither.
Activity
Register UP83 as filed: redhat-developer/lsp4ij#2126, fixed by our #2127
fix: open a file at a starting language server with the edits made wh…
Send the language server a file's current text when its didOpen was o…
Send the language server a file's current text when its didOpen was o…
Send the language server a file's current text when its didOpen was o…
Register UP83 as filed: redhat-developer/lsp4ij#2126, fixed by our #2127
Send the language server a file's current text when its didOpen was o…
Send the language server a file's current text when its didOpen was o…
Register UP83 as filed: redhat-developer/lsp4ij#2126, fixed by our #2127
Send the language server a file's current text when its didOpen was o…
Send the language server a file's current text when its didOpen was o…
Register UP83 as filed: redhat-developer/lsp4ij#2126, fixed by our #2127
3 remaining items
Send the language server a file's current text when its didOpen was o…
Send the language server a file's current text when its didOpen was o…
Register UP83 as filed: redhat-developer/lsp4ij#2126, fixed by our #2127
Send the language server a file's current text when its didOpen was o…
Send the language server a file's current text when its didOpen was o…
Register UP83 as filed: redhat-developer/lsp4ij#2126, fixed by our #2127
Send the language server a file's current text when its didOpen was o…
Send the language server a file's current text when its didOpen was o…
Register UP83 as filed: redhat-developer/lsp4ij#2126, fixed by our #2127
Send the language server a file's current text when its didOpen was o…
Send the language server a file's current text when its didOpen was o…
Send the language server a file's current text when its didOpen was o…
Send the language server a file's current text when its didOpen was o…
Send the language server a file's current text when its didOpen was o…
Send the language server a file's current text when its didOpen was o…