Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

🐛 Incorrect handling of incremental LSP changes #4094

Closed
1 task done
rchl opened this issue Dec 22, 2022 · 2 comments
Closed
1 task done

🐛 Incorrect handling of incremental LSP changes #4094

rchl opened this issue Dec 22, 2022 · 2 comments
Labels
A-LSP Area: language server protocol S-Bug: confirmed Status: report has been confirmed as a valid bug

Comments

@rchl
Copy link

rchl commented Dec 22, 2022

Environment information

CLI:
  Version:              11.0.0
  Color support:        true

Platform:
  CPU Architecture:     aarch64
  OS:                   macos

What happened?

It appears there is a bug with handling of the textDocument/didChange LSP request.

(Note that this reproduces in Sublime Text when using sublimelsp/LSP-rome#1 but I don't expect you to set it up to test.)

With a document like:

/*
 * comment
 */

import * as path from 'node:path';
  1. Place cursor on the first line and press cmd + /
  2. ST removes both the initial /* and trailing */ characters which results in:
 * comment
 

import * as path from 'node:path';
  1. LSP server receives a textDocument/didChange notification:
{
  "contentChanges": [
    {
      "range": {
        "end": {
          "character": 2,
          "line": 0
        },
        "start": {
          "character": 0,
          "line": 0
        }
      },
      "rangeLength": 2,
      "text": ""
    },
    {
      "range": {
        "end": {
          "character": 3,
          "line": 2
        },
        "start": {
          "character": 1,
          "line": 2
        }
      },
      "rangeLength": 2,
      "text": ""
    }
  ],
  "textDocument": {
    "uri": "file:///usr/local/workspace/github/typescript-language-server/src/test.ts",
    "version": 6
  }
}

at which point its internal state gets confused as evident by the diagnostic which says

expected a statement but instead found '* comment */'

Note how the server still sees the trailing */ which was removed.

As far as I can see this bug triggers because of the order of changes in the contentChanges list. When the order is from top to bottom of the document then the bug triggers. Otherwise not.

I've tried reproducing it in VSCode by selecting both ranges and removing them with backspace but VSCode sends changes in opposite order so it doesn't reproduce there.

Expected result

Server should correctly process didChange notification regardless of the order of changes.

ST behavior is valid per spec. The server just has to ensure that the change it is currently applying is applied for the document state that includes previously applied change.

Code of Conduct

  • I agree to follow Rome's Code of Conduct
@rchl rchl added the S-To triage Status: user report of a possible bug that needs to be triaged label Dec 22, 2022
@github-actions
Copy link

github-actions bot commented Jan 6, 2023

👋 @rome/staff please triage this issue by adding one of the following labels: S-Bug: confirmed, S-Planned , S-Wishlist or umbrella

@leops leops added S-Bug: confirmed Status: report has been confirmed as a valid bug A-LSP Area: language server protocol and removed S-To triage Status: user report of a possible bug that needs to be triaged S-Stale labels Jan 9, 2023
@leops
Copy link
Contributor

leops commented Jan 9, 2023

This should have been fixed in #4135, I'll try to push a new nightly release that includes the fix

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-LSP Area: language server protocol S-Bug: confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants