Skip to content

Commit 1770f67

Browse files
venkatarenduchintalaVenkata Subramani Renduchintala
andauthored
refactor(rust): replace rust-tools.nvim with rustaceanvim for native LSP (#22)
rust-tools.nvim is archived and called lspconfig.rust_analyzer.setup() internally, conflicting with mason-lspconfig automatic_enable (double start). - lua/lsp/configs/rust.lua: replace rust-tools.nvim with mrcjkb/rustaceanvim v5 - vim.g.rustaceanvim for tools config; server settings live in after/lsp/rust_analyzer.lua - Rust keymaps via LspAttach autocmd (consistent with global lsp/init.lua pattern) - RustLsp debuggables/runnables replace RustDebuggables/RustRun commands - Keep crates.nvim unchanged - mason.lua: add rust_analyzer to automatic_enable.exclude (rustaceanvim owns the start) Co-authored-by: Venkata Subramani Renduchintala <venkatarenduchintala@pm.me>
1 parent 80d9b68 commit 1770f67

2 files changed

Lines changed: 26 additions & 152 deletions

File tree

lua/lsp/configs/rust.lua

Lines changed: 24 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,169 +1,43 @@
11
return {
2-
-- Rust-tools
2+
-- rustaceanvim: native LSP API Rust support (replaces archived rust-tools.nvim)
33
{
4-
"simrat39/rust-tools.nvim",
5-
dependencies = {
6-
"neovim/nvim-lspconfig",
7-
"nvim-lua/plenary.nvim",
8-
"mfussenegger/nvim-dap",
9-
},
10-
enabled = true,
11-
ft = { "rust", "toml" },
12-
config = function()
13-
local handlers = require("lsp.handlers")
14-
local extension_path = require("mason-registry").get_package("codelldb"):get_install_path() .. "/extension/"
15-
local codelldb_path = extension_path .. "adapter/codelldb"
16-
local liblldb_path = extension_path .. "lldb/lib/liblldb.so"
17-
local rust_tools = require("rust-tools")
18-
19-
rust_tools.setup({
4+
"mrcjkb/rustaceanvim",
5+
version = "^5",
6+
lazy = false,
7+
init = function()
8+
vim.g.rustaceanvim = {
209
tools = {
21-
executor = require("rust-tools.executors").termopen,
22-
autoSetHints = true,
23-
runnables = {
24-
use_telescope = true,
25-
},
26-
reload_workspace_from_cargo_toml = true,
27-
on_initialized = function()
28-
vim.cmd([[
29-
augroup RustLSP
30-
autocmd CursorHold *.rs silent! lua vim.lsp.buf.document_highlight()
31-
autocmd CursorMoved,InsertEnter *.rs silent! lua vim.lsp.buf.clear_references()
32-
autocmd BufEnter,CursorHold,InsertLeave *.rs silent! lua vim.lsp.codelens.refresh()
33-
augroup END
34-
]])
35-
end,
36-
inlay_hints = {
37-
auto = false,
38-
only_current_line = false,
39-
show_parameter_hints = true,
40-
parameter_hints_prefix = "<- ",
41-
other_hints_prefix = "=> ",
42-
max_len_align = false,
43-
max_len_align_padding = 1,
44-
right_align = false,
45-
right_align_padding = 7,
46-
highlight = "Comment",
47-
},
48-
hover_actions = {
49-
border = {
50-
{ "", "FloatBorder" },
51-
{ "", "FloatBorder" },
52-
{ "", "FloatBorder" },
53-
{ "", "FloatBorder" },
54-
{ "", "FloatBorder" },
55-
{ "", "FloatBorder" },
56-
{ "", "FloatBorder" },
57-
{ "", "FloatBorder" },
58-
},
59-
max_width = nil,
60-
max_height = nil,
61-
auto_focus = true,
62-
},
63-
crate_graph = {
64-
backend = "x11",
65-
output = nil,
66-
full = true,
67-
enabled_graphviz_backends = {
68-
"bmp",
69-
"cgimage",
70-
"canon",
71-
"dot",
72-
"gv",
73-
"xdot",
74-
"xdot1.2",
75-
"xdot1.4",
76-
"eps",
77-
"exr",
78-
"fig",
79-
"gd",
80-
"gd2",
81-
"gif",
82-
"gtk",
83-
"ico",
84-
"cmap",
85-
"ismap",
86-
"imap",
87-
"cmapx",
88-
"imap_np",
89-
"cmapx_np",
90-
"jpg",
91-
"jpeg",
92-
"jpe",
93-
"jp2",
94-
"json",
95-
"json0",
96-
"dot_json",
97-
"xdot_json",
98-
"pdf",
99-
"pic",
100-
"pct",
101-
"pict",
102-
"plain",
103-
"plain-ext",
104-
"png",
105-
"pov",
106-
"ps",
107-
"ps2",
108-
"psd",
109-
"sgi",
110-
"svg",
111-
"svgz",
112-
"tga",
113-
"tiff",
114-
"tif",
115-
"tk",
116-
"vml",
117-
"vmlz",
118-
"wbmp",
119-
"webp",
120-
"xlib",
121-
"x11",
122-
},
123-
},
10+
hover_actions = { auto_focus = true },
12411
},
125-
server = {
126-
on_attach = function(_, bufnr)
127-
handlers.on_attach(_, bufnr)
128-
wk = require("which-key")
129-
wk.add({
130-
{ "<leader>dE", "<cmd>RustDebuggables<cr>", desc = "[RUST] Show debug configurations" },
131-
{ "<leader>de", "<cmd>RustLastDebug<cr>", desc = "[RUST] Debug last" },
132-
{ "<leader>dR", "<cmd>RustRun<cr>", desc = "[RUST] Show run configurations" },
133-
{ "<leader>dr", "<cmd>RustLastRun<cr>", desc = "[RUST] Run last" },
12+
}
13+
-- Rust-specific keymaps; global on_attach is wired in lsp/init.lua via LspAttach
14+
vim.api.nvim_create_autocmd("LspAttach", {
15+
callback = function(args)
16+
local client = vim.lsp.get_client_by_id(args.data.client_id)
17+
if client and client.name == "rust_analyzer" then
18+
require("which-key").add({
19+
{ "<leader>dE", "<cmd>RustLsp debuggables<cr>", desc = "[RUST] Show debuggables", buffer = args.buf },
20+
{ "<leader>de", "<cmd>RustLsp! debuggables<cr>", desc = "[RUST] Debug last", buffer = args.buf },
21+
{ "<leader>dR", "<cmd>RustLsp runnables<cr>", desc = "[RUST] Show runnables", buffer = args.buf },
22+
{ "<leader>dr", "<cmd>RustLsp! runnables<cr>", desc = "[RUST] Run last", buffer = args.buf },
13423
})
135-
end,
136-
capabilities = handlers.capabilities,
137-
standalone = false,
138-
},
139-
dap = {
140-
adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path),
141-
},
24+
end
25+
end,
14226
})
14327
end,
14428
},
145-
-- Crates
29+
-- crates.nvim: Cargo.toml dependency management
14630
{
14731
"saecki/crates.nvim",
14832
enabled = true,
149-
event = { "BufRead Cargo.toml" },
33+
event = { "BufRead Cargo.toml" },
15034
tag = "v0.4.0",
15135
lazy = true,
15236
dependencies = { "nvim-lua/plenary.nvim" },
15337
config = function()
15438
require("crates").setup({
155-
src = {
156-
--[[ coq = {
157-
enabled = true,
158-
name = "crates.nvim",
159-
}, ]]
160-
cmp = {
161-
enabled = true,
162-
},
163-
},
164-
popup = {
165-
border = "rounded",
166-
},
39+
src = { cmp = { enabled = true } },
40+
popup = { border = "rounded" },
16741
})
16842
end,
16943
},

lua/plugins/configs/mason.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ return {
1717
"mason-org/mason-lspconfig.nvim",
1818
config = function()
1919
require("mason-lspconfig").setup({
20-
-- Auto-enable all installed servers; jdtls has its own startup lifecycle
20+
-- Auto-enable all installed servers; jdtls + rust_analyzer have their own lifecycle
2121
automatic_enable = {
22-
exclude = { "jdtls" },
22+
exclude = { "jdtls", "rust_analyzer" },
2323
},
2424
-- skip heavy binary downloads in CI; lazy.nvim plugin code is still validated
2525
ensure_installed = vim.env.CI and {} or {

0 commit comments

Comments
 (0)