Open Ralith opened 2 years ago
Is this for any specific language server?
I'm using rust-analyzer, though I'd assume the "try to run a binary" code isn't terribly specific to it.
Yeah, I started to have a poke around lsp-mode
to investigate. I think this is more of an lsp-mode
issue tbh, but I'd at least like to be able to point at the upstream code that should be fixed up.
Some other things might have changed since this issue was open, but I found that using (lsp-deferred)
to activate LSP instead of (lsp)
works well with envrc
. LSP can find the language server binary even if's loaded into $PATH
using Nix + direnv, i.e. use nix -p gopls
lsp-deferred
works fine for starting rust-analyzer
provided by direnv
, but there's another problem: when I navigate to source of library I use, the files are in ~/.cargo/registry/
, which is outside the project directory and its .envrc
, so lsp-mode
is not finding proper rust-analyzer
.
It looks like the problem is caused by envrc
working exactly as intended and it will be tricky to solve. Maybe I can convince cargo to download sources inside project? This will cause some duplication, but it will be covered by the .envrc
at least.
Edited to add: the following .envrc
line seems to be a good workaround to my problem for Rust/Cargo:
export CARGO_HOME="$(dirname "$(realpath "${BASH_SOURCE[0]}")")/target/.cargo"
The issue with envrc applying env after lsp-mode is indeed solved by lsp-deferred
for me too.
Configured with
envrc works for the first file I open in a workspace, but when I open another file in the same workspace, lsp-mode complains that the configured language-server command is not present on the path. Is there a way I can get this working?