mrcjkb / rustaceanvim

Supercharge your Rust experience in Neovim! A heavily modified fork of rust-tools.nvim
GNU General Public License v2.0
1.3k stars 47 forks source link

fix(lsp): renderDiagnostics and explainError skipping valid diagnostics #372

Closed LukeFranceschini closed 2 months ago

LukeFranceschini commented 2 months ago

There were a couple different issues with the search for the next valid diagnostic location, which I've separated out into their own commits.

I used stylua and luacheck directly instead of through nix (because I was too lazy to set it up :see_no_evil: ) but they seemed to be satisfied with what I had. If I've missed anything just let me know. Similarly, I had six tests fail when I ran luarocks --local test but the same six tests fail even without my changes so hopefully that's fine.

Thanks for all your work on this project by the way! I only recently started in rust and having the inline diagnostics show up as I work has been a huge time saver while I'm learning the ropes : )

To reproduce the issue, turn on the clippy::shadow_unrelated lint and try to cycle between the three lints in the following code:

    // A
    let bool = true;
    if bool == true { println!("hello"); } // bool_comparison lint

    // B
    let  blah = 6_i32; // <--- C (cursor on blah in this line)
    let bar = 3_i32;
    let blah = 5_i32; // shadow_unrelated lint // D
    let bar = 2_i32; // shadow_unrelated lint

Without these changes you should have inconsistent behaviour depending on where your cursor is (A/B/C/D) when you run RustLsp renderDiagnostic, sometimes going to the closest diagnostic after the current cursor position, and other times falling back to the first lint in the file (the bool_comparison one).

With the changes you should always go to the closest diagnostic after the current cursor position, only wrapping around to the top when you are at the last lint or further.

(Note that there are two spaces between let and blah on the C line. This is to demonstrate the hash collisions, but you might need to disable autoformatting if you have that turned on so rustfmt doesn't switch it back to a single space.)

github-actions[bot] commented 2 months ago

Review Checklist

Does this PR follow the Contribution Guidelines? Following is a partial checklist:

Proper conventional commit scoping:

If applicable: