fannheyward / coc-rust-analyzer

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

second line of file is replaced with the name of the crate upon `:w` #1176

Closed petrovito closed 2 months ago

petrovito commented 1 year ago

What's the output of :CocInfo

## versions

vim version: NVIM v0.8.3
node version: v18.15.0
coc.nvim version: 0.0.82-b7375d5f 2023-01-30 05:09:03 +0800
coc.nvim directory: ~~~~~~
term: xterm-256color
platform: linux

## Log of coc.nvim

2023-09-06T19:40:49.727 INFO (pid:11955) [plugin] - coc.nvim initialized with node: v18.15.0 after 129
2023-09-06T19:40:49.727 INFO (pid:11955) [services] - LanguageClient Rust Analyzer Language Server state change: stopped => starting
2023-09-06T19:40:49.734 INFO (pid:11955) [language-client-index] - Language server "rust-analyzer" started with 11980
2023-09-06T19:40:49.743 INFO (pid:11955) [services] - LanguageClient Rust Analyzer Language Server state change: starting => running
2023-09-06T19:40:49.772 INFO (pid:11955) [services] - service rust-analyzer started
2023-09-06T19:40:49.955 INFO (pid:11955) [attach] - receive notification: highlight []
2023-09-06T19:40:52.284 INFO (pid:11955) [attach] - receive notification: highlight []
2023-09-06T19:40:53.598 INFO (pid:11955) [attach] - receive notification: highlight []
2023-09-06T19:40:54.589 INFO (pid:11955) [attach] - receive notification: highlight []
2023-09-06T19:40:56.181 INFO (pid:11955) [attach] - receive notification: highlight []
2023-09-06T19:40:56.743 INFO (pid:11955) [attach] - receive notification: highlight []
2023-09-06T19:40:57.153 INFO (pid:11955) [attach] - receive notification: highlight []
2023-09-06T19:40:58.285 INFO (pid:11955) [attach] - receive notification: highlight []
2023-09-06T19:40:58.987 INFO (pid:11955) [attach] - receive notification: highlight []
2023-09-06T19:41:01.724 INFO (pid:11955) [attach] - receive notification: showInfo []

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

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

I have a weird and annoying problem: every time I save a .rs file using :w or :wa the second line of file will be replaced with the name of the library:

Before

use backgammon::{Game, rules::{Roll, Move}};
fn main() {
    let mut game = Game::new();
}

After :w

use backgammon::{Game, rules::{Roll, Move}};
backgammon-bot
    let mut game = Game::new();
}

with backgammon-bot being the name of the crate

Any ideas?

I have never seen this before with any other language, also when I :CocUninstall coc-rust-analyzer this problem disappears, but comes back again upon reinstalling .

fannheyward commented 1 year ago

@petrovito can you make a test, set "codeLens.position": "eol" in your coc-settings.json and try again.

petrovito commented 1 year ago

that didn't help. but I have played a bit more with it now, and it seems like this behavior only happens if the code in the buffer is syntactically correct: if there are compile errors then everything is good (besides the compile errors of course :D).

a bit more info:

fannheyward commented 1 year ago

only get code analysis after I save the file

Yes, rust-analyzer only analyze on-saving.

Debugging on this.

fannheyward commented 1 year ago

I can't reproduce this, upgrade your nvim and try again.