From 3d79ebb7c74d7a3de947f20d35b9b855cc878cc9 Mon Sep 17 00:00:00 2001 From: Rofelson Date: Sat, 10 Feb 2024 09:09:13 +0000 Subject: [PATCH] add rust config --- init.lua | 57 +++++++++++++++++++++++++++++-- lua/custom/plugins/crates.lua | 6 ++-- lua/custom/plugins/rust-tools.lua | 18 +++++----- 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/init.lua b/init.lua index 164a2394..ab43c514 100644 --- a/init.lua +++ b/init.lua @@ -448,7 +448,7 @@ local servers = { -- clangd = {}, -- gopls = {}, -- pyright = {}, - -- rust_analyzer = {}, + rust_analyzer = {}, -- tsserver = {}, -- html = { filetypes = { 'html', 'twig', 'hbs'} }, @@ -474,6 +474,54 @@ mason_lspconfig.setup { ensure_installed = vim.tbl_keys(servers), } +local rust_tools_config = { + -- executor = require("rust-tools.executors").quickfix, + + inlay_hints = { + auto = true, + parameter_hints_prefix = "<-", + other_hints_prefix = "->", + }, + server = { + standalone = false, + }, + dap = function() + local install_root_dir = vim.fn.stdpath "data" .. "/mason" + local extension_path = install_root_dir .. "/packages/codelldb/extension/" + local codelldb_path = extension_path .. "adapter/codelldb" + local liblldb_path = extension_path .. "lldb/lib/liblldb.so" + + return { + adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path) + } + end, +} + +local rust_tools_rust_server = { + on_attach = on_attach, + settings = { + -- List of all options: + -- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc + ["rust-analyzer"] = { + check = { + command = "cranky", + -- extraArgs = { "--all", "--", "-W", "clippy::all" }, + }, + + -- rust-analyzer.server.extraEnv + -- neovim doesn"t have custom client-side code to honor this setting, it doesn't actually work + -- https://github.com/neovim/nvim-lspconfig/issues/1735 + -- it's in init.vim as a real env variable + -- + -- server = { + -- extraEnv = { + -- CARGO_TARGET_DIR = "target/rust-analyzer-check" + -- } + -- } + }, + }, +} + mason_lspconfig.setup_handlers { function(server_name) require('lspconfig')[server_name].setup { @@ -484,7 +532,12 @@ mason_lspconfig.setup_handlers { } end, ["rust_analyzer"] = function() - require("rust-tools").setup {} + require("rust-tools").setup { + capabilities = capabilities, + -- add from https://github.com/Gremious/configs/blob/main/lua/config/lsp.lua#L110 + tools = rust_tools_config, + server = rust_tools_rust_server, + } end } diff --git a/lua/custom/plugins/crates.lua b/lua/custom/plugins/crates.lua index da4bb616..b5ae2fd9 100644 --- a/lua/custom/plugins/crates.lua +++ b/lua/custom/plugins/crates.lua @@ -5,9 +5,9 @@ return { config = function() local crates = require('crates') crates.setup() - require('cmp').setup.buffer({ - sources = { { name = 'crates' } } - }) + -- require('cmp').setup.buffer({ + -- sources = { { name = 'crates' } } + -- }) crates.show() end, } diff --git a/lua/custom/plugins/rust-tools.lua b/lua/custom/plugins/rust-tools.lua index b4bd4005..3ea57f5d 100644 --- a/lua/custom/plugins/rust-tools.lua +++ b/lua/custom/plugins/rust-tools.lua @@ -1,13 +1,11 @@ return { - { - "simrat39/rust-tools.nvim", - dependencies = { - 'neovim/nvim-lspconfig', - 'nvim-lua/plenary.nvim', - 'mfussenegger/nvim-dap', - }, - opts = function(_, _) - require("rust-tools").setup({}) - end, + "simrat39/rust-tools.nvim", + dependencies = { + 'neovim/nvim-lspconfig', + 'nvim-lua/plenary.nvim', + 'mfussenegger/nvim-dap', }, + -- config = function() + -- require("rust-tools").setup({}) + -- end, }