From 6ac0abba1235a94c17ba8e4c71fa9534648f42d2 Mon Sep 17 00:00:00 2001 From: Gabe Venberg Date: Wed, 19 Jan 2022 00:17:58 -0600 Subject: [PATCH] improved rust LSP --- neovim/.config/nvim/lua/LSPconfig.lua | 35 ++++++++++++++++++++++++++- neovim/.config/nvim/lua/cmp-lsp.lua | 2 +- neovim/.config/nvim/lua/packages.lua | 8 ++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/neovim/.config/nvim/lua/LSPconfig.lua b/neovim/.config/nvim/lua/LSPconfig.lua index 1671633..0a1a367 100644 --- a/neovim/.config/nvim/lua/LSPconfig.lua +++ b/neovim/.config/nvim/lua/LSPconfig.lua @@ -35,7 +35,7 @@ end -- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches -- the packages for these servers are: pyright, rust-analyzer, texlab, and lua-language-server -local servers = { 'pyright', 'rust_analyzer', 'texlab'} +local servers = { 'pyright', 'texlab'} for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup { flags = { @@ -44,6 +44,39 @@ for _, lsp in ipairs(servers) do } end +--rust configuration +local rustOpts = { + tools = { -- rust-tools options + autoSetHints = true, + hover_with_actions = true, + inlay_hints = { + show_parameter_hints = false, + parameter_hints_prefix = "", + other_hints_prefix = "", + }, + }, + + -- all the opts to send to nvim-lspconfig + -- these override the defaults set by rust-tools.nvim + -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer + server = { + -- on_attach is a callback called when the language server attachs to the buffer + -- on_attach = on_attach, + settings = { + -- to enable rust-analyzer settings visit: + -- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc + ["rust-analyzer"] = { + -- enable clippy on save + checkOnSave = { + command = "clippy" + }, + } + } + }, +} + +require('rust-tools').setup(rustOpts) + --lua-language-server needs seperate config. local runtime_path = vim.split(package.path, ';') table.insert(runtime_path, "lua/?.lua") diff --git a/neovim/.config/nvim/lua/cmp-lsp.lua b/neovim/.config/nvim/lua/cmp-lsp.lua index f9cf4be..3bd78b7 100644 --- a/neovim/.config/nvim/lua/cmp-lsp.lua +++ b/neovim/.config/nvim/lua/cmp-lsp.lua @@ -19,7 +19,7 @@ for _, lsp in ipairs(servers) do end -- Set completeopt to have a better completion experience -vim.o.completeopt = 'menuone,noselect' +vim.o.completeopt='menu,menuone,preview,noinsert' -- nvim-cmp setup local cmp = require 'cmp' diff --git a/neovim/.config/nvim/lua/packages.lua b/neovim/.config/nvim/lua/packages.lua index cfbbee4..76a94eb 100644 --- a/neovim/.config/nvim/lua/packages.lua +++ b/neovim/.config/nvim/lua/packages.lua @@ -17,6 +17,8 @@ return require('packer').startup(function(use) use 'yamatsum/nvim-cursorline' + use 'simrat39/rust-tools.nvim' + use {'stevearc/dressing.nvim', config=function() require('dressing').setup{} @@ -86,6 +88,12 @@ return require('packer').startup(function(use) end } + use {'glepnir/lspsaga.nvim', + requires = { + 'neovim/nvim-lspconfig', + } + } + use {'hrsh7th/nvim-cmp', requires = { 'neovim/nvim-lspconfig',