Skip to content

fix(rust): drop incompatible root_dir under native_lsp_config#1747

Closed
Mic92 wants to merge 1 commit intoAstroNvim:mainfrom
Mic92:fix-rust-native-lsp-config
Closed

fix(rust): drop incompatible root_dir under native_lsp_config#1747
Mic92 wants to merge 1 commit intoAstroNvim:mainfrom
Mic92:fix-rust-native-lsp-config

Conversation

@Mic92
Copy link
Copy Markdown
Contributor

@Mic92 Mic92 commented Mar 29, 2026

📑 Description

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 on every rust file open:

Error executing lua callback: .../lsp/rust_analyzer.lua:89: Invalid 'buffer': Expected Lua number
stack traceback:
        [C]: in function 'nvim_buf_get_name'
        .../nvim-lspconfig/lsp/rust_analyzer.lua:89: in function 'root_dir'
        .../rustaceanvim/lua/rustaceanvim/cargo.lua:127: in function 'get_config_root_dir'
        .../rustaceanvim/lua/rustaceanvim/lsp/init.lua:171: in function 'start'

This drops 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.

  • Tested with native_lsp_config = true — rust-analyzer attaches, no errors
  • Tested with native_lsp_config = false (default) — rust-analyzer attaches, root_dir untouched, no behavior change

📖 Additional Information

This becomes relevant for all users once native_lsp_config is the default (astrolsp v4, see AstroNvim/astrolsp#35).

The dart, scala, typescript-deno and moonbit packs also call astrolsp.lsp_opts and may have similar issues, but I have not tested those.

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).
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 29, 2026

Review Checklist

Does this PR follow the [Contribution Guidelines](development guidelines)? Following is a partial checklist:

Proper conventional commit scoping:

  • If you are adding a new plugin, the scope would be the name of the category it is being added into. ex. feat(utility): added noice.nvim plugin

  • If you are modifying a pre-existing plugin or pack, the scope would be the name of the plugin folder. ex. fix(noice-nvim): fix LSP handler error

  • Pull request title has the appropriate conventional commit type and scope where the scope is the name of the pre-existing directory in the project as described above

  • README is properly formatted and uses fenced in links with <url> unless they are inside a [title](url)

  • Entry returns a single plugin spec with the new plugin as the only top level spec (not applicable for recipes or packs).

  • Proper usage of opts table rather than setting things up with the config function.

  • Proper usage of specs table for all specs that are not dependencies of a given plugin (not applicable for recipes or packs).

@rami3l
Copy link
Copy Markdown
Contributor

rami3l commented Apr 7, 2026

I second this; this fix is also a necessary step to bump rustaceanvim to v7 and higher.

FTR I've already got rustaceanvim v9 running with some tiny modifications to the current pack, and I'd love to upstream the rest when this fix lands.

@Uzaaft
Copy link
Copy Markdown
Member

Uzaaft commented Apr 10, 2026

@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
Copy link
Copy Markdown
Contributor

@rami3l rami3l Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since AstroNvim/astrolsp#35 has been merged, astrolsp.config.native_lsp_config no longer exists, so this line should simply be:

Suggested change
if astrolsp_avail and astrolsp.config.native_lsp_config then astrolsp_opts.root_dir = nil end
astrolsp_opts.root_dir = nil

@Uzaaft Uzaaft closed this Apr 11, 2026
@Mic92 Mic92 deleted the fix-rust-native-lsp-config branch April 14, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants