mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-21 08:35:53 +02:00
## Description Rather than manually handling hover and completions through nvim-cmp and nvim-lspconfig, enable the crates.nvim in-process lsp server. This also allows crates.nvim to provide code actions. <!-- Describe the big picture of your changes to communicate to the maintainers why we should accept this pull request. --> ## Related Issue(s) This change also removes the direct dependency on nvim-cmp, which should help with #4680 <!-- If this PR fixes any issues, please link to the issue here. - Fixes #<issue_number> --> ## Screenshots <!-- Add screenshots of the changes if applicable. --> ## Checklist - [x] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines. Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
109 lines
2.6 KiB
Lua
109 lines
2.6 KiB
Lua
return {
|
|
recommended = function()
|
|
return LazyVim.extras.wants({
|
|
ft = "rust",
|
|
root = { "Cargo.toml", "rust-project.json" },
|
|
})
|
|
end,
|
|
|
|
-- LSP for Cargo.toml
|
|
{
|
|
"Saecki/crates.nvim",
|
|
event = { "BufRead Cargo.toml" },
|
|
opts = {
|
|
completion = {
|
|
crates = {
|
|
enabled = true,
|
|
},
|
|
},
|
|
lsp = {
|
|
enabled = true,
|
|
actions = true,
|
|
completion = true,
|
|
hover = true,
|
|
},
|
|
},
|
|
},
|
|
|
|
-- Add Rust & related to treesitter
|
|
{
|
|
"nvim-treesitter/nvim-treesitter",
|
|
opts = { ensure_installed = { "rust", "ron" } },
|
|
},
|
|
|
|
-- Ensure Rust debugger is installed
|
|
{
|
|
"williamboman/mason.nvim",
|
|
optional = true,
|
|
opts = { ensure_installed = { "codelldb" } },
|
|
},
|
|
|
|
{
|
|
"mrcjkb/rustaceanvim",
|
|
version = vim.fn.has("nvim-0.10.0") == 0 and "^4" or false,
|
|
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 = true,
|
|
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 = {
|
|
servers = {
|
|
rust_analyzer = { enabled = false },
|
|
},
|
|
},
|
|
},
|
|
|
|
{
|
|
"nvim-neotest/neotest",
|
|
optional = true,
|
|
opts = {
|
|
adapters = {
|
|
["rustaceanvim.neotest"] = {},
|
|
},
|
|
},
|
|
},
|
|
}
|