fix(rust): drop incompatible root_dir under native_lsp_config#1747
fix(rust): drop incompatible root_dir under native_lsp_config#1747Mic92 wants to merge 1 commit intoAstroNvim:mainfrom
Conversation
With astrolsp native_lsp_config enabled, lsp_opts("rust_analyzer")
returns the full vim.lsp.config table including nvim-lspconfig's
root_dir(bufnr, on_dir) function. rustaceanvim calls its root_dir
with (file_name, default_fn) instead, causing:
lsp/rust_analyzer.lua:89: Invalid 'buffer': Expected Lua number
Drop root_dir from the forwarded opts so rustaceanvim falls back to
its own cargo-aware root detection. Guarded on native_lsp_config so
legacy-path users who set a custom root_dir via
opts.config.rust_analyzer are unaffected.
This becomes relevant once native_lsp_config is the default
(astrolsp v4).
Review ChecklistDoes this PR follow the [Contribution Guidelines](development guidelines)? Following is a partial checklist: Proper conventional commit scoping:
|
|
I second this; this fix is also a necessary step to bump FTR I've already got |
|
@Mic92 Fix the conflicts and I'll merge this. |
| -- uses its own cargo-aware root detection. Only strip under | ||
| -- native_lsp_config so users on the legacy path who set a custom | ||
| -- root_dir via opts.config.rust_analyzer keep their override. | ||
| if astrolsp_avail and astrolsp.config.native_lsp_config then astrolsp_opts.root_dir = nil end |
There was a problem hiding this comment.
Since AstroNvim/astrolsp#35 has been merged, astrolsp.config.native_lsp_config no longer exists, so this line should simply be:
| if astrolsp_avail and astrolsp.config.native_lsp_config then astrolsp_opts.root_dir = nil end | |
| astrolsp_opts.root_dir = nil |
📑 Description
With astrolsp
native_lsp_configenabled,lsp_opts("rust_analyzer")returns the fullvim.lsp.configtable including nvim-lspconfig'sroot_dir(bufnr, on_dir)function. rustaceanvim calls itsroot_dirwith(file_name, default_fn)instead, causing on every rust file open:This drops
root_dirfrom the forwarded opts so rustaceanvim falls back to its own cargo-aware root detection. Guarded onnative_lsp_configso legacy-path users who set a customroot_dirviaopts.config.rust_analyzerare unaffected.native_lsp_config = true— rust-analyzer attaches, no errorsnative_lsp_config = false(default) — rust-analyzer attaches,root_diruntouched, no behavior change📖 Additional Information
This becomes relevant for all users once
native_lsp_configis the default (astrolsp v4, see AstroNvim/astrolsp#35).The
dart,scala,typescript-denoandmoonbitpacks also callastrolsp.lsp_optsand may have similar issues, but I have not tested those.