-
Checked other resources
DescriptionI want to be able to open multiple nvim instances with same project, using the same connection to rust-analyzer. Right now, multiple RA servers are instantiated when opening multiple nvim instances. Example Codevim.env.LAZY_STDPATH = '.repro'
---@diagnostic disable-next-line: param-type-mismatch
load(vim.fn.system('curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua'))()
require('lazy.minit').repro {
spec = {
{
'mrcjkb/rustaceanvim',
version = '^6',
init = function()
-- Configure rustaceanvim here
vim.g.rustaceanvim = {}
end,
lazy = false,
},
},
}Neovim version (nvim -v)NVIM v0.11.4 Operating system/versionArch Linux Output of :checkhealth rustaceanvimWith `minimal.lua`:- LSP log level : WARN
- Log path: /home/playbahn/master/simd-basics/.repro/state/nvim/lsp.log
- Log size: 0 KB
vim.lsp: Active Clients
- rust-analyzer (id: 1)
- Version: 1.92.0-nightly (1d23d06 2025-10-22)
- Root directory: ~/master/simd-basics
- Command: { "/usr/lib/rustup/bin/rust-analyzer", "--log-file", "/tmp/nvim.playbahn/ebLd8E/0-rust-analyzer.log" }
- Settings: {
["rust-analyzer"] = {
check = {
command = "clippy",
extraArgs = { "--no-deps" }
},
checkOnSave = true
}
}
- Attached buffers: 1
vim.lsp: Enabled Configurations
vim.lsp: File Watcher
- file watching "(workspace/didChangeWatchedFiles)" disabled on all clients
vim.lsp: Position Encodings
- No buffers contain mixed position encodingsWith normal config |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 2 replies
-
|
I tried using using the root_dir function from the nvim-lspconfig plugin word-for-word, but: Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: /usr/share/nvim/runtime/filetype.lua:36: BufReadPost Autocommands for "*"..FileType Autocommands for "*"..function <SNR>1_LoadFTPlugin[20]..
script /home/playbahn/.local/share/nvim/lazy/rustaceanvim/ftplugin/rust.lua: Vim(runtime):E5113: Error while calling lua chunk: /home/playbahn/.config/nvim/lua/plugins/ru
staceanvim.lua:56: Invalid 'buffer': Expected Lua number
stack traceback:
[C]: in function 'nvim_buf_get_name'
/home/playbahn/.config/nvim/lua/plugins/rustaceanvim.lua:56: in function 'root_dir'
.../share/nvim/lazy/rustaceanvim/lua/rustaceanvim/cargo.lua:127: in function 'get_config_root_dir'
...are/nvim/lazy/rustaceanvim/lua/rustaceanvim/lsp/init.lua:169: in function 'start'
...hn/.local/share/nvim/lazy/rustaceanvim/ftplugin/rust.lua:64: in main chunk
[C]: in function 'nvim_cmd'
/usr/share/nvim/runtime/filetype.lua:36: in function </usr/share/nvim/runtime/filetype.lua:35>
[C]: in function 'pcall'
vim/shared.lua: in function <vim/shared.lua:0>
[C]: in function '_with'
/usr/share/nvim/runtime/filetype.lua:35: in function </usr/share/nvim/runtime/filetype.lua:10>
stack traceback:
[C]: in function '_with'
/usr/share/nvim/runtime/filetype.lua:35: in function </usr/share/nvim/runtime/filetype.lua:10>I then tried looking at the rustaceanvim code, and though it does have mentions of root_dir I don't understand Lua enough to form a strong understanding. I then i could just just pass |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
Looks like the problem is in here: vim.system(cmd, { text = true }, function(output)
if output.code == 0 then
if output.stdout then
local result = vim.json.decode(output.stdout)
if result['workspace_root'] then
cargo_workspace_root = vim.fs.normalize(result['workspace_root'])
end
end
on_dir(cargo_workspace_root or cargo_crate_dir)
else
vim.schedule(function()
vim.notify(
('[rust_analyzer] cmd failed with code %d: %s\n%s'):format(
output.code,
cmd,
output.stderr
)
)
end)
end
end)With the exact line being: on_dir(cargo_workspace_root or cargo_crate_dir) |
Beta Was this translation helpful? Give feedback.
-
|
Adding a |
Beta Was this translation helpful? Give feedback.
-
|
Nvim's
Then why is it not reusing? |
Beta Was this translation helpful? Give feedback.
-
|
Playing around: diff --git a/lua/rustaceanvim/cargo.lua b/lua/rustaceanvim/cargo.lua
index 448a20a..68a17d1 100644
--- a/lua/rustaceanvim/cargo.lua
+++ b/lua/rustaceanvim/cargo.lua
@@ -94,6 +94,7 @@ end
---@param file_name string
---@return string | nil root_dir The root directory of the active client for file_name (if there is one)
local function get_mb_active_client_root(file_name)
+ vim.print("inside get_mb_active_client_root")
---@diagnostic disable-next-line: missing-parameter
local cargo_home = vim.uv.os_getenv('CARGO_HOME') or vim.fs.joinpath(vim.env.HOME, '.cargo')
local registry = vim.fs.joinpath(cargo_home, 'registry', 'src')
@@ -105,8 +106,13 @@ local function get_mb_active_client_root(file_name)
for _, item in ipairs { toolchains, registry, checkouts } do
item = os.normalize_path_on_windows(item)
+ vim.print("file_name: " .. file_name)
+ vim.print("item: " .. item)
+ vim.print("file_name:sub(1, #item): " .. file_name:sub(1, #item))
+ vim.print("file_name:sub(1, #item) == item: " .. tostring(file_name:sub(1, #item) == item))
if file_name:sub(1, #item) == item then
local clients = rust_analyzer.get_active_rustaceanvim_clients()
+ vim.print("clients: " .. clients)
return clients and #clients > 0 and clients[#clients].config.root_dir or nil
end
endresulting in: inside get_mb_active_client_root
file_name: /home/playbahn/master/simd-basics/src/lib.rs
item: /home/playbahn/.rustup/toolchains
file_name:sub(1, #item): /home/playbahn/master/simd-basics
file_name:sub(1, #item) == item: false
file_name: /home/playbahn/master/simd-basics/src/lib.rs
item: /home/playbahn/.cargo/registry/src
file_name:sub(1, #item): /home/playbahn/master/simd-basics/
file_name:sub(1, #item) == item: false
file_name: /home/playbahn/master/simd-basics/src/lib.rs
item: /home/playbahn/.cargo/git/checkouts
file_name:sub(1, #item): /home/playbahn/master/simd-basics/s
file_name:sub(1, #item) == item: falseall the
EDIT: What if its a Cargo workspace with a lot of crates? |
Beta Was this translation helpful? Give feedback.
-
This is not supported by rustaceanvim or rust-analyzer. I've just realised that ra-multiplex has been archived and moved to lspmux. |
Beta Was this translation helpful? Give feedback.

This is not supported by rustaceanvim or rust-analyzer.
You can use ra-mulitplex for that.
I've just realised that ra-multiplex has been archived and moved to lspmux.
I haven't looked into whether lspmux has any breaking changes of if it's still compatible with rustaceanvim yet (see #870).