neovim: breaking change in nvim-cmp config

nvim-cmp now uses floating window instead of pumsible.
See https://github.com/hrsh7th/nvim-cmp/issues/231
This commit is contained in:
Hoang Nguyen 2021-10-08 20:06:52 +07:00
parent 4508f2a819
commit c9941850a2
No known key found for this signature in database
GPG Key ID: 813CF484F4993419
3 changed files with 39 additions and 13 deletions

View File

@ -278,10 +278,35 @@ local function highlight_lsp()
hi('LspReferenceRead', c.fg, c.grey_bright, '', '') hi('LspReferenceRead', c.fg, c.grey_bright, '', '')
hi('LspReferenceWrite', c.fg, c.grey_bright, '', '') hi('LspReferenceWrite', c.fg, c.grey_bright, '', '')
vim.api.nvim_command('hi! link LspCodeLens Comment') vim.api.nvim_command('hi! link LspCodeLens Comment')
-- Theses are for neovim 0.6
vim.api.nvim_command('hi! link DiagnosticVirtualTextWarn LspDiagnosticsVirtualTextWarning')
vim.api.nvim_command('hi! link DiagnosticUnderlineWarn LspDiagnosticsUnderlineWarning')
vim.api.nvim_command('hi! link DiagnosticFloatingWarn LspDiagnosticsFloatingWarning')
vim.api.nvim_command('hi! link DiagnosticSignWarn LspDiagnosticsSignWarning')
vim.api.nvim_command('hi! link DiagnosticVirtualTextError LspDiagnosticsVirtualTextError')
vim.api.nvim_command('hi! link DiagnosticUnderlineError LspDiagnosticsUnderlineError')
vim.api.nvim_command('hi! link DiagnosticFloatingError LspDiagnosticsFloatingError')
vim.api.nvim_command('hi! link DiagnosticSignError LspDiagnosticsSignError')
vim.api.nvim_command('hi! link DiagnosticVirtualTextInfo LspDiagnosticsVirtualTextInformation')
vim.api.nvim_command('hi! link DiagnosticUnderlineInfo LspDiagnosticsUnderlineInformation')
vim.api.nvim_command('hi! link DiagnosticFloatingInfo LspDiagnosticsFloatingInformation')
vim.api.nvim_command('hi! link DiagnosticSignInfo LspDiagnosticsSignInformation')
vim.api.nvim_command('hi! link DiagnosticVirtualTextHint LspDiagnosticsVirtualTextHint')
vim.api.nvim_command('hi! link DiagnosticUnderlineHint LspDiagnosticsUnderlineHint')
vim.api.nvim_command('hi! link DiagnosticFloatingHint LspDiagnosticsFloatingHint')
vim.api.nvim_command('hi! link DiagnosticSignHint LspDiagnosticsSignHint')
end end
-- Specify groups for plugins -- Specify groups for plugins
local function highlight_plugins() local function highlight_plugins()
-- nvim-cmp (experimental custom menu)
hi('CmpItemAbbr', c.fg, '', '', '')
hi('CmpItemAbbrMatch', c.yellow, '', '', '')
hi('CmpItemAbbrMatchFuzzy', c.yellow, '', '', '')
hi('CmpItemKind', c.fg, '', '', '')
hi('CmpItemMenu', c.fg, '', '', '')
-- Gitsigns -- Gitsigns
hi('GitSignsAddNr' , c.green , '', '', '') hi('GitSignsAddNr' , c.green , '', '', '')
hi('GitSignsChangeNr', c.yellow, '', '', '') hi('GitSignsChangeNr', c.yellow, '', '', '')

View File

@ -5,11 +5,12 @@ function M.cmp_conf()
local luasnip = require('luasnip') local luasnip = require('luasnip')
local has_words_before = function() local has_words_before = function()
local cursor = vim.api.nvim_win_get_cursor(0) local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return not vim.api.nvim_get_current_line():sub(1, cursor[2]):match('^%s$') return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil
end end
cmp.setup { cmp.setup {
experimental = {custom_menu = true}, -- Use custom highlightng for the floating completion menu
formatting = { formatting = {
format = function(entry, vim_item) format = function(entry, vim_item)
local lspkind_icons = { local lspkind_icons = {
@ -72,33 +73,35 @@ function M.cmp_conf()
-- Change choice nodes for luasnip -- Change choice nodes for luasnip
['<C-h>'] = cmp.mapping(function(fallback) ['<C-h>'] = cmp.mapping(function(fallback)
if luasnip.choice_active() then if luasnip.choice_active() then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-prev-choice', true, true, true), '', true) luasnip.change_choice(-1)
else else
fallback() fallback()
end end
end, {'i', 's'}), end, {'i', 's'}),
['<C-l>'] = cmp.mapping(function(fallback) ['<C-l>'] = cmp.mapping(function(fallback)
if luasnip.choice_active() then if luasnip.choice_active() then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-next-choice', true, true, true), '', true) luasnip.change_choice(1)
else else
fallback() fallback()
end end
end, {'i', 's'}), end, {'i', 's'}),
-- supertab-like mapping -- supertab-like mapping
['<Tab>'] = cmp.mapping(function(fallback) ['<Tab>'] = cmp.mapping(function(fallback)
if vim.fn.pumvisible() == 1 then if cmp.visible() then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n', true) cmp.select_next_item()
elseif has_words_before() and luasnip.expand_or_jumpable() then elseif luasnip.expand_or_jumpable() then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '', true) luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else else
fallback() fallback()
end end
end, {'i', 's'}), end, {'i', 's'}),
['<S-Tab>'] = cmp.mapping(function(fallback) ['<S-Tab>'] = cmp.mapping(function(fallback)
if vim.fn.pumvisible() == 1 then if cmp.visible() then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<C-p>', true, true, true), 'n', true) cmp.select_prev_item()
elseif luasnip.jumpable(-1) then elseif luasnip.jumpable(-1) then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-jump-prev', true, true, true), '', true) luasnip.jump(-1)
else else
fallback() fallback()
end end

View File

@ -1,7 +1,5 @@
#!/bin/sh #!/bin/sh
# TODO: consider forking 'kabouzeid/nvim-lspinstall' or 'anott03/nvim-lspinstall'
# instead of running scripts
if [ "$#" -ne 1 ]; then if [ "$#" -ne 1 ]; then
echo "Usage:" echo "Usage:"
printf " - %s server_name: install specified server\n" "$0" printf " - %s server_name: install specified server\n" "$0"