Skip to content

Commit

Permalink
fix: use internal CompletionItemKind table
Browse files Browse the repository at this point in the history
closes #17
  • Loading branch information
Saghen committed Oct 9, 2024
1 parent df5c0de commit 4daf96d
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 11 deletions.
10 changes: 5 additions & 5 deletions lua/blink/cmp/accept/brackets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ function brackets.add_brackets(filetype, item)
-- check if configuration incidates we should skip
if not brackets.should_run_resolution(filetype, 'kind') then return 'check_semantic_token', text_edit, 0 end
-- not a function, skip
if
item.kind ~= vim.lsp.protocol.CompletionItemKind.Function
and item.kind ~= vim.lsp.protocol.CompletionItemKind.Method
then
local CompletionItemKind = require('blink.cmp.types').CompletionItemKind
if item.kind ~= CompletionItemKind.Function and item.kind ~= CompletionItemKind.Method then
return 'check_semantic_token', text_edit, 0
end

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

local start_time = vim.uv.hrtime()
if not (client.server_capabilities.semanticTokensProvider and client.server_capabilities.semanticTokensProvider.legend) then
if
not (client.server_capabilities.semanticTokensProvider and client.server_capabilities.semanticTokensProvider.legend)
then
return callback()
end
local numToTokenType = client.server_capabilities.semanticTokensProvider.legend.tokenTypes
Expand Down
2 changes: 1 addition & 1 deletion lua/blink/cmp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ cmp.add_default_highlights = function()
set_hl('BlinkCmpLabelDeprecated', { link = use_nvim_cmp and 'CmpItemAbbrDeprecated' or 'Comment' })
set_hl('BlinkCmpLabelMatch', { link = use_nvim_cmp and 'CmpItemAbbrMatch' or 'Pmenu' })
set_hl('BlinkCmpKind', { link = use_nvim_cmp and 'CmpItemKind' or 'Special' })
for _, kind in pairs(vim.lsp.protocol.CompletionItemKind) do
for _, kind in ipairs(require('blink.cmp.types').CompletionItemKind) do
set_hl('BlinkCmpKind' .. kind, { link = use_nvim_cmp and 'CmpItemKind' .. kind or 'BlinkCmpKind' })
end

Expand Down
2 changes: 1 addition & 1 deletion lua/blink/cmp/sources/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ local function words_to_items(words)
for _, word in ipairs(words) do
table.insert(items, {
label = word,
kind = vim.lsp.protocol.CompletionItemKind.Text,
kind = require('blink.cmp.types').CompletionItemKind.Text,
insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet,
insertText = word,
})
Expand Down
2 changes: 1 addition & 1 deletion lua/blink/cmp/sources/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function lsp:get_completions(context, callback)
for _, item in ipairs(response.items) do
-- todo: terraform lsp doesn't return a .kind in situations like `toset`, is there a default value we need to grab?
-- it doesn't seem to return itemDefaults either
item.kind = item.kind or vim.lsp.protocol.CompletionItemKind.Text
item.kind = item.kind or require('blink.cmp.types').CompletionItemKind.Text
item.client_id = client_id

-- todo: make configurable
Expand Down
3 changes: 2 additions & 1 deletion lua/blink/cmp/sources/path/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ end
--- @return blink.cmp.CompletionItem[]
function lib.entry_to_completion_item(entry, dirname, opts)
local is_dir = entry.type == 'directory'
local CompletionItemKind = require('blink.cmp.types').CompletionItemKind
return {
label = (opts.label_trailing_slash and is_dir) and entry.name .. '/' or entry.name,
kind = is_dir and vim.lsp.protocol.CompletionItemKind.Folder or vim.lsp.protocol.CompletionItemKind.File,
kind = is_dir and CompletionItemKind.Folder or CompletionItemKind.File,
insertText = is_dir and entry.name .. '/' or entry.name,
word = opts.trailing_slash and entry.name or nil,
data = { path = entry.name, full_path = dirname .. '/' .. entry.name, type = entry.type, stat = entry.stat },
Expand Down
2 changes: 1 addition & 1 deletion lua/blink/cmp/sources/snippets/registry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ end
function registry:snippet_to_completion_item(snippet)
local body = type(snippet.body) == 'string' and snippet.body or table.concat(snippet.body, '\n')
return {
kind = vim.lsp.protocol.CompletionItemKind.Snippet,
kind = require('blink.cmp.types').CompletionItemKind.Snippet,
label = snippet.prefix,
insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet,
insertText = self:parse_body(body),
Expand Down
58 changes: 58 additions & 0 deletions lua/blink/cmp/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,61 @@
--- @field source string
--- @field cursor_column number
--- @field client_id number

return {
-- some plugins mutate the vim.lsp.protocol.CompletionItemKind table
-- so we use our own copy
CompletionItemKind = {
'Text',
'Method',
'Function',
'Constructor',
'Field',
'Variable',
'Class',
'Interface',
'Module',
'Property',
'Unit',
'Value',
'Enum',
'Keyword',
'Snippet',
'Color',
'File',
'Reference',
'Folder',
'EnumMember',
'Constant',
'Struct',
'Event',
'Operator',
'TypeParameter',

Text = 1,
Method = 2,
Function = 3,
Constructor = 4,
Field = 5,
Variable = 6,
Class = 7,
Interface = 8,
Module = 9,
Property = 10,
Unit = 11,
Value = 12,
Enum = 13,
Keyword = 14,
Snippet = 15,
Color = 16,
File = 17,
Reference = 18,
Folder = 19,
EnumMember = 20,
Constant = 21,
Struct = 22,
Event = 23,
Operator = 24,
TypeParameter = 25,
},
}
2 changes: 1 addition & 1 deletion lua/blink/cmp/windows/autocomplete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function autocomplete.draw()
local icon_gap = config.nerd_font_variant == 'mono' and ' ' or ' '
local arr_of_components = {}
for _, item in ipairs(autocomplete.items) do
local kind = vim.lsp.protocol.CompletionItemKind[item.kind] or 'Unknown'
local kind = require('blink.cmp.types').CompletionItemKind[item.kind] or 'Unknown'
local kind_icon = config.kind_icons[kind] or config.kind_icons.Field

table.insert(
Expand Down

0 comments on commit 4daf96d

Please sign in to comment.