From 9ef7575b8395bba6ff4fbe4a5656c7fad7f518b7 Mon Sep 17 00:00:00 2001 From: Jatinderjit Singh Date: Sun, 19 Jan 2025 22:04:15 +0530 Subject: [PATCH] Replace `rust-tools` with `rustaceanvim` (#166) * Replace rust-tools with rustaceanvim `rust-tools` is archived. The Astrocommunity Rust language pack has also moved to `rustaceanvim`. * fix(rust): update rustaceanvim docs to use AstroLSP settings --------- Co-authored-by: Micah Halter --- src/content/docs/recipes/advanced_lsp.mdx | 39 +++++++++++++++++------ 1 file changed, 30 insertions(+), 9 deletions(-) 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` }, }, {