Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fannheyward opened this issue Dec 18, 2024 · 7 comments
Assignees
Labels
A-diagnostics diagnostics / error reporting A-lsp LSP conformance issues and missing features C-bug Category: bug

Comments

@fannheyward
Copy link
Contributor

fannheyward commented Dec 18, 2024

  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 fannheyward/coc-rust-analyzer#1276 (comment)

[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 (27e824f 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!");
}
@fannheyward fannheyward added the C-bug Category: bug label Dec 18, 2024
@Veykril Veykril added A-diagnostics diagnostics / error reporting A-lsp LSP conformance issues and missing features labels Dec 18, 2024
@Veykril
Copy link
Member

Veykril commented Dec 18, 2024

We use publishDiagnostics for the rustc/cargo errors, the pull model for our native ones. This works just fine in VSCode and the spec doesn't state anything regarding it. Though according to microsoft/language-server-protocol#1743 (comment) this setup is discouraged.

cc @rchl @jwortmann tagging you because of your comments in #18404 (I forgot about this sorry)

@Veykril Veykril self-assigned this Dec 18, 2024
@fannheyward
Copy link
Contributor Author

This problem is not that RA is us ing push and pull mode at same time, but: RA can publish diagnostics at pushing mode, but no diagnostics at pulling mode.

@fannheyward
Copy link
Contributor Author

This works just fine in VSCode

From the tracking logs in VSCode, publishDiagnostics has two diagnostics, but empty result in pull request.

@Veykril
Copy link
Member

Veykril commented Dec 18, 2024

We use the push mode for cargo diagnostics where as pull only pull rust-analyzer native ones. So as currently implemented in r-a there is no overlap between the two (pull diagnostics will never list cargo check ones, push diagnostics will never list rust-analyzer native ones). So clients (except for VSCode for some reason?) will naturally replace push results for a document with the pull results for the given document (as we don't even populate the result-id #18717 fixes that part so there is no distinguishing to be done either way).

I personally do think using both pull and push is valid, but the spec leaves that (+ how to handle such a case) completely unspecified.

@fannheyward
Copy link
Contributor Author

except for VSCode for some reason?

See my previous comment, VSCode also pulls empty result, just that it didn't replace/update the PROBLEMS list.

@Veykril
Copy link
Member

Veykril commented Dec 18, 2024

It is correct that the pull there is empty, because the pull only pulls rust-analyzer native diagnostics (the ones we compute), so they do not include the diagnostic computed by us via cargo check (triggered when you save a file). It is intentional by our implementation that pull and push diagnostics do not yield the same set of diagnostics for a document.

@fannheyward
Copy link
Contributor Author

I see, thank you for the clarification. Maybe I can make an improvement in the client side for the both modes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting A-lsp LSP conformance issues and missing features C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants