fannheyward / coc-rust-analyzer

rust-analyzer extension for coc.nvim
MIT License
1.12k stars 39 forks source link

Warning diagnostics underline formatting is using hint underline formatting. #1227

Closed ZacharyRizer closed 2 months ago

ZacharyRizer commented 6 months ago

What's the output of :CocInfo

## versions

vim version: NVIM v0.10.0-dev-2382+g478273a42
node version: v20.6.1
coc.nvim version: 0.0.82-d1568d56 2023-09-29 19:43:34 +0800
coc.nvim directory: /Users/zrizer/.local/share/nvim/lazy/coc.nvim
term: xterm-kitty
platform: darwin

## Log of coc.nvim

2024-02-18T11:20:39.779 INFO (pid:63069) [extension:coc-git] - Looking for git in: git
2024-02-18T11:20:39.818 INFO (pid:63069) [plugin] - coc.nvim initialized with node: v20.6.1 after 262
2024-02-18T11:20:39.818 INFO (pid:63069) [services] - LanguageClient Rust Analyzer Language Server state change: stopped => starting
2024-02-18T11:20:39.822 INFO (pid:63069) [language-client-index] - Language server "rust-analyzer" started with 63080
2024-02-18T11:20:39.848 INFO (pid:63069) [services] - LanguageClient Rust Analyzer Language Server state change: starting => running
2024-02-18T11:20:39.863 INFO (pid:63069) [services] - service rust-analyzer started
2024-02-18T11:20:39.929 INFO (pid:63069) [core-watchman] - watchman watching project: /Users/zrizer/CodeProjects/rust/the_book/rust_programming_concepts

What's the output of :CocCommand rust-analyzer.serverVersion

 rust-analyzer 0.3.1839-standalone (c06ca6cff 2024-02-11)

What's your coc-rust-analyzer version? You can get it from :CocList extensions

0.75.1

The issue I'm having is that diagnostic warnings are using the hint diagnostics underline formatting. The warnings are correctly taking precedence over the hints, but the underline color and formatting is showing as if it was hint. Here is a screen shot:

image

You can see that the gutter and diagnostic list is correctly showing the warning diagnostics as having priority over the hints, but the underline is showing it as if it is a hint, and also the text is dull as if it is a hint. If in my coc.settings.json I set this: "diagnostic.level": "warning", then it will only list and show the warning, but the formatting is still off.

image image image

When I look at the DiagnosticUnderline highlight groups, they are correct, guisp is yellow for warning and green for hint. And if I switch to a different lsp, the warnings are shown as expected (text is not dull, undercurl is yellow). Lua as a reference:

image image

You can see that in the lua file the priority is correct in the gutter and in the lists, and the undercurl formatting is appropriate to the correct level.

And just for reference if I look at the same rust file in VsCode it is formatting as I would expect coc-rust-analyzer to do:

image
fannheyward commented 2 months ago

The diagnostic:

[
        {
            "range": {},
            "severity": 2,
            "code": "unused_variables",
            "source": "rustc",
            "message": "unused variable: `chunk1`\n`#[warn(unused_variables)]` on by default",
            "relatedInformation": [{}],
            "tags": [
                1
            ],
            "data": {
                "rendered": "warning: unused variable: `chunk1`\n --> src/main.rs:4:9\n  |\n4 |     let chunk1 = &s1[0..5];\n  |         ^^^^^^ help: if this is intentional, prefix it with an underscore: `_chunk1`\n  |\n  = note: `#[warn(unused_variables)]` on by default\n\n"
            }
        },
        {
            "range": {},
            "severity": 4,
            "code": "unused_variables",
            "source": "rustc",
            "message": "if this is intentional, prefix it with an underscore: `_chunk1`",
            "relatedInformation": [
                {
                    ...
                    "message": "original diagnostic"
                }
            ]
        }
    ]

The problem: there're two diagnostics on chunk1, the first one unused variable diagnostic contains Unnecessary tag, coc.nvim uses this instead the warning for the first diagnostic. We should use stack these.

https://github.com/neoclide/coc.nvim/blob/974b9c8dc54202c2cd23f09315b9eaff0116cae5/src/diagnostic/util.ts#L161-L179