Bläddra i källkod

nixpkgs/neovim: switch to nvim-cmp for completion

Thomas Dy 1 år sedan
förälder
incheckning
4dd1afd4d6

+ 7 - 0
.config/nixpkgs/neovim/lsp.lua

@@ -3,6 +3,8 @@ vim.diagnostic.config({
   virtual_text = { severity = { min = vim.diagnostic.severity.WARN } },
 })
 
+local capabilities = require('cmp_nvim_lsp').default_capabilities()
+
 local nvim_lsp = require('lspconfig')
 local null_ls = require('null-ls')
 
@@ -42,6 +44,7 @@ end
 
 if vim.fn.executable("deno") == 1 then
   nvim_lsp.denols.setup({
+    capabilities = capabilities,
     on_attach = on_attach,
   });
 else
@@ -50,6 +53,7 @@ else
       init_options = {
         completionDisableFilterText = true,
       },
+      capabilities = capabilities,
       flags = {
         debounce_text_changes = 150,
       },
@@ -72,6 +76,7 @@ end
 
 if vim.fn.executable("gopls") == 1 then
   nvim_lsp.gopls.setup({
+    capabilities = capabilities,
     on_attach = on_attach,
   });
 elseif vim.fn.executable("gofmt") == 1 then
@@ -80,6 +85,7 @@ end
 
 if vim.fn.executable("solargraph") == 1 then
   nvim_lsp.solargraph.setup({
+    capabilities = capabilities,
     on_attach = on_attach,
     init_options = {
       formatting = false,
@@ -130,6 +136,7 @@ if not configs.elvish then
 end
 
 nvim_lsp.elvish.setup({
+  capabilities = capabilities,
   on_attach = on_attach,
 })
 

+ 1 - 6
.config/nixpkgs/neovim/mappings.lua

@@ -13,9 +13,6 @@ vim.keymap.set({'n', 'v'}, 'k', 'gk', opts)
 -- leave insert mode with <ESC><ESC>
 vim.keymap.set('t', '<ESC><ESC>', '<C-\\><C-N>', opts)
 
--- allow pressing enter to autocomplete
-vim.keymap.set('i', '<CR>', 'pumvisible() ? "\\<C-y>" : "\\<CR>"', { expr = true })
-
 -- select pasted text
 vim.keymap.set('n', 'gp', '`[v`]', opts)
 
@@ -78,15 +75,13 @@ vim.keymap.set('n', '<space>q', '<cmd>lua vim.diagnostic.setqflist({ severity =
 
 function on_attach(client, bufnr)
   local opts = { silent = true, buffer = bufnr }
-  -- Enable completion triggered by <c-x><c-o>
-  vim.bo.omnifunc = 'v:lua.MiniCompletion.completefunc_lsp'
 
   -- LSP-specific mappings
   vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
   vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
   vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
   vim.keymap.set('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
-  vim.keymap.set('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
+  vim.keymap.set({'n', 'i'}, '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
   vim.keymap.set('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
   vim.keymap.set('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
   vim.keymap.set('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)

+ 24 - 27
.config/nixpkgs/neovim/plugins.lua

@@ -91,33 +91,6 @@ require('mini.comment').setup()
 -- surround actions
 require('mini.surround').setup()
 
--- LSP completion and function signature display
-require('mini.completion').setup({
-  delay = {
-    -- disable autocomplete
-    completion = 100000000,
-    info = 100,
-    signature = 50,
-  },
-  lsp_completion = {
-    source_func = 'omnifunc',
-    auto_setup = false,
-
-    -- workaround from https://github.com/echasnovski/mini.nvim/issues/306#issuecomment-1517954136
-    process_items = function(items, base)
-      -- Remove dots as prefix from `textEdit.newText` as it is used verbatim
-      for _, item in ipairs(items) do
-        local new_text = (item.textEdit or {}).newText
-        if type(new_text) == 'string' then
-          item.textEdit.newText = new_text:gsub('^%.+', '')
-        end
-      end
-
-      return MiniCompletion.default_process_items(items, base)
-    end,
-  },
-});
-
 local spec_treesitter = require('mini.ai').gen_spec.treesitter
 
 require('mini.ai').setup({
@@ -201,5 +174,29 @@ require('treesj').setup({
   },
 })
 
+-- completion
+local cmp = require('cmp')
+cmp.setup({
+  snippet = {
+    expand = function(args)
+      vim.fn['vsnip#anonymous'](args.body)
+    end,
+  },
+  mapping = cmp.mapping.preset.insert({
+    ['<C-b>'] = cmp.mapping.scroll_docs(-4),
+    ['<C-f>'] = cmp.mapping.scroll_docs(4),
+    ['<C-Space>'] = cmp.mapping.complete(),
+    ['<C-e>'] = cmp.mapping.abort(),
+    ['<CR>'] = 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" },
+  }),
+  completion = {
+    autocomplete = false,
+  },
+})
+
 -- typescript-vim compiler options
 vim.g.typescript_compiler_options = '--incremental --noEmit'

+ 16 - 0
.config/nixpkgs/neovim/plugins/sources.json

@@ -78,5 +78,21 @@
   "rest-nvim/rest.nvim": {
     "rev": "c21eed6cbbc76e120a31b8eafa8f77c338bcbce7",
     "sha256": "1zyzl2fyaxwn7w037yy01xg4lnqb3x65bnjwd9krwpwdq6bm9gs1"
+  },
+  "hrsh7th/cmp-nvim-lsp": {
+    "rev": "0e6b2ed705ddcff9738ec4ea838141654f12eeef",
+    "sha256": "0gpwwc3rhfckaava83hpl7pw4rspicblxs7hy3y57gb560ymq6hg"
+  },
+  "hrsh7th/nvim-cmp": {
+    "rev": "8a1694ff330ed58ed29716686fcef79c28090354",
+    "sha256": "00zxvwc244njvkbwbvxffrcqam37xi93r0pvcvzin4kc9npaygaq"
+  },
+  "hrsh7th/cmp-vsnip": {
+    "rev": "989a8a73c44e926199bfd05fa7a516d51f2d2752",
+    "sha256": "1hs1gv7q0vfn82pwdwpy46nsi4n5z6yljnzl0rpvwfp8g79hssfs"
+  },
+  "hrsh7th/vim-vsnip": {
+    "rev": "7753ba9c10429c29d25abfd11b4c60b76718c438",
+    "sha256": "1l8myq6c5rckk6jr3s5rx9jpnrgzk1a65yky1b28mvayd6yff4vs"
   }
 }