1

LSP allows for synchronization (textDocument/didChange) to be incremental, as long as client and server support this.

Implementing support for this on the server's side, I am confused how the server is supposed to correctly order[^1] these incremental edits. The server gets DidChangeTextDocumentParams containing VersionedTextDocumentIdentifier with a version field, that is documented as follows (emphasis: mine):

[...] The version number of a document will increase after each change, including undo/redo. The number doesn't need to be consecutive.

If it can be non-consecutive, then how can the server find out if it has missed a change?

In this context, I have also wondered, if there is any way to request a full synchronization of a document from the client, when the server suspects it is out of sync? This would mitigate the issue, at least.

[^1]: most of the time they're received in the right order of course, and my implementation does work fine

Radek Simko
  • 15,886
  • 17
  • 69
  • 107
zaep
  • 73
  • 1
  • 4
  • The server has access to the document being modified, wouldn't be enough to access the file an do a read&update of the internal model when it suspects it is out of sync? – Alejandro González Jun 08 '22 at 12:06
  • @AlejandroGonzález That would not be enough, as most language servers deal with intermediate document state as well (before the document is explicitly saved). Now that I'm thinking about this I imagine it might be a good first step to wait for a write notification and then do what you propose, at which point the server _ought_ to be up to date again. – zaep Jul 27 '22 at 14:27

0 Answers0