mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-01-03 01:25:57 +00:00
rust: switch to rustaceanvim
This commit is contained in:
parent
fceee5c8d3
commit
e0e81e6e62
1 changed files with 48 additions and 59 deletions
|
|
@ -125,72 +125,61 @@ in {
|
||||||
|
|
||||||
(mkIf (cfg.lsp.enable || cfg.dap.enable) {
|
(mkIf (cfg.lsp.enable || cfg.dap.enable) {
|
||||||
vim = {
|
vim = {
|
||||||
startPlugins = ["rust-tools"] ++ optionals cfg.dap.enable [cfg.dap.package];
|
startPlugins = ["rustaceanvim"];
|
||||||
|
|
||||||
lsp.lspconfig = {
|
luaConfigRC.rustaceanvim = entryAnywhere ''
|
||||||
enable = true;
|
vim.g.rustaceanvim = {
|
||||||
sources.rust-lsp = ''
|
${optionalString cfg.lsp.enable ''
|
||||||
local rt = require('rust-tools')
|
-- LSP
|
||||||
rust_on_attach = function(client, bufnr)
|
tools = {
|
||||||
default_on_attach(client, bufnr)
|
hover_actions = {
|
||||||
local opts = { noremap=true, silent=true, buffer = bufnr }
|
replace_builtin_hover = false
|
||||||
vim.keymap.set("n", "<leader>ris", rt.inlay_hints.set, opts)
|
|
||||||
vim.keymap.set("n", "<leader>riu", rt.inlay_hints.unset, opts)
|
|
||||||
vim.keymap.set("n", "<leader>rr", rt.runnables.runnables, opts)
|
|
||||||
vim.keymap.set("n", "<leader>rp", rt.parent_module.parent_module, opts)
|
|
||||||
vim.keymap.set("n", "<leader>rm", rt.expand_macro.expand_macro, opts)
|
|
||||||
vim.keymap.set("n", "<leader>rc", rt.open_cargo_toml.open_cargo_toml, opts)
|
|
||||||
vim.keymap.set("n", "<leader>rg", function() rt.crate_graph.view_crate_graph("x11", nil) end, opts)
|
|
||||||
${optionalString cfg.dap.enable ''
|
|
||||||
vim.keymap.set("n", "<leader>rd", ":RustDebuggables<cr>", opts)
|
|
||||||
vim.keymap.set(
|
|
||||||
"n", "${config.vim.debugger.nvim-dap.mappings.continue}",
|
|
||||||
function()
|
|
||||||
local dap = require("dap")
|
|
||||||
if dap.status() == "" then
|
|
||||||
vim.cmd "RustDebuggables"
|
|
||||||
else
|
|
||||||
dap.continue()
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
''}
|
|
||||||
end
|
|
||||||
local rustopts = {
|
|
||||||
tools = {
|
|
||||||
autoSetHints = true,
|
|
||||||
hover_with_actions = false,
|
|
||||||
inlay_hints = {
|
|
||||||
only_current_line = false,
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
server = {
|
},
|
||||||
capabilities = capabilities,
|
server = {
|
||||||
on_attach = rust_on_attach,
|
cmd = ${
|
||||||
cmd = ${
|
|
||||||
if isList cfg.lsp.package
|
if isList cfg.lsp.package
|
||||||
then expToLua cfg.lsp.package
|
then expToLua cfg.lsp.package
|
||||||
else ''{"${cfg.lsp.package}/bin/rust-analyzer"}''
|
else ''{"${cfg.lsp.package}/bin/rust-analyzer"}''
|
||||||
},
|
},
|
||||||
settings = {
|
on_attach = function(client, bufnr)
|
||||||
${cfg.lsp.opts}
|
default_on_attach(client, bufnr)
|
||||||
}
|
local opts = { noremap=true, silent=true, buffer = bufnr }
|
||||||
},
|
vim.keymap.set("n", "<leader>rr", ":RustLsp runnables<CR>", opts)
|
||||||
|
vim.keymap.set("n", "<leader>rp", ":RustLsp parentModule<CR>", opts)
|
||||||
${optionalString cfg.dap.enable ''
|
vim.keymap.set("n", "<leader>rm", ":RustLsp expandMacro<CR>", opts)
|
||||||
dap = {
|
vim.keymap.set("n", "<leader>rc", ":RustLsp openCargo", opts)
|
||||||
adapter = {
|
vim.keymap.set("n", "<leader>rg", ":RustLsp crateGraph x11", opts)
|
||||||
type = "executable",
|
${optionalString cfg.dap.enable ''
|
||||||
command = "${cfg.dap.package}/bin/lldb-vscode",
|
vim.keymap.set("n", "<leader>rd", ":RustLsp debuggables<cr>", opts)
|
||||||
name = "rt_lldb",
|
vim.keymap.set(
|
||||||
},
|
"n", "${config.vim.debugger.nvim-dap.mappings.continue}",
|
||||||
},
|
function()
|
||||||
|
local dap = require("dap")
|
||||||
|
if dap.status() == "" then
|
||||||
|
vim.cmd "RustLsp debuggables"
|
||||||
|
else
|
||||||
|
dap.continue()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
opts
|
||||||
|
)
|
||||||
''}
|
''}
|
||||||
}
|
end
|
||||||
rt.setup(rustopts)
|
},
|
||||||
'';
|
''}
|
||||||
};
|
|
||||||
|
${optionalString cfg.dap.enable ''
|
||||||
|
dap = {
|
||||||
|
adapter = {
|
||||||
|
type = "executable",
|
||||||
|
command = "${cfg.dap.package}/bin/lldb-vscode",
|
||||||
|
name = "rustacean_lldb",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
''}
|
||||||
|
}
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue