Skip to content

Commit d16a5fe

Browse files
committed
2 parents cb2bc02 + 6a21d7c commit d16a5fe

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

lua/blink/cmp/accept/text-edits.lua

+5-6
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@ function text_edits.guess_text_edit(bufnr, item)
4949
-- Search forward/backward for the start/end of the word
5050
local start_col = current_col
5151
while start_col > 1 do
52-
local char = line:sub(start_col, start_col)
53-
if char:match('[%w_\\-]') == nil then
54-
start_col = start_col + 1
55-
break
56-
end
52+
local char = line:sub(start_col - 1, start_col - 1)
53+
if char:match('[%w_\\-]') == nil then break end
5754
start_col = start_col - 1
5855
end
5956

60-
-- todo: dont search forward since LSPs dont typically do this so it will be inconsistent
57+
-- todo: optionally dont search forward since LSPs dont typically do this with textEdits
58+
-- so this will lead to inconsistent behavior
59+
-- OR add support on textEdits
6160
local end_col = current_col
6261
while end_col < #line do
6362
local char = line:sub(end_col + 1, end_col + 1)

lua/blink/cmp/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ cmp.setup_signature_help = function()
7575
signature_trigger.listen_on_show(function(context)
7676
cmp.sources.cancel_signature_help()
7777
cmp.sources.get_signature_help(context, function(signature_help)
78-
if signature_help ~= nil and signature_trigger.context.id == context.id then
78+
if signature_help ~= nil and signature_trigger.context ~= nil and signature_trigger.context.id == context.id then
7979
signature_trigger.set_active_signature_help(signature_help)
8080
signature_window.open_with_signature_help(context, signature_help)
8181
else

lua/blink/cmp/sources/snippets/init.lua

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
--- @class blink.cmp.SnippetsOpts
2-
--- @param friendly_snippets boolean
3-
--- @param search_paths string[]
4-
--- @param global_snippets string[]
5-
--- @param extended_filetypes table<string, string[]>
6-
--- @param ignored_filetypes string[]
2+
--- @field friendly_snippets boolean
3+
--- @field search_paths string[]
4+
--- @field global_snippets string[]
5+
--- @field extended_filetypes table<string, string[]>
6+
--- @field ignored_filetypes string[]
77

8-
local utils = require('blink.cmp.utils')
98
local snippets = {}
109

1110
--- @param opts blink.cmp.SnippetsOpts
@@ -29,27 +28,24 @@ function snippets:get_completions(_, callback)
2928

3029
self.cache[filetype] = {}
3130
for _, snippet in pairs(snips) do
32-
table.insert(self.cache[filetype], self.registry:snippet_to_completion_item(snippet))
31+
table.insert(self.cache[filetype], snippet)
3332
end
3433
end
3534

36-
local copied_items = vim.tbl_map(function(item) return utils.shallow_copy(item) end, self.cache[filetype])
35+
local items = vim.tbl_map(
36+
function(item) return self.registry:snippet_to_completion_item(item) end,
37+
self.cache[filetype]
38+
)
3739
callback({
3840
is_incomplete_forward = false,
3941
is_incomplete_backward = false,
40-
items = copied_items,
42+
items = items,
4143
})
4244
end
4345

4446
function snippets:resolve(item, callback)
4547
-- TODO: ideally context is passed with the filetype
46-
local documentation = '```'
47-
.. vim.bo.filetype
48-
.. '\n'
49-
.. self.registry:preview(item.insertText)
50-
.. '```'
51-
.. '\n---\n'
52-
.. item.description
48+
local documentation = '```' .. vim.bo.filetype .. '\n' .. item.insertText .. '```' .. '\n---\n' .. item.description
5349

5450
local resolved_item = vim.deepcopy(item)
5551
resolved_item.documentation = {

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,21 @@ function registry:get_global_snippets()
103103
end
104104

105105
--- @param snippet blink.cmp.Snippet
106-
--- @param filetype string
107-
--- @param include_documentation boolean
108106
--- @return blink.cmp.CompletionItem
109107
function registry:snippet_to_completion_item(snippet)
108+
local body = type(snippet.body) == 'string' and snippet.body or table.concat(snippet.body, '\n')
110109
return {
111110
kind = vim.lsp.protocol.CompletionItemKind.Snippet,
112111
label = snippet.prefix,
113112
insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet,
114-
insertText = type(snippet.body) == 'string' and snippet.body or table.concat(snippet.body, '\n'),
113+
insertText = self:parse_body(body),
115114
description = snippet.description,
116115
}
117116
end
118117

119118
--- @param snippet string
120119
--- @return string
121-
function registry:preview(snippet)
120+
function registry:parse_body(snippet)
122121
local parse = utils.safe_parse(self:expand_vars(snippet))
123122
return parse and tostring(parse) or snippet
124123
end

0 commit comments

Comments
 (0)