rust-lang / rust-lang/rust-analyzer

rust-analyzer didn't return warning/hint diagnostics on `textDocument/diagnostic`

Open
#18,709 11 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

  1. rust-analyzer publishDiagnostics after open rust file, containing the warning/hint level diagnostics
  2. switch windows in editor, then the client requests textDocument/diagnostic for the same file, rust-analyzer returns empty diagnostics

Server trace logs, same logs with VSCode+rust-analzyer too, more logs https://github.com/fannheyward/coc-rust-analyzer/issues/1276#issuecomment-2462451351

[Trace - 14:56:20] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///Users/fannheyward/src/hello-rust/src/main.rs",
    "diagnostics": [
        {
            "range": {...},
            "severity": 2,
            "code": "unused_imports",
            "source": "rustc",
            "message": "unused import: `std::env`\n`#[warn(unused_imports)]` on by default",
            "relatedInformation": [...],
            "tags": [1],
            "data": {...}
        },
        {
            "range": {...}
            },
            "severity": 4,
            "code": "unused_imports",
            "source": "rustc",
            "message": "remove the whole `use` item",
            "relatedInformation": [...]
        }
    ],
    "version": 1
}

...

[Trace - 14:57:31] Sending request 'textDocument/diagnostic - (18)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/fannheyward/src/hello-rust/src/main.rs"
    }
}


[Trace - 14:57:31] Received response 'textDocument/diagnostic - (18)' in 2ms.
Result: {
    "kind": "full",
    "items": []
}

rust-analyzer version: rust-analyzer 0.0.0 (27e824fad4 2024-12-15)

rustc version: rustc 1.83.0 (90b35a623 2024-11-26)

editor or extension: nvim + coc.nvim

code snippet to reproduce:

use std::env;

fn main() {
    println!("Hello, world!");
}

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 with the provided Rust snippet and compare the publishDiagnostics trace with the textDocument/diagnostic response. Trace the server's diagnostic handling for warning and hint levels; done means the pull request returns the same warning and hint diagnostics instead of an empty items array after the client requests diagnostics.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.