rust-lang / rust-lang/rust-analyzer

Publish diagnostics sends partial or empty information causing markup blinking

Open
#8,876 0 comments 3 reactions 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

After a didSave request is issued, Rust Analyzer often sends multiple publishDiagnostics notifications in a row, with the first one containing no diagnostics, then maybe some with a few diagnostics and finally one with all the available diagnostics. The first notification with empty diagnostics causes editors such as VS Code to remove the markup and then add it again causing some blinking behaviour if you have autoSave enabled.

Here is an example in VS Code:

blinking markup

Looking at the server trace, it's possible to see the notifications with empty diagnostics. For example:

Trace - 11:46:11 AM] Sending notification 'textDocument/didSave'.
Params: {
    "textDocument": {
        "uri": "file:///Users/manuel.ceron/code/sandbox/rtest/src/main.rs"
    }
}


[Trace - 11:46:11 AM] Received request 'window/workDoneProgress/create - (25)'.
Params: {
    "token": "rustAnalyzer/cargo check"
}


[Trace - 11:46:11 AM] Sending response 'window/workDoneProgress/create - (25)'. Processing request took 0ms
No result returned.


[Trace - 11:46:11 AM] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/cargo check",
    "value": {
        "kind": "begin",
        "title": "cargo check"
    }
}


[Trace - 11:46:11 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///Users/manuel.ceron/code/sandbox/rtest/src/main.rs",
    "diagnostics": [],
    "version": 1
}


[Trace - 11:46:12 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///Users/manuel.ceron/code/sandbox/rtest/src/main.rs",
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 5,
                    "character": 3
                },
                "end": {
                    "line": 5,
                    "character": 6
                }
            },
            "severity": 2,
            "code": "dead_code",
            "source": "rustc",
            "message": "function is never used: `foo`\n`#[warn(dead_code)]` on by default",
            "tags": [
                1
            ]
        },
        {
            "range": {
                "start": {
                    "line": 8,
                    "character": 3
                },
                "end": {
                    "line": 8,
                    "character": 6
                }
            },
            "severity": 2,
            "code": "dead_code",
            "source": "rustc",
            "message": "function is never used: `bar`",
            "tags": [
                1
            ]
        }
    ],
    "version": 1
}

This was tested on rust-analyzer release from 2021-05-17

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

Reproduce the didSave sequence in VS Code and inspect how rust-analyzer emits textDocument/publishDiagnostics notifications. Compare the empty, partial, and final notifications in the server trace; done means editors no longer receive an unnecessary empty or incomplete update that causes markup to blink.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.