-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmp.lua
132 lines (122 loc) · 3.68 KB
/
cmp.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
vim.g.vsnip_filetypes = {
typescript = { 'javascript' },
typescriptreact = { 'javascript' },
text = { 'license' },
}
local config = function()
local cmp = require('cmp')
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
local cmp_context = require('cmp.config.context')
local lspkind = require('lspkind')
local cmp_window_bordered = cmp.config.window.bordered()
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done())
cmp.setup({
snippet = {
expand = function(args)
vim.fn['vsnip#anonymous'](args.body)
end,
},
window = {
completion = cmp_window_bordered,
documentation = cmp_window_bordered,
},
mapping = cmp.mapping.preset.insert({
['<Tab>'] = cmp.mapping(function(fallback)
if vim.fn['vsnip#jumpable'](1) == 1 then
feedkey('<Plug>(vsnip-jump-next)', '')
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if vim.fn['vsnip#jumpable'](-1) == 1 then
feedkey('<Plug>(vsnip-jump-prev)', '')
else
fallback()
end
end, { 'i', 's' }),
['<C-j>'] = cmp.mapping(cmp.mapping.select_next_item()),
['<C-k>'] = cmp.mapping(cmp.mapping.select_prev_item()),
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-s>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
['<C-n>'] = cmp.config.disable,
['<C-p>'] = cmp.config.disable,
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'vsnip' },
{ name = 'nvim_lsp_signature_help' },
{ name = 'path' },
{ name = 'buffer' },
}),
formatting = {
format = lspkind.cmp_format({
mode = 'symbol_text',
maxwidth = 50,
}),
},
enabled = function()
-- disable completion in comments
-- See https://github.com/hrsh7th/nvim-cmp/pull/676#issuecomment-1002532096
if cmp_context.in_treesitter_capture('comment') == true or cmp_context.in_syntax_group('Comment') then
return false
else
return true
end
end,
})
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' },
},
})
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' },
{ name = 'cmdline' },
}),
})
end
return {
'hrsh7th/nvim-cmp',
dependencies = {
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-cmdline',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-nvim-lsp-signature-help',
'hrsh7th/cmp-path',
'onsails/lspkind.nvim',
'hrsh7th/cmp-vsnip',
'rafamadriz/friendly-snippets',
'hrsh7th/vim-vsnip',
{
-- TODO: move to its own file
'windwp/nvim-autopairs',
event = 'InsertEnter',
config = function()
local Rule = require('nvim-autopairs.rule')
local npairs = require('nvim-autopairs')
npairs.setup({})
npairs.add_rules({
Rule('<% ', ' %>', { 'ejs', 'hygen' }):set_end_pair_length(3),
Rule('<%=', ' %>', { 'ejs', 'hygen' }):set_end_pair_length(3),
Rule('<%-', ' %>', { 'ejs', 'hygen' }):set_end_pair_length(3),
Rule('<%#', ' %>', { 'ejs', 'hygen' }):set_end_pair_length(3),
})
npairs.add_rules({
Rule('{/*', ' */', { 'markdown.mdx' }),
})
end,
},
},
event = 'VeryLazy',
config = config,
}