Remove LuaSnip, vsnip, cmp-vsnip, cmp_luasnip, and friendly-snippets. Remove snippet sources from cmp. Use Neovim's built-in vim.snippet.expand as a safety net for any LSP items that arrive as snippets despite snippetSupport=false in capabilities.
86 lines
2.9 KiB
Lua
86 lines
2.9 KiB
Lua
return {
|
|
-- [[ LSP Completion Source ]]
|
|
'hrsh7th/nvim-cmp', -- NVIM Completion Framework
|
|
dependencies = {
|
|
'hrsh7th/cmp-nvim-lsp',
|
|
'hrsh7th/cmp-nvim-lua', -- Lua Autocompletion
|
|
'hrsh7th/cmp-nvim-lsp-signature-help',
|
|
'hrsh7th/cmp-path', -- Completion for file system paths
|
|
'hrsh7th/cmp-buffer', -- Completion from current buffer
|
|
},
|
|
config = function()
|
|
local opt = vim.opt
|
|
|
|
opt.completeopt = {'menuone', 'noselect', 'noinsert',}
|
|
opt.shortmess = opt.shortmess + {c = true,}
|
|
vim.opt.updatetime = 50
|
|
|
|
-- local diag_float_grp = vim.api.nvim_create_augroup('DiagnosticFloat', {clear = true})
|
|
-- vim.api.nvim_create_autocmd('CursorHold', {
|
|
-- callback = function()
|
|
-- vim.diagnostic.open_float(nil, { focusable = false })
|
|
-- end,
|
|
-- group = diag_float_grp,
|
|
-- })
|
|
|
|
-- Completion Plugin Setup
|
|
local cmp = require('cmp')
|
|
|
|
cmp.setup({
|
|
preselect = cmp.PreselectMode.None,
|
|
|
|
-- Fallback snippet expand for LSP items that arrive as snippets despite
|
|
-- snippetSupport=false in capabilities. Uses Neovim 0.10+ built-in.
|
|
snippet = {
|
|
expand = function(args)
|
|
vim.snippet.expand(args.body)
|
|
end,
|
|
},
|
|
|
|
mapping = {
|
|
['<C-k>'] = cmp.mapping.select_prev_item(), -- Previous Suggestion
|
|
['<C-j>'] = cmp.mapping.select_next_item(), -- Next Suggestion
|
|
['<C-Space>'] = cmp.mapping.complete(), -- Show Completion Suggestions
|
|
['<C-e>'] = cmp.mapping.abort(), -- Close the window
|
|
['<CR>'] = cmp.mapping.confirm({
|
|
behavior = cmp.ConfirmBehavior.Insert,
|
|
select = false,
|
|
}),
|
|
},
|
|
|
|
-- Installed sources:
|
|
sources = {
|
|
{name = 'path',}, -- file paths
|
|
{name = 'nvim_lsp', keyword_length = 3,}, -- from language server
|
|
{name = 'nvim_lsp_signature_help',}, -- display function signatures with current parameter emphasized
|
|
{name = 'nvim_lua', keyword_length = 2,}, -- complete neovim's Lua runtime API such vim.lsp.*
|
|
{name = 'buffer', keyword_length = 2,}, -- source current buffer
|
|
},
|
|
|
|
window = {
|
|
completion = cmp.config.window.bordered(),
|
|
documentation = cmp.config.window.bordered(),
|
|
},
|
|
|
|
formatting = {
|
|
fields = {'menu', 'abbr', 'kind',},
|
|
format = function(entry, item)
|
|
local menu_icon = {
|
|
nvim_lsp = 'λ',
|
|
buffer = 'Ω',
|
|
path = '🖫',
|
|
}
|
|
item.menu = menu_icon[entry.source.name]
|
|
return item
|
|
end,
|
|
},
|
|
})
|
|
|
|
-- Apply per-filetype cmp source overrides from language modules
|
|
local languages = require('languages')
|
|
for ft, ft_config in pairs(languages.cmp_filetypes()) do
|
|
cmp.setup.filetype(ft, ft_config)
|
|
end
|
|
end,
|
|
}
|