Skip to content

Commit

Permalink
Switch to rustaceanvim (#335)
Browse files Browse the repository at this point in the history
* flake: use rustaceanvim instead of rust-tools

* rust: switch to rustaceanvim

* docs: update release notes

* flake: update nixpkgs

* docs: wording

---------

Co-authored-by: raf <[email protected]>
  • Loading branch information
horriblename and NotAShelf authored Jul 18, 2024
1 parent 0f17147 commit 9c93e9a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 74 deletions.
5 changes: 5 additions & 0 deletions docs/release-notes/rl-0.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Release notes for release 0.7
longer filtered and thus should be used instead.
- Add dap-go for better dap configurations
- Make noice.nvim customizable
- Switch from [rust-tools.nvim](https://github.com/simrat39/rust-tools.nvim)
to the more feature-packed [rustacean.nvim](https://github.com/mrcjkb/rustaceanvim.
This switch entails a whole bunch of new features and options, so you are
recommended to go through rustacean.nvim's README to take a closer look at
its features and usage.

[jacekpoz](https://github.com/jacekpoz):

Expand Down
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@
flake = false;
};

plugin-rust-tools = {
url = "github:simrat39/rust-tools.nvim";
plugin-rustaceanvim = {
url = "github:mrcjkb/rustaceanvim";
flake = false;
};

Expand Down
109 changes: 49 additions & 60 deletions modules/plugins/languages/rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -125,72 +125,61 @@ in {

(mkIf (cfg.lsp.enable || cfg.dap.enable) {
vim = {
startPlugins = ["rust-tools"] ++ optionals cfg.dap.enable [cfg.dap.package];

lsp.lspconfig = {
enable = true;
sources.rust-lsp = ''
local rt = require('rust-tools')
rust_on_attach = function(client, bufnr)
default_on_attach(client, bufnr)
local opts = { noremap=true, silent=true, buffer = bufnr }
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,
}
startPlugins = ["rustaceanvim"];

luaConfigRC.rustaceanvim = entryAnywhere ''
vim.g.rustaceanvim = {
${optionalString cfg.lsp.enable ''
-- LSP
tools = {
hover_actions = {
replace_builtin_hover = false
},
server = {
capabilities = capabilities,
on_attach = rust_on_attach,
cmd = ${
},
server = {
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/rust-analyzer"}''
},
settings = {
${cfg.lsp.opts}
}
},
${optionalString cfg.dap.enable ''
dap = {
adapter = {
type = "executable",
command = "${cfg.dap.package}/bin/lldb-vscode",
name = "rt_lldb",
},
},
on_attach = function(client, bufnr)
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)
vim.keymap.set("n", "<leader>rm", ":RustLsp expandMacro<CR>", opts)
vim.keymap.set("n", "<leader>rc", ":RustLsp openCargo", opts)
vim.keymap.set("n", "<leader>rg", ":RustLsp crateGraph x11", opts)
${optionalString cfg.dap.enable ''
vim.keymap.set("n", "<leader>rd", ":RustLsp debuggables<cr>", opts)
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
)
''}
}
rt.setup(rustopts)
'';
};
end
},
''}
${optionalString cfg.dap.enable ''
dap = {
adapter = {
type = "executable",
command = "${cfg.dap.package}/bin/lldb-vscode",
name = "rustacean_lldb",
},
},
''}
}
'';
};
})
]);
Expand Down

0 comments on commit 9c93e9a

Please sign in to comment.