From 920f98ca75495afac6c7f23312a4a6c33b8679d1 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Fri, 24 Jun 2022 12:41:32 +0200 Subject: [PATCH] feat(nvim): enable rust lsp support --- home-mandlm.nix | 3 +++ nvim/lua/plugins/lspconfig.lua | 24 +++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/home-mandlm.nix b/home-mandlm.nix index 291b581..eaf1c95 100644 --- a/home-mandlm.nix +++ b/home-mandlm.nix @@ -32,6 +32,7 @@ terraform-ls tflint nodePackages.bash-language-server + rust-analyzer ]; stateVersion = "22.05"; @@ -143,6 +144,7 @@ # LSP nvim-lspconfig lsp-status-nvim + rust-tools-nvim ]; extraConfig = '' @@ -150,6 +152,7 @@ ${builtins.readFile ./nvim/lua/keymaps.lua } ${builtins.readFile ./nvim/lua/options.lua } ${builtins.readFile ./nvim/lua/plugins/treesitter.lua } + ${builtins.readFile ./nvim/lua/plugins/lspconfig.lua } require("toggleterm").setup({ size = 32, open_mapping = [[]] }) diff --git a/nvim/lua/plugins/lspconfig.lua b/nvim/lua/plugins/lspconfig.lua index 5b459b0..e72cda9 100644 --- a/nvim/lua/plugins/lspconfig.lua +++ b/nvim/lua/plugins/lspconfig.lua @@ -27,7 +27,7 @@ local on_attach = function(client, bufnr) group = augroup, buffer = bufnr, callback = function() - vim.lsp.buf.formatting_sync() + vim.lsp.buf.formatting_sync({}, 3000) end, }) end @@ -63,10 +63,28 @@ local servers = { local lspconfig = require("lspconfig") -for lsp, config in pairs(servers) do +for lsp, settings in pairs(servers) do lspconfig[lsp].setup({ - settings = config or {}, + settings = settings, on_attach = on_attach, capabilities = capabilities, }) end + +require("rust-tools").setup({ + server = { + on_attach = on_attach, + settings = { + ["rust-analyzer"] = { + cargo = { + loadOutDirsFromCheck = true, + }, + checkOnSave = { command = "clippy" }, + procMacro = { + enable = true, + }, + }, + }, + capabilities = capabilities, + }, +})