forked from hrsh7th/nvim-cmp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmp.lua
111 lines (101 loc) · 2.99 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
if vim.g.loaded_cmp then
return
end
vim.g.loaded_cmp = true
local api = require('cmp.utils.api')
local misc = require('cmp.utils.misc')
local types = require('cmp.types')
local config = require('cmp.config')
local highlight = require('cmp.utils.highlight')
local emit = require('cmp.utils.autocmd').emit
local autocmds = require('cmp.autocmds')
misc.set(_G, { 'cmp', 'plugin', 'cmdline', 'leave' }, function()
if vim.fn.expand('<afile>') ~= '=' then
vim.cmd([[
augroup cmp-cmdline
autocmd!
augroup END
]])
emit('CmdlineLeave')
end
end)
misc.set(_G, { 'cmp', 'plugin', 'cmdline', 'enter' }, function()
if config.is_native_menu() then
return
end
if vim.fn.expand('<afile>') ~= '=' then
vim.schedule(function()
if api.is_cmdline_mode() then
autocmds.cmdline_mode()
emit('CmdlineEnter')
end
end)
end
end)
misc.set(_G, { 'cmp', 'plugin', 'colorscheme' }, function()
highlight.inherit('CmpItemAbbrDefault', 'Pmenu', {
guibg = 'NONE',
ctermbg = 'NONE',
})
highlight.inherit('CmpItemAbbrDeprecatedDefault', 'Comment', {
gui = 'NONE',
guibg = 'NONE',
ctermbg = 'NONE',
})
highlight.inherit('CmpItemAbbrMatchDefault', 'Pmenu', {
gui = 'NONE',
guibg = 'NONE',
ctermbg = 'NONE',
})
highlight.inherit('CmpItemAbbrMatchFuzzyDefault', 'Pmenu', {
gui = 'NONE',
guibg = 'NONE',
ctermbg = 'NONE',
})
highlight.inherit('CmpItemKindDefault', 'Special', {
guibg = 'NONE',
ctermbg = 'NONE',
})
highlight.inherit('CmpItemMenuDefault', 'Pmenu', {
guibg = 'NONE',
ctermbg = 'NONE',
})
for name in pairs(types.lsp.CompletionItemKind) do
if type(name) == 'string' then
vim.cmd(([[highlight default link CmpItemKind%sDefault CmpItemKind]]):format(name))
end
end
end)
_G.cmp.plugin.colorscheme()
vim.cmd([[
highlight default link CmpItemAbbr CmpItemAbbrDefault
highlight default link CmpItemAbbrDeprecated CmpItemAbbrDeprecatedDefault
highlight default link CmpItemAbbrMatch CmpItemAbbrMatchDefault
highlight default link CmpItemAbbrMatchFuzzy CmpItemAbbrMatchFuzzyDefault
highlight default link CmpItemKind CmpItemKindDefault
highlight default link CmpItemMenu CmpItemMenuDefault
]])
for name in pairs(types.lsp.CompletionItemKind) do
if type(name) == 'string' then
local hi = ('CmpItemKind%s'):format(name)
if vim.fn.hlexists(hi) ~= 1 then
vim.cmd(([[highlight default link %s %sDefault]]):format(hi, hi))
end
end
end
if vim.on_key then
vim.on_key(function(keys)
if keys == vim.api.nvim_replace_termcodes('<C-c>', true, true, true) then
vim.schedule(function()
if not api.is_suitable_mode() then
require('cmp.utils.autocmd').emit('InsertLeave')
end
end)
end
end, vim.api.nvim_create_namespace('cmp.plugin'))
end
vim.api.nvim_create_user_command('CmpStatus', function()
require('cmp').status()
end, { desc = 'Check status of cmp sources' })
vim.cmd([[doautocmd <nomodeline> User CmpReady]])
autocmds.autocmd()