rust-lang / rust-lang/rust-analyzer

Diagnostics after didChange contain incorrect ranges

Open
#8,836 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics S-actionable
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

Hello,

This issue might be related to the know issue that on-the-fly diagnostics are mostly unimplemented. If that's the case, I apologize for the noise. I wanted to bring it up anyway.

When making changes to a file without saving, the editor will only send textDocument/didChange notifications to the server. As a result of this, some times the server will then send a textDocument/publishDiagnostics. However, some times the diagnostics coming for this request contain incorrect ranges, which cases warning/error markup to be rendered in incorrect places by the editor.

Here is a GIF showing this behaviour on VS Code:

rust-analyzer-bug

What is happening here is that the textDocument/publishDiagnostics notification contains ranges for the latest saved version of the file, not the one reported by textDocument/didChange. The interesting bit is that the textDocument/publishDiagnostics notification does contain a version field which matches perfectly with the one sent by textDocument/didChange. It's just that the ranges are incorrect.

This was tested with the released version of rust-analyzer from 2021-05-10. Please let me know if you need more information for debugging.

Contributor guide

Open the contributing guide

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 by reproducing the issue in VS Code while inspecting textDocument/didChange and textDocument/publishDiagnostics notifications, especially their version and ranges. Done means diagnostics for an unsaved file use ranges from the matching changed version rather than the latest saved version.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, vscode
Domain
api, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.