diff --git a/.vimrc b/.vimrc index 3e156f6..b00870d 100644 --- a/.vimrc +++ b/.vimrc @@ -94,7 +94,13 @@ Plug 'matze/vim-tex-fold' " rust-lsp configuration Plug 'neovim/nvim-lspconfig' -"Plug 'simrat39/rust-tools.nvim' +Plug 'hrsh7th/nvim-cmp' " completion framework +Plug 'hrsh7th/cmp-nvim-lsp' " LSP completion source for nvim-cmp +Plug 'hrsh7th/cmp-vsnip' " snippet completion source for nvim-cmp +Plug 'hrsh7th/cmp-path' " other usefull completion sources +Plug 'hrsh7th/cmp-buffer' +Plug 'simrat39/rust-tools.nvim' +Plug 'hrsh7th/vim-vsnip' " snippet engine " Plug 'nvim-lua/lsp_extensions.nvim' " File tree @@ -117,52 +123,6 @@ lua require('feline').setup({components = require('catppuccin.core.integrations. lua require('gitsigns').setup() lua require('spellsitter').setup() -" LSP config -lua << EOF --- Mappings. --- See `:help vim.diagnostic.*` for documentation on any of the below functions -local opts = { noremap=true, silent=true } - --- Use an on_attach function to only map the following keys --- after the language server attaches to the current buffer -local on_attach = function(client, bufnr) - -- Enable completion triggered by - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - - -- Mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'f', 'lua vim.lsp.buf.formatting()', opts) -end - --- Use a loop to conveniently call 'setup' on multiple servers and --- map buffer local keybindings when the language server attaches -local servers = { 'pylsp', 'rust_analyzer', 'asm_lsp', 'gdscript' } -for _, lsp in pairs(servers) do - require('lspconfig')[lsp].setup { - on_attach = on_attach, - flags = { - -- This will be the default in neovim 0.7+ - debounce_text_changes = 150, - } - } -end -require('lspconfig').arduino_language_server.setup({ - cmd = { - -- Required - "arduino-language-server", - "-cli-config", "/home/erin/.arduino15/arduino-cli.yaml", - -- Optional - "-cli", "/usr/bin/arduino-cli", - "-clangd", "/usr/bin/clangd" - } -}) -EOF - " Default value is clap let g:dashboard_default_executive ='fzf' let g:dashboard_custom_header=[ @@ -234,6 +194,8 @@ require'nvim-treesitter.configs'.setup { } EOF +" Rust LSP setup based on https://sharksforarms.dev/posts/neovim-rust/ + " Set completeopt to have a better completion experience " :help completeopt " menuone: popup even when there's only one match @@ -243,3 +205,103 @@ set completeopt=menuone,noinsert,noselect " Avoid showing extra messages when using completion set shortmess+=c + + +" Configure LSP through rust-tools.nvim plugin. +" rust-tools will configure and enable certain LSP features for us. +" See https://github.com/simrat39/rust-tools.nvim#configuration +lua <'] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + -- Add tab support + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }) + }, + + -- Installed sources + sources = { + { name = 'nvim_lsp' }, + { name = 'vsnip' }, + { name = 'path' }, + { name = 'buffer' }, + }, +}) +EOF + +" Code navigation shortcuts +nnoremap lua vim.lsp.buf.definition() +nnoremap K lua vim.lsp.buf.hover() +nnoremap gD lua vim.lsp.buf.implementation() +nnoremap lua vim.lsp.buf.signature_help() +nnoremap 1gD lua vim.lsp.buf.type_definition() +nnoremap gr lua vim.lsp.buf.references() +nnoremap g0 lua vim.lsp.buf.document_symbol() +nnoremap gW lua vim.lsp.buf.workspace_symbol() +nnoremap gd lua vim.lsp.buf.definition()