@@ -2,15 +2,18 @@ local cmp = {}
2
2
3
3
--- @param opts CmpConfig
4
4
cmp .setup = function (opts )
5
- require (' blink.cmp.config' ).merge_with (opts )
5
+ local config = require (' blink.cmp.config' )
6
+ config .merge_with (opts )
7
+
8
+ require (' blink.cmp.keymap' ).setup (config .keymap )
6
9
7
10
cmp .add_default_highlights ()
8
11
vim .api .nvim_create_autocmd (' ColorScheme' , { callback = cmp .add_default_highlights })
9
12
13
+ -- STRUCTURE
10
14
-- trigger -> sources -> fuzzy (filter/sort) -> windows (render)
11
- --
12
- -- trigger controls when to show the window and the current context
13
- -- for caching
15
+
16
+ -- trigger controls when to show the window and the current context for caching
14
17
cmp .trigger = require (' blink.cmp.trigger' ).activate_autocmds ()
15
18
16
19
-- sources fetch autocomplete items and documentation
@@ -28,11 +31,7 @@ cmp.setup = function(opts)
28
31
cmp .fuzzy = require (' blink.cmp.fuzzy' )
29
32
cmp .fuzzy .init_db (vim .fn .stdpath (' data' ) .. ' /blink/cmp/fuzzy.db' )
30
33
31
- local start_time = vim .loop .hrtime ()
32
- cmp .trigger .listen_on_show (function (context )
33
- start_time = vim .loop .hrtime ()
34
- cmp .sources .completions (context )
35
- end )
34
+ cmp .trigger .listen_on_show (function (context ) cmp .sources .completions (context ) end )
36
35
cmp .trigger .listen_on_hide (function ()
37
36
cmp .sources .cancel_completions ()
38
37
cmp .windows .autocomplete .close ()
@@ -50,30 +49,13 @@ cmp.setup = function(opts)
50
49
end )
51
50
end
52
51
53
- -- todo: dont default to cmp, use new hl groups
54
52
cmp .add_default_highlights = function ()
55
- --- @class Opts
56
- --- @field name string
57
- --- @field cmp_name string | nil
58
- --- @field default_name string
59
-
60
- --- @param opts Opts
61
- local function default_to_cmp (opts )
62
- local cmp_hl_name = ' CmpItem' .. (opts .cmp_name or opts .name )
63
- local blink_hl_name = ' BlinkCmp' .. opts .name
64
- if vim .api .nvim_get_hl (0 , { name = cmp_hl_name , create = false }) ~= nil then
65
- vim .api .nvim_set_hl (0 , blink_hl_name , { link = cmp_hl_name , default = true })
66
- else
67
- vim .api .nvim_set_hl (0 , blink_hl_name , { link = opts .default_name , default = true })
68
- end
69
- end
70
-
71
- default_to_cmp ({ name = ' Label' , cmp_name = ' Abbr' , default_name = ' Pmenu' })
72
- default_to_cmp ({ name = ' LabelDeprecated' , cmp_name = ' AbbrDeprecated' , default_name = ' Comment' })
73
- default_to_cmp ({ name = ' LabelMatch' , cmp_name = ' AbbrMatch' , default_name = ' Pmenu' })
74
- default_to_cmp ({ name = ' Kind' , default_name = ' Special' })
53
+ vim .api .nvim_set_hl (0 , ' BlinkCmpLabel' , { link = ' Pmenu' , default = true })
54
+ vim .api .nvim_set_hl (0 , ' BlinkCmpLabelDeprecated' , { link = ' Comment' , default = true })
55
+ vim .api .nvim_set_hl (0 , ' BlinkCmpLabelMatch' , { link = ' Pmenu' , default = true })
56
+ vim .api .nvim_set_hl (0 , ' BlinkCmpKind' , { link = ' Special' , default = true })
75
57
for _ , kind in pairs (vim .lsp .protocol .CompletionItemKind ) do
76
- default_to_cmp ({ name = ' Kind ' .. kind , default_name = ' BlinkCmpItemKind' })
58
+ vim . api . nvim_set_hl ( 0 , ' BlinkCmpKind ' .. kind , { link = ' BlinkCmpItemKind' , default = true })
77
59
end
78
60
end
79
61
@@ -82,6 +64,11 @@ cmp.show = function()
82
64
return true
83
65
end
84
66
67
+ cmp .hide = function ()
68
+ vim .schedule (function () cmp .trigger .hide () end )
69
+ return true
70
+ end
71
+
85
72
cmp .accept = function ()
86
73
local item = cmp .windows .autocomplete .get_selected_item ()
87
74
if item == nil then return end
0 commit comments