]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/lang/rust.lua
lazyvim: absorb all langs
[dotfiles.git] / nvim / lua / plugins / lang / rust.lua
1 return {
2 { "Saecki/crates.nvim",
3 event = { "BufRead Cargo.toml" },
4 opts = {
5 completion = {
6 crates = {
7 enabled = true,
8 },
9 },
10 lsp = {
11 enabled = true,
12 actions = true,
13 completion = true,
14 hover = true,
15 },
16 },
17 },
18 { "nvim-treesitter/nvim-treesitter",
19 opts = { ensure_installed = { "rust", "ron" } },
20 },
21 { "williamboman/mason.nvim",
22 optional = true,
23 opts = function(_, opts)
24 opts.ensure_installed = opts.ensure_installed or {}
25 vim.list_extend(opts.ensure_installed, { "codelldb" })
26 end,
27 },
28 { "mrcjkb/rustaceanvim",
29 version = vim.fn.has("nvim-0.10.0") == 0 and "^4" or false,
30 ft = { "rust" },
31 opts = {
32 server = {
33 on_attach = function(_, bufnr)
34 vim.keymap.set("n", "<leader>cR", function()
35 vim.cmd.RustLsp("codeAction")
36 end, { desc = "Code Action", buffer = bufnr })
37 vim.keymap.set("n", "<leader>dr", function()
38 vim.cmd.RustLsp("debuggables")
39 end, { desc = "Rust Debuggables", buffer = bufnr })
40 end,
41 default_settings = {
42 -- rust-analyzer language server configuration
43 ["rust-analyzer"] = {
44 cargo = {
45 allFeatures = true,
46 loadOutDirsFromCheck = true,
47 buildScripts = {
48 enable = true,
49 },
50 },
51 -- Add clippy lints for Rust if using rust-analyzer
52 checkOnSave = true,
53 -- Enable diagnostics if using rust-analyzer
54 diagnostics = {
55 enable = true,
56 },
57 procMacro = {
58 enable = true,
59 ignored = {
60 ["async-trait"] = { "async_trait" },
61 ["napi-derive"] = { "napi" },
62 ["async-recursion"] = { "async_recursion" },
63 },
64 },
65 files = {
66 excludeDirs = {
67 ".direnv",
68 ".git",
69 ".github",
70 ".gitlab",
71 "bin",
72 "node_modules",
73 "target",
74 "venv",
75 ".venv",
76 },
77 },
78 },
79 },
80 },
81 },
82 config = function(_, opts)
83 local package_path = require("mason-registry").get_package("codelldb"):get_install_path()
84 local codelldb = package_path .. "/extension/adapter/codelldb"
85 local library_path = package_path .. "/extension/lldb/lib/liblldb.dylib"
86 local uname = io.popen("uname"):read("*l")
87 if uname == "Linux" then
88 library_path = package_path .. "/extension/lldb/lib/liblldb.so"
89 end
90 opts.dap = {
91 adapter = require("rustaceanvim.config").get_codelldb_adapter(codelldb, library_path),
92 }
93 vim.g.rustaceanvim = vim.tbl_deep_extend("keep", vim.g.rustaceanvim or {}, opts or {})
94 if vim.fn.executable("rust-analyzer") == 0 then
95 rmz.lazy.error(
96 "**rust-analyzer** not found in PATH, please install it.\nhttps://rust-analyzer.github.io/",
97 { title = "rustaceanvim" }
98 )
99 end
100 end,
101 },
102 { "neovim/nvim-lspconfig",
103 opts = {
104 servers = {
105 rust_analyzer = { enabled = false }, -- rustaceanvim is used instead
106 },
107 },
108 },
109 { "nvim-neotest/neotest",
110 optional = true,
111 opts = {
112 adapters = {
113 ["rustaceanvim.neotest"] = {},
114 },
115 },
116 },
117 }