Closed eero-lehtinen closed 5 months ago
Hey :wave:
Thanks for the detailed report :pray: Do you know if the behaviour is different when using rust-analyzer with VSCode?
I'm not sure if there's a good solution to this for rustaceanvim, as you would want to be able to navigate through the dependency with textDocument/definition
, etc.
I'd have to check if not attaching an LSP client if a file is in ~/.cargo/git/checkouts
(or whatever the path is on macos/windows) would cause problems.
I tested on VSCode and it works like I want in this situation.
I think just ignoring workspaces in this path would be fine (if that is possible).
I guess root_dir
passed into vim.lsp.start
is the culprit for adding new workspaces, while I think in VSCode you always manually create your workspaces.
Looks like you already have an explicit check for the normal dependency registry, so adding the same for git checkouts seems to just work.
diff --git a/lua/rustaceanvim/cargo.lua b/lua/rustaceanvim/cargo.lua
index 9678aa5..f506ba1 100644
--- a/lua/rustaceanvim/cargo.lua
+++ b/lua/rustaceanvim/cargo.lua
@@ -13,11 +13,13 @@ local function get_mb_active_client_root(file_name)
local cargo_home = compat.uv.os_getenv('CARGO_HOME') or joinpath(vim.env.HOME, '.cargo')
local registry = joinpath(cargo_home, 'registry', 'src')
+ local checkouts = joinpath(cargo_home, 'git', 'checkouts')
+
---@diagnostic disable-next-line: missing-parameter
local rustup_home = compat.uv.os_getenv('RUSTUP_HOME') or joinpath(vim.env.HOME, '.rustup')
local toolchains = joinpath(rustup_home, 'toolchains')
- for _, item in ipairs { toolchains, registry } do
+ for _, item in ipairs { toolchains, registry, checkouts } do
item = os.normalize_path_on_windows(item)
if file_name:sub(1, #item) == item then
local clients = rust_analyzer.get_active_rustaceanvim_clients()
Have you read the docs and searched existing issues?
Neovim version (nvim -v)
v0.9.5
Operating system/version
EndeavourOS
Output of :checkhealth rustaceanvim
How to reproduce the issue
Make Cargo.toml in a project:
Make src/main.rs
Use go to definition on both
jittr
andjittr_git
.jittr
works as it should, butjittr_git
's folder gets added to workspaces erroneously.Expected behaviour
Neither of these crates are added to workspaces.
Actual behaviour
:lua =vim.lsp.buf.list_workspace_folders()
shows that~/.cargo/git/checkouts/jittr-{something}
is added to lsp workspaces and then warnings from this dependency are shown as if we were editing it.The minimal config used to reproduce this issue.