@@ -6,41 +6,39 @@ local brackets_lib = require('blink.cmp.accept.brackets')
6
6
local function accept (item )
7
7
item = vim .deepcopy (item )
8
8
9
- local text_edit = item .textEdit
10
- if text_edit ~= nil then
11
- -- Adjust the position of the text edit to be the current cursor position
12
- -- since the data might be outdated. We compare the cursor column position
13
- -- from when the items were fetched versus the current.
14
- -- hack: figure out a better way
9
+ -- Adjust the position of the text edit to be the current cursor position
10
+ -- since the data might be outdated. We compare the cursor column position
11
+ -- from when the items were fetched versus the current.
12
+ -- hack: figure out a better way
13
+ if item .textEdit ~= nil then
15
14
local offset = vim .api .nvim_win_get_cursor (0 )[2 ] - item .cursor_column
16
- text_edit .range [' end' ].character = text_edit .range [' end' ].character + offset
15
+ item .textEdit .range [' end' ].character = item .textEdit .range [' end' ].character + offset
16
+ -- No text edit so we fallback to our own resolution
17
17
else
18
- -- No text edit so we fallback to our own resolution
19
- text_edit = text_edits_lib .guess_text_edit (vim .api .nvim_get_current_buf (), item )
18
+ item .textEdit = text_edits_lib .guess_text_edit (vim .api .nvim_get_current_buf (), item )
20
19
end
21
- item .textEdit = text_edit
22
20
23
21
-- Add brackets to the text edit if needed
24
22
local brackets_status , text_edit_with_brackets , offset = brackets_lib .add_brackets (vim .bo .filetype , item )
25
- text_edit = text_edit_with_brackets
23
+ item . textEdit = text_edit_with_brackets
26
24
27
25
-- Snippet
28
26
if item .insertTextFormat == vim .lsp .protocol .InsertTextFormat .Snippet then
29
27
-- We want to handle offset_encoding and the text edit api can do this for us
30
28
-- so we empty the newText and apply
31
- local temp_text_edit = vim .deepcopy (text_edit )
29
+ local temp_text_edit = vim .deepcopy (item . textEdit )
32
30
temp_text_edit .newText = ' '
33
31
text_edits_lib .apply_text_edits (item .client_id , { temp_text_edit })
34
32
35
33
-- Expand the snippet
36
- vim .snippet .expand (text_edit .newText )
34
+ vim .snippet .expand (item . textEdit .newText )
37
35
38
36
-- OR Normal: Apply the text edit and move the cursor
39
37
else
40
- text_edits_lib .apply_text_edits (item .client_id , { text_edit })
38
+ text_edits_lib .apply_text_edits (item .client_id , { item . textEdit })
41
39
vim .api .nvim_win_set_cursor (0 , {
42
- text_edit .range .start .line + 1 ,
43
- text_edit . range .start .character + # text_edit .newText + offset ,
40
+ item . textEdit .range .start .line + 1 ,
41
+ item . textEdit . range .start .character + # item . textEdit .newText + offset ,
44
42
})
45
43
end
46
44
0 commit comments