|
2 | 2 | local enums = require("codeium.enums") |
3 | 3 | local util = require("codeium.util") |
4 | 4 |
|
| 5 | +--- @class blink.cmp.Source |
| 6 | +--- @field server codeium.Server |
| 7 | +local M = {} |
| 8 | + |
5 | 9 | local function utf8len(str) |
6 | 10 | if not str then |
7 | 11 | return 0 |
|
12 | 16 | local function codeium_to_item(comp, offset, right) |
13 | 17 | local documentation = comp.completion.text |
14 | 18 |
|
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) |
18 | 22 | end |
19 | 23 |
|
20 | 24 | -- We get the completion part that has the largest offset |
@@ -45,41 +49,42 @@ local function codeium_to_item(comp, offset, right) |
45 | 49 | }, |
46 | 50 | } |
47 | 51 |
|
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 |
50 | 54 | display_label = display_label .. " " |
51 | 55 | end |
52 | 56 |
|
53 | 57 | 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 | | - }, |
63 | 58 | label = display_label, |
64 | | - insertText = label, |
| 59 | + insertText = insert_text, |
65 | 60 | kind = require('blink.cmp.types').CompletionItemKind.Text, |
66 | 61 | insertTextFormat = vim.lsp.protocol.InsertTextFormat.PlainText, |
| 62 | + kind_name = 'Codeium', |
| 63 | + kind_hl_group = 'BlinkCmpKindCopilot', |
| 64 | + kind_icon = '', |
67 | 65 | textEdit = { |
68 | | - newText = label, |
| 66 | + newText = insert_text, |
69 | 67 | insert = range, |
70 | 68 | replace = range, |
71 | 69 | }, |
72 | | - cmp = { |
73 | | - kind_text = "Codeium", |
74 | | - kind_hl_group = "BlinkCmpKindCopilot", |
75 | | - }, |
76 | | - codeium_completion_id = comp.completion.completionId, |
77 | 70 | } |
78 | 71 | end |
79 | 72 |
|
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 |
83 | 88 |
|
84 | 89 | function M.new() |
85 | 90 | local o = {} |
|
0 commit comments