fannheyward / coc-rust-analyzer

rust-analyzer extension for coc.nvim
MIT License
1.13k stars 40 forks source link

How can I diagnose/trace `cargo check` invocations? #1142

Closed feuGeneA closed 1 year ago

feuGeneA commented 1 year ago

I'm experiencing the exact problem described in https://github.com/rust-lang/rust-analyzer/issues/3292 . I'd love some help debugging it.

From that issue:

My workspace is in a compilation battle between rust-analyzer and my git-hooks. Every time I run a git hook it recompiles the binary, I assume because of an options mismatch with rust-analyzer.

An example from my git hook is RUSTFLAGS="-D warnings" cargo check --tests --features="mock" || exit 1

Can I set the rust-analyzer defaults to be the same and avoid these needless recompilations ?

In my specific case, my git hook has:

set -e
export RUSTFLAGS=-Dwarnings
cargo check --workspace --all-features --all-targets

So I've set up my CocConfig with the following:

{
"rust-analyzer.cargo.features": "all",
"rust-analyzer.check.allTargets": true,
"rust-analyzer.check.extraEnv": {"RUSTFLAGS": "-D warnings", "CARGO_TARGET_DIR": "./target/rust-analyzer"},
"rust-analyzer.cargo.extraEnv": {"RUSTFLAGS": "-D warnings", "CARGO_TARGET_DIR": "./target/rust-analyzer"},
"rust-analyzer.server.extraEnv": {"RUSTFLAGS": "-D warnings", "CARGO_TARGET_DIR": "./target/rust-analyzer"},
"rust-analyzer.check.overrideCommand": ["cargo", "check", "--workspace", "--all-features", "--all-targets", "--message-format=json"],
"rust-analyzer.restartServerOnConfigChange": true,
"@ignored/coc-solidity.telemetry": true
}

A lot of the things in there are just me trying out various different things to fix the problem. I'm sure some of that stuff is not necessary.

While I would appreciate any info in solving this particular problem, my reason for raising the issue is this question:

How can I see a log or trace of what's happening when cargo check is run? For example the command line used, it's environment variables, and its output?

What's the output of :CocInfo


vim version: VIM - Vi IMproved 9.0 9000813
node version: v18.4.0
coc.nvim version: 0.0.82-7a50d4d9 2022-08-01 01:37:29 +0800
coc.nvim directory: /home/gene/.vim/pack/git-plugins/start/coc.nvim
term: dumb
platform: linux

## Log of coc.nvim

2023-05-16T20:11:33.289 INFO (pid:1373564) [services] - registered service "rust-analyzer"
2023-05-16T20:11:33.291 INFO (pid:1373564) [services] - Rust Analyzer Language Server state change: stopped => starting
2023-05-16T20:11:33.293 INFO (pid:1373564) [plugin] - coc.nvim initialized with node: v18.4.0 after 126ms
2023-05-16T20:11:33.310 INFO (pid:1373564) [language-client-index] - Language server "rust-analyzer" started with 1373594
...
2023-05-17T19:00:34.128 INFO (pid:1373564) [services] - Rust Analyzer Language Server state change: starting => running
2023-05-17T19:01:06.011 INFO (pid:1373564) [attach] - receive notification: showInfo []
2023-05-17T19:04:10.251 INFO (pid:1373564) [attach] - receive notification: checkJsonExtension []
2023-05-17T19:08:49.320 INFO (pid:1373564) [attach] - receive notification: showInfo []

What's the output of :CocCommand rust-analyzer.serverVersion [coc.nvim] rust-analyzer 0.3.1514-standalone

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

fannheyward commented 1 year ago

How can I see a log or trace of what's happening when cargo check is run

Maybe the trace logs, try "rust-analyzer.trace.server": "verbose", then :CocCommand workspace.showOutput rust-analyzer, but I don't know whether this logs contains command line/env variables or not.