Skip to content

Commit 9c0abcc

Browse files
nvim: refactored completion support
1 parent 1031e8c commit 9c0abcc

2 files changed

Lines changed: 70 additions & 55 deletions

File tree

.config/cvim/init/init.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ elseif g:vimDistribution ==# g:VIM_FLAVOR_NEOVIM
240240
\ 'hrsh7th/cmp-buffer':{'lazy': 1},
241241
\ 'hrsh7th/cmp-path':{'lazy': 1},
242242
\ 'hrsh7th/cmp-cmdline':{'lazy': 1},
243+
\ 'hrsh7th/cmp-nvim-lsp-signature-help':{'lazy': 1},
243244
\ 'rasulomaroff/cmp-bufname':{'lazy': 1},
244245
\ 'amarakon/nvim-cmp-buffer-lines':{'lazy': 1},
245246
\ 'hrsh7th/cmp-calc':{'lazy': 1},
@@ -269,6 +270,11 @@ elseif g:vimDistribution ==# g:VIM_FLAVOR_NEOVIM
269270
\ 'name': 'hrsh7th/cmp-cmdline',
270271
\ 'lazy': 1,
271272
\ }
273+
" Auto completion source: function signature
274+
let cvim_plugins.nvim_cmp_lsp_signature_help = {
275+
\ 'name': 'hrsh7th/cmp-nvim-lsp-signature-help',
276+
\ 'lazy': 1,
277+
\ }
272278
" Auto completion source: vim's buffer name
273279
let cvim_plugins.nvim_cmp_bufname = {
274280
\ 'name': 'rasulomaroff/cmp-bufname',

.config/cvim/settings/nvim_nvim-cmp.lua

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,75 @@ local function config()
55
-- For a list of support completion plugins,
66
-- see https://github.com/hrsh7th/nvim-cmp/wiki/List-of-sources
77
local cmp = require('cmp')
8-
cmp.setup({
9-
sources = {
10-
{ name = 'nvim_lsp', keyword_length = 1 },
11-
{ name = 'buffer'},
12-
{ name = 'path'},
13-
{ name = 'bufname'},
14-
{ name = 'buffer-lines', option = {
15-
leading_whitespace = true
16-
}},
17-
{ name = 'calc'},
18-
{ name = 'rpncalc'},
19-
{ name = 'dictionary', keyword_length = 2},
20-
{ name = 'omni', option = {
21-
disable_omnifuncs = {'v:lua.vim.lsp.omnifunc'}
22-
}},
23-
{ name = 'spell', option = {
24-
keep_all_entries = false,
25-
enable_in_context = function()
26-
return true
27-
end,
28-
preselect_correc_word = true
29-
}}
8+
cmp.setup(
9+
{
10+
sources = {
11+
{ name = 'nvim_lsp', keyword_length = 1 },
12+
{ name = 'buffer'},
13+
{ name = 'path'},
14+
{ name = 'bufname'},
15+
{ name = 'buffer-lines', option = {
16+
leading_whitespace = true
17+
}},
18+
{ name = 'nvim_lsp_signature_help'},
19+
{ name = 'calc'},
20+
{ name = 'rpncalc'},
21+
{ name = 'dictionary', keyword_length = 2},
22+
{ name = 'omni', option = {
23+
disable_omnifuncs = {'v:lua.vim.lsp.omnifunc'}
24+
}},
25+
{ name = 'spell', option = {
26+
keep_all_entries = false,
27+
enable_in_context = function()
28+
return true
29+
end,
30+
preselect_correc_word = true
31+
}}
32+
}
3033
}
31-
})
32-
-- setup completion for '/' search
33-
cmp.setup.cmdline('/', {
34-
mapping = cmp.mapping.preset.cmdline(),
35-
sources = {
36-
-- cmp-cmdline offers completion based on current buffer
37-
{ name = 'buffer' }
38-
}
39-
})
40-
-- setup completion for command mode
41-
cmp.setup.cmdline(':', {
42-
mapping = cmp.mapping.preset.cmdline(),
43-
sources = cmp.config.sources(
34+
)
35+
-- setup completion for '/' and '?' search
36+
cmp.setup.cmdline(
37+
{ '/', '?' },
4438
{
45-
-- cmp-cmdline offers completion based on paths
46-
{ name = 'path' }
47-
},
39+
mapping = cmp.mapping.preset.cmdline(),
40+
sources = cmp.config.sources(
41+
{
42+
-- offers completion based on current buffer's words
43+
{
44+
name = 'buffer',
45+
option = { keyword_pattern = [[\k\+]] } -- recognize words
46+
}
47+
},
48+
{
49+
-- offers completion based on current buffer's lines unless words source is available
50+
{
51+
name = "buffer-lines"
52+
}
53+
}
54+
)
55+
}
56+
)
57+
-- setup completion for command mode
58+
cmp.setup.cmdline(
59+
{':'},
4860
{
49-
{
50-
name = 'cmdline',
51-
option = {
52-
ignore_cmds = { 'Man', '!' }
61+
mapping = cmp.mapping.preset.cmdline(),
62+
sources = {
63+
-- offers completion based on paths
64+
{
65+
name = 'path'
66+
},
67+
-- offers completion based on cmdline
68+
{
69+
name = 'cmdline',
70+
option = {
71+
ignore_cmds = { 'Man', '!' }
72+
}
73+
}
5374
}
54-
}
55-
})
56-
})
57-
-- setup completion for / and ? in the command line
58-
cmp.setup.cmdline({ "/", "?" }, {
59-
mapping = cmp.mapping.preset.cmdline(),
60-
sources = {
61-
{
62-
name = "buffer",
63-
option = { keyword_pattern = [[\k\+]] }
64-
},
65-
{ name = "buffer-lines" }
6675
}
67-
})
76+
)
6877
-- View cmp sources status with :CmpStatus
6978
end
7079

0 commit comments

Comments
 (0)