Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace rust-tools with rustaceanvim #166

Merged
merged 2 commits into from
Jan 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading