Files
LazyVim/lua/lazyvim/plugins/extras/lang/rust.lua
Lucas 3fadf6af8f fix(rust): let rustaceans.nvim setup rust_analyzer (#3389)
fix this warning
```
   Warn  11:52:45 PM notify.warn nvim-lspconfig.rust_analyzer has been setup.
This will likely lead to conflicts with the rustaceanvim LSP client.
See ':h rustaceanvim.mason'
```
fix taken from https://github.com/mrcjkb/rustaceanvim/blob/master/doc/mason.txt
2024-05-31 13:56:40 +02:00

142 lines
3.6 KiB
Lua

return {
recommended = function()
return LazyVim.extras.wants({
ft = "rust",
root = { "Cargo.toml", "rust-project.json" },
})
end,
-- Extend auto completion
{
"hrsh7th/nvim-cmp",
dependencies = {
{
"Saecki/crates.nvim",
event = { "BufRead Cargo.toml" },
opts = {
completion = {
cmp = { enabled = true },
},
},
},
},
---@param opts cmp.ConfigSchema
opts = function(_, opts)
opts.sources = opts.sources or {}
table.insert(opts.sources, { name = "crates" })
end,
},
-- Add Rust & related to treesitter
{
"nvim-treesitter/nvim-treesitter",
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { "ron", "rust", "toml" })
end,
},
-- Ensure Rust debugger is installed
{
"williamboman/mason.nvim",
optional = true,
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { "codelldb" })
end,
},
{
"mrcjkb/rustaceanvim",
version = "^4", -- Recommended
ft = { "rust" },
opts = {
server = {
on_attach = function(_, bufnr)
vim.keymap.set("n", "<leader>cR", function()
vim.cmd.RustLsp("codeAction")
end, { desc = "Code Action", buffer = bufnr })
vim.keymap.set("n", "<leader>dr", function()
vim.cmd.RustLsp("debuggables")
end, { desc = "Rust Debuggables", buffer = bufnr })
end,
default_settings = {
-- rust-analyzer language server configuration
["rust-analyzer"] = {
cargo = {
allFeatures = true,
loadOutDirsFromCheck = true,
buildScripts = {
enable = true,
},
},
-- Add clippy lints for Rust.
checkOnSave = {
allFeatures = true,
command = "clippy",
extraArgs = { "--no-deps" },
},
procMacro = {
enable = true,
ignored = {
["async-trait"] = { "async_trait" },
["napi-derive"] = { "napi" },
["async-recursion"] = { "async_recursion" },
},
},
},
},
},
},
config = function(_, opts)
vim.g.rustaceanvim = vim.tbl_deep_extend("keep", vim.g.rustaceanvim or {}, opts or {})
if vim.fn.executable("rust-analyzer") == 0 then
LazyVim.error(
"**rust-analyzer** not found in PATH, please install it.\nhttps://rust-analyzer.github.io/",
{ title = "rustaceanvim" }
)
end
end,
},
-- Correctly setup lspconfig for Rust 🚀
{
"neovim/nvim-lspconfig",
opts = {
setup = {
rust_analyzer = function()
return true
end,
},
servers = {
taplo = {
keys = {
{
"K",
function()
if vim.fn.expand("%:t") == "Cargo.toml" and require("crates").popup_available() then
require("crates").show_popup()
else
vim.lsp.buf.hover()
end
end,
desc = "Show Crate Documentation",
},
},
},
},
},
},
{
"nvim-neotest/neotest",
optional = true,
opts = function(_, opts)
opts.adapters = opts.adapters or {}
vim.list_extend(opts.adapters, {
require("rustaceanvim.neotest"),
})
end,
},
}