Skip to content

Commit 4daf96d

Browse files
committed
fix: use internal CompletionItemKind table
closes #17
1 parent df5c0de commit 4daf96d

File tree

8 files changed

+70
-11
lines changed

8 files changed

+70
-11
lines changed

lua/blink/cmp/accept/brackets.lua

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ function brackets.add_brackets(filetype, item)
5151
-- check if configuration incidates we should skip
5252
if not brackets.should_run_resolution(filetype, 'kind') then return 'check_semantic_token', text_edit, 0 end
5353
-- not a function, skip
54-
if
55-
item.kind ~= vim.lsp.protocol.CompletionItemKind.Function
56-
and item.kind ~= vim.lsp.protocol.CompletionItemKind.Method
57-
then
54+
local CompletionItemKind = require('blink.cmp.types').CompletionItemKind
55+
if item.kind ~= CompletionItemKind.Function and item.kind ~= CompletionItemKind.Method then
5856
return 'check_semantic_token', text_edit, 0
5957
end
6058

@@ -107,7 +105,9 @@ function brackets.add_brackets_via_semantic_token(filetype, item, callback)
107105
if client == nil then return callback() end
108106

109107
local start_time = vim.uv.hrtime()
110-
if not (client.server_capabilities.semanticTokensProvider and client.server_capabilities.semanticTokensProvider.legend) then
108+
if
109+
not (client.server_capabilities.semanticTokensProvider and client.server_capabilities.semanticTokensProvider.legend)
110+
then
111111
return callback()
112112
end
113113
local numToTokenType = client.server_capabilities.semanticTokensProvider.legend.tokenTypes

lua/blink/cmp/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ cmp.add_default_highlights = function()
9898
set_hl('BlinkCmpLabelDeprecated', { link = use_nvim_cmp and 'CmpItemAbbrDeprecated' or 'Comment' })
9999
set_hl('BlinkCmpLabelMatch', { link = use_nvim_cmp and 'CmpItemAbbrMatch' or 'Pmenu' })
100100
set_hl('BlinkCmpKind', { link = use_nvim_cmp and 'CmpItemKind' or 'Special' })
101-
for _, kind in pairs(vim.lsp.protocol.CompletionItemKind) do
101+
for _, kind in ipairs(require('blink.cmp.types').CompletionItemKind) do
102102
set_hl('BlinkCmpKind' .. kind, { link = use_nvim_cmp and 'CmpItemKind' .. kind or 'BlinkCmpKind' })
103103
end
104104

lua/blink/cmp/sources/buffer.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ local function words_to_items(words)
3737
for _, word in ipairs(words) do
3838
table.insert(items, {
3939
label = word,
40-
kind = vim.lsp.protocol.CompletionItemKind.Text,
40+
kind = require('blink.cmp.types').CompletionItemKind.Text,
4141
insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet,
4242
insertText = word,
4343
})

lua/blink/cmp/sources/lsp.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function lsp:get_completions(context, callback)
118118
for _, item in ipairs(response.items) do
119119
-- todo: terraform lsp doesn't return a .kind in situations like `toset`, is there a default value we need to grab?
120120
-- it doesn't seem to return itemDefaults either
121-
item.kind = item.kind or vim.lsp.protocol.CompletionItemKind.Text
121+
item.kind = item.kind or require('blink.cmp.types').CompletionItemKind.Text
122122
item.client_id = client_id
123123

124124
-- todo: make configurable

lua/blink/cmp/sources/path/lib.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ end
7373
--- @return blink.cmp.CompletionItem[]
7474
function lib.entry_to_completion_item(entry, dirname, opts)
7575
local is_dir = entry.type == 'directory'
76+
local CompletionItemKind = require('blink.cmp.types').CompletionItemKind
7677
return {
7778
label = (opts.label_trailing_slash and is_dir) and entry.name .. '/' or entry.name,
78-
kind = is_dir and vim.lsp.protocol.CompletionItemKind.Folder or vim.lsp.protocol.CompletionItemKind.File,
79+
kind = is_dir and CompletionItemKind.Folder or CompletionItemKind.File,
7980
insertText = is_dir and entry.name .. '/' or entry.name,
8081
word = opts.trailing_slash and entry.name or nil,
8182
data = { path = entry.name, full_path = dirname .. '/' .. entry.name, type = entry.type, stat = entry.stat },

lua/blink/cmp/sources/snippets/registry.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ end
107107
function registry:snippet_to_completion_item(snippet)
108108
local body = type(snippet.body) == 'string' and snippet.body or table.concat(snippet.body, '\n')
109109
return {
110-
kind = vim.lsp.protocol.CompletionItemKind.Snippet,
110+
kind = require('blink.cmp.types').CompletionItemKind.Snippet,
111111
label = snippet.prefix,
112112
insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet,
113113
insertText = self:parse_body(body),

lua/blink/cmp/types.lua

+58
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,61 @@
33
--- @field source string
44
--- @field cursor_column number
55
--- @field client_id number
6+
7+
return {
8+
-- some plugins mutate the vim.lsp.protocol.CompletionItemKind table
9+
-- so we use our own copy
10+
CompletionItemKind = {
11+
'Text',
12+
'Method',
13+
'Function',
14+
'Constructor',
15+
'Field',
16+
'Variable',
17+
'Class',
18+
'Interface',
19+
'Module',
20+
'Property',
21+
'Unit',
22+
'Value',
23+
'Enum',
24+
'Keyword',
25+
'Snippet',
26+
'Color',
27+
'File',
28+
'Reference',
29+
'Folder',
30+
'EnumMember',
31+
'Constant',
32+
'Struct',
33+
'Event',
34+
'Operator',
35+
'TypeParameter',
36+
37+
Text = 1,
38+
Method = 2,
39+
Function = 3,
40+
Constructor = 4,
41+
Field = 5,
42+
Variable = 6,
43+
Class = 7,
44+
Interface = 8,
45+
Module = 9,
46+
Property = 10,
47+
Unit = 11,
48+
Value = 12,
49+
Enum = 13,
50+
Keyword = 14,
51+
Snippet = 15,
52+
Color = 16,
53+
File = 17,
54+
Reference = 18,
55+
Folder = 19,
56+
EnumMember = 20,
57+
Constant = 21,
58+
Struct = 22,
59+
Event = 23,
60+
Operator = 24,
61+
TypeParameter = 25,
62+
},
63+
}

lua/blink/cmp/windows/autocomplete.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function autocomplete.draw()
194194
local icon_gap = config.nerd_font_variant == 'mono' and ' ' or ' '
195195
local arr_of_components = {}
196196
for _, item in ipairs(autocomplete.items) do
197-
local kind = vim.lsp.protocol.CompletionItemKind[item.kind] or 'Unknown'
197+
local kind = require('blink.cmp.types').CompletionItemKind[item.kind] or 'Unknown'
198198
local kind_icon = config.kind_icons[kind] or config.kind_icons.Field
199199

200200
table.insert(

0 commit comments

Comments
 (0)