microsoft / microsoft/language-server-protocol

Stronger validation of incremental text sync consistency between the client and the server

Open
#1,706 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

document synchronization feature-request
Dominant language
TypeScript
Stars
13k
Forks
1k
Avg merge
6d 1h
Merged PRs (30d)
10

Description

Context

I maintain a markdown language server that is used by 6 different LSP clients. Sometimes I get bug reports like this (Neovim editor) or this (Helix editor) but getting a repro is very hard and debugging is very time consuming (especially, given that I don't personally use all 6 LSP clients on a daily basis).

Even when I can find a repro (like in this case with Emacs lsp-mode) this is just 1 client out of 6.

One thing that can simplify my life as a maintainer of an LSP sever is stronger validation.

The proposal

Update: Replace 'starting version' with 'content hash' below. The spirit of the proposal hasn't changed and is about enabling stronger validation for incremental text sync.


This is relevant for the incremental text sync. The protocol currently has the following in textDocument/didChange:

/**
 * The document that did change. The version number points
 * to the version after all provided content changes have
 * been applied.
 */
textDocument: VersionedTextDocumentIdentifier;

The version number there is "the version after all provided content changes have been applied".

I find this problematic because each LSP client (nvim lsp, emacs lsp-mode & eglot, sublime text, helix, etc.) has its own way of dealing with document versions:

  1. some increment by 1 on each change notifications,
  2. others increment by the number of content changes in the change notification,
  3. other just increment by a seemingly random number that is tied to their internal counters.

This means that if there's a bug in a client (or in the server), the state can subtly drift apart until the server receives a change that violates the state of the document that it has.

This prevents stronger validation on the server side, and makes triaging and debugging incremental text sync issues very painful.

Having both an starting and a final version in the document change notification would allow the server to check its current version with the notification's initial version and if there's a mismatch to abort early. Also, would simplify triaging: is it a client error? is it a race condition or some other bug in the server?

Perhaps I'm missing something in the spec that would allow me to do this type of stronger validation of the state?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the textDocument/didChange entry point and the VersionedTextDocumentIdentifier definition described in the issue. Review the incremental text-sync rules and the linked client examples to determine whether the protocol can expose stronger consistency validation. Done means reaching an agreed specification change or documenting why the current protocol already supports it.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.