From 8df1e359a5cf9487052d2f21739a29978b5cc172 Mon Sep 17 00:00:00 2001 From: Evie Litherland-Smith Date: Tue, 31 Jan 2023 13:42:24 +0000 Subject: [PATCH] Clean up and extend LSP Move nvim-cmp set up to own file, LSP file was getting unmanageable Add more cmp/lsp plugins to improve capabilities Switch python LSP back to using pyright Remove legacy neovide stuff --- config/nvim/init.lua | 5 - config/nvim/lua/config_plugins/config_cmp.lua | 75 ++++++++++++++ config/nvim/lua/config_plugins/config_lsp.lua | 97 +------------------ config/nvim/lua/plugins.lua | 23 ++--- 4 files changed, 92 insertions(+), 108 deletions(-) create mode 100644 config/nvim/lua/config_plugins/config_cmp.lua diff --git a/config/nvim/init.lua b/config/nvim/init.lua index 72a4347b..2ba022a2 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -9,8 +9,3 @@ require 'keymaps' -- Remaining vim commands to be converted to lua require 'vimcommands' - --- Neovide specific config, only used if Neovide is runnning -if vim.g.neovide then - require 'neovide' -end diff --git a/config/nvim/lua/config_plugins/config_cmp.lua b/config/nvim/lua/config_plugins/config_cmp.lua new file mode 100644 index 00000000..0f03f9f2 --- /dev/null +++ b/config/nvim/lua/config_plugins/config_cmp.lua @@ -0,0 +1,75 @@ +local cmp = require 'cmp' +local luasnip = require 'luasnip' + +require('luasnip.loaders.from_vscode').lazy_load() + +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) -- For `luasnip` users. + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), -- Up + [''] = cmp.mapping.scroll_docs(4), -- Down + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), + }), + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'latex_symbols' }, + } +}) + +-- Set configuration for specific filetype. +cmp.setup.filetype('gitcommit', { + sources = { + { name = 'git' }, + { name = 'commit' }, + { name = 'buffer' }, + } +}) + +cmp.setup.filetype('markdown', { + sources = { + { name = 'spell' }, + { name = 'buffer' }, + }, +}) + +cmp.setup.cmdline('/', { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } +}) + +cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'path' }, + { name = 'cmdline' } + } +}) diff --git a/config/nvim/lua/config_plugins/config_lsp.lua b/config/nvim/lua/config_plugins/config_lsp.lua index 40f95bed..ccfb58c7 100644 --- a/config/nvim/lua/config_plugins/config_lsp.lua +++ b/config/nvim/lua/config_plugins/config_lsp.lua @@ -15,9 +15,6 @@ end -- 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 local bufopts = { noremap = true, silent = true, buffer = bufnr } @@ -37,18 +34,9 @@ local on_attach = function(client, bufnr) vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) - -- Keep support for deprecated syntax in vim <= 7 - if vim.version().minor <= 7 then - vim.keymap.set('n', 'i', function() - vim.lsp.buf.formatting() - end, bufopts) - else - vim.keymap.set('n', 'i', function() - vim.lsp.buf.format({ timeout_ms = 10000, async = false }) - end, bufopts) - end - -- Enable aerial support - require("aerial").on_attach(client, bufnr) + vim.keymap.set('n', 'i', function() + vim.lsp.buf.format({ timeout_ms = 10000, async = false }) + end, bufopts) end local lsp_flags = { @@ -56,87 +44,12 @@ local lsp_flags = { debounce_text_changes = 150, } --- Setup nvim-cmp. -local cmp = require 'cmp' +local capabilities = require('cmp_nvim_lsp').default_capabilities() -cmp.setup({ - snippet = { - -- REQUIRED - you must specify a snippet engine - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. - -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - -- require('snippy').expand_snippet(args.body) -- For `snippy` users. - -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. - end, - }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - }), - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'vsnip' }, -- For vsnip users. - -- { name = 'luasnip' }, -- For luasnip users. - -- { name = 'ultisnips' }, -- For ultisnips users. - -- { name = 'snippy' }, -- For snippy users. - }, { - { name = 'buffer' }, - }) -}) - --- Set configuration for specific filetype. -cmp.setup.filetype('gitcommit', { - sources = cmp.config.sources({ - { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. - }, { - { name = 'buffer' }, - }) -}) - --- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). -cmp.setup.cmdline('/', { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = 'buffer' } - } -}) - --- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). -cmp.setup.cmdline(':', { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = 'path' } - }, { - { name = 'cmdline' } - }) -}) - --- Setup lspconfig. -local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) - -require('lspconfig')['pylsp'].setup { +require('lspconfig')['pyright'].setup{ on_attach = on_attach, flags = lsp_flags, capabilities = capabilities, - settings = { - pylsp = { - plugins = { - pycodestyle = { - maxLineLength = 88 - }, - mypy = { - report_progress = true, - }, - }, - }, - }, } require('lspconfig')['fortls'].setup { diff --git a/config/nvim/lua/plugins.lua b/config/nvim/lua/plugins.lua index d912a18d..77987e70 100644 --- a/config/nvim/lua/plugins.lua +++ b/config/nvim/lua/plugins.lua @@ -25,22 +25,22 @@ require('packer').startup { } use 'kyazdani42/nvim-web-devicons' use 'nvim-lua/plenary.nvim' - use { - 'neovim/nvim-lspconfig', - config = function() - require 'config_plugins.config_lsp' - end, - } use 'christoomey/vim-tmux-navigator' use { + 'neovim/nvim-lspconfig', + 'hrsh7th/nvim-cmp', 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', 'hrsh7th/cmp-cmdline', - 'hrsh7th/cmp-nvim-lua', - 'hrsh7th/nvim-cmp', - 'hrsh7th/cmp-vsnip', - 'hrsh7th/vim-vsnip', + 'f3fora/cmp-spell', + 'petertriho/cmp-git', + 'Dosx001/cmp-commit', + 'kdheepak/cmp-latex-symbols', + 'L3MON4D3/LuaSnip', + 'saadparwaiz1/cmp_luasnip', + 'rafamadriz/friendly-snippets', + 'windwp/nvim-autopairs', } use { 'nvim-treesitter/nvim-treesitter', @@ -56,7 +56,6 @@ require('packer').startup { } use { 'stevearc/aerial.nvim', - branch = 'nvim-0.5', config = function() require 'config_plugins.config_aerial' end @@ -147,3 +146,5 @@ require('packer').startup { }, } } +require 'config_plugins.config_lsp' +require 'config_plugins.config_cmp'