Skip to content

Commit cc17f4b

Browse files
update blink support for the latest version
add kind_icon
1 parent d0431b4 commit cc17f4b

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

lua/codeium/blink.lua

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
local enums = require("codeium.enums")
33
local util = require("codeium.util")
44

5+
--- @class blink.cmp.Source
6+
--- @field server codeium.Server
7+
local M = {}
8+
59
local function utf8len(str)
610
if not str then
711
return 0
@@ -12,9 +16,9 @@ end
1216
local function codeium_to_item(comp, offset, right)
1317
local documentation = comp.completion.text
1418

15-
local label = documentation:sub(offset)
16-
if label:sub(-#right) == right then
17-
label = label:sub(1, -#right - 1)
19+
local insert_text = documentation:sub(offset)
20+
if insert_text:sub(-#right) == right then
21+
insert_text = insert_text:sub(1, -#right - 1)
1822
end
1923

2024
-- We get the completion part that has the largest offset
@@ -45,41 +49,42 @@ local function codeium_to_item(comp, offset, right)
4549
},
4650
}
4751

48-
local display_label = string.match(label, "([^\n]*)")
49-
if display_label ~= label then
52+
local display_label = string.match(insert_text, "([^\n]*)")
53+
if display_label ~= insert_text then
5054
display_label = display_label .. ""
5155
end
5256

5357
return {
54-
type = 1,
55-
documentation = {
56-
kind = "markdown",
57-
value = table.concat({
58-
"```" .. vim.api.nvim_get_option_value("filetype", {}),
59-
label,
60-
"```",
61-
}, "\n"),
62-
},
6358
label = display_label,
64-
insertText = label,
59+
insertText = insert_text,
6560
kind = require('blink.cmp.types').CompletionItemKind.Text,
6661
insertTextFormat = vim.lsp.protocol.InsertTextFormat.PlainText,
62+
kind_name = 'Codeium',
63+
kind_hl_group = 'BlinkCmpKindCopilot',
64+
kind_icon = '󰘦',
6765
textEdit = {
68-
newText = label,
66+
newText = insert_text,
6967
insert = range,
7068
replace = range,
7169
},
72-
cmp = {
73-
kind_text = "Codeium",
74-
kind_hl_group = "BlinkCmpKindCopilot",
75-
},
76-
codeium_completion_id = comp.completion.completionId,
7770
}
7871
end
7972

80-
--- @class blink.cmp.Source
81-
--- @field server codeium.Server
82-
local M = {}
73+
--- Resolve the completion item
74+
function M:resolve(item, callback)
75+
item = vim.deepcopy(item)
76+
77+
item.documentation = {
78+
kind = 'markdown',
79+
value = table.concat({
80+
"```" .. vim.api.nvim_get_option_value("filetype", {}),
81+
item.insertText,
82+
"```",
83+
}, "\n"),
84+
}
85+
86+
callback(item)
87+
end
8388

8489
function M.new()
8590
local o = {}

0 commit comments

Comments
 (0)