Skip to content

Commit

Permalink
Replace rust-tools with rustaceanvim (#166)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
jatinderjit and mehalter authored Jan 19, 2025
1 parent eb046a0 commit 9ef7575
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions src/content/docs/recipes/advanced_lsp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ return {
}
```

### Rust ([rust-tools.nvim](https://github.com/simrat39/rust-tools.nvim))
### Rust ([rustaceanvim](https://github.com/mrcjkb/rustaceanvim))

:::tip

Expand All @@ -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`
},
},
{
Expand Down

0 comments on commit 9ef7575

Please sign in to comment.