diff --git a/src/content/docs/recipes/advanced_lsp.mdx b/src/content/docs/recipes/advanced_lsp.mdx index 0843ac714..09c6caf50 100644 --- a/src/content/docs/recipes/advanced_lsp.mdx +++ b/src/content/docs/recipes/advanced_lsp.mdx @@ -566,7 +566,7 @@ return { } ``` -### Rust ([rust-tools.nvim](https://github.com/simrat39/rust-tools.nvim)) +### Rust ([rustaceanvim](https://github.com/mrcjkb/rustaceanvim)) :::tip @@ -581,19 +581,40 @@ return { ::: -```lua title="lua/plugins/rust-tools.lua" +```lua title="lua/plugins/rustaceanvim.lua" return { - { "simrat39/rust-tools.nvim", lazy = true }, -- add lsp plugin + { + 'mrcjkb/rustaceanvim', -- add lsp plugin + version = '^5', + lazy = false, -- This plugin is already lazy + opts = function(_, opts) + local astrolsp_avail, astrolsp = pcall(require, "astrolsp") + local astrolsp_opts = (astrolsp_avail and astrolsp.lsp_opts "rust_analyzer") or {} + local server = { + ---@type table | (fun(project_root:string|nil, default_settings: table|nil):table) -- The rust-analyzer settings or a function that creates them. + settings = function(project_root, default_settings) + local astrolsp_settings = astrolsp_opts.settings or {} + + local merge_table = require("astrocore").extend_tbl(default_settings or {}, astrolsp_settings) + local ra = require "rustaceanvim.config.server" + -- load_rust_analyzer_settings merges any found settings with the passed in default settings table and then returns that table + return ra.load_rust_analyzer_settings(project_root, { + settings_file_pattern = "rust-analyzer.json", + default_settings = merge_table, + }) + end, + } + return { server = require("astrocore").extend_tbl(astrolsp_opts, server) } + end, + -- configure `rustaceanvim` by setting the `vim.g.rustaceanvim` variable + config = function(_, opts) vim.g.rustaceanvim = require("astrocore").extend_tbl(opts, vim.g.rustaceanvim) end, + + }, { "AstroNvim/astrolsp", ---@type AstroLSPOpts opts = { - setup_handlers = { - -- add custom handler - rust_analyzer = function(_, opts) - require("rust-tools").setup({ server = opts }) - end, - }, + handlers = { rust_analyzer = false }, -- Let rustaceanvim setup `rust_analyzer` }, }, {