Skip to content

Commit

Permalink
feat(rust): rust improvements (LazyVim#1015)
Browse files Browse the repository at this point in the history
* fix(rust): move lspconfig opts to correct location

lspconfig's `opts` goes in rust-tools's `opts.server`; see
https://github.com/simrat39/rust-tools.nvim#configuration

* feat(rust): add neotest-rust

* feat(rust): allow user to extend rust-tools with `opts`

Also avoids calling rust-tools's `setup()` twice.

* style(rust): fix indentation for stylua comment
  • Loading branch information
loqusion authored and joshmedeski committed Sep 1, 2023
1 parent a6246f0 commit c836481
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions lua/lazyvim/plugins/extras/lang/rust.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ return {
-- Correctly setup lspconfig for Rust 🚀
{
"neovim/nvim-lspconfig",
dependencies = { "simrat39/rust-tools.nvim" },
dependencies = {
"simrat39/rust-tools.nvim",
-- Avoid calling setup twice if user supplies `opts`
config = function() end,
},
opts = {
servers = {
-- Ensure mason installs the server
Expand All @@ -52,7 +56,7 @@ return {
setup = {
rust_analyzer = function(_, opts)
require("lazyvim.util").on_attach(function(client, buffer)
-- stylua: ignore
-- stylua: ignore
if client.name == "rust_analyzer" then
vim.keymap.set("n", "K", "<cmd>RustHoverActions<cr>", { buffer = buffer, desc = "Hover Actions (Rust)" })
vim.keymap.set( "n", "<leader>cR", "<cmd>RustCodeAction<cr>", { buffer = buffer, desc = "Code Action (Rust)" })
Expand All @@ -66,7 +70,8 @@ return {
local codelldb_path = extension_path .. "adapter/codelldb"
local liblldb_path = vim.fn.has("mac") == 1 and extension_path .. "lldb/lib/liblldb.dylib"
or extension_path .. "lldb/lib/liblldb.so"
local rust_tools_opts = vim.tbl_deep_extend("force", opts, {
local user_rust_tools_opts = require("lazyvim.util").opts("rust-tools.nvim")
local rust_tools_opts = vim.tbl_deep_extend("force", user_rust_tools_opts, {
dap = {
adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path),
},
Expand All @@ -81,7 +86,7 @@ return {
]])
end,
},
server = {
server = vim.tbl_deep_extend("force", opts, {
settings = {
["rust-analyzer"] = {
cargo = {
Expand All @@ -105,7 +110,7 @@ return {
},
},
},
},
}),
})
require("rust-tools").setup(rust_tools_opts)
return true
Expand All @@ -128,4 +133,17 @@ return {
},
},
},

{
"nvim-neotest/neotest",
optional = true,
dependencies = {
"rouge8/neotest-rust",
},
opts = {
adapters = {
["neotest-rust"] = {},
},
},
},
}

0 comments on commit c836481

Please sign in to comment.