@@ -10,7 +10,12 @@ local M = {}
10
10
--- @param offset_encoding string | nil , ' utf-8,16,32' or ni
11
11
--- @param apply_text_edits_fn function , has to apply regular textEdits , most
12
12
--- likely `vim.lsp.util.apply_text_edits` (we expect its' interface).
13
- function M .apply_text_edits (snippet_or_text_edits , bufnr , offset_encoding , apply_text_edits_fn )
13
+ function M .apply_text_edits (
14
+ snippet_or_text_edits ,
15
+ bufnr ,
16
+ offset_encoding ,
17
+ apply_text_edits_fn
18
+ )
14
19
-- plain textEdits, applied using via `apply_text_edits_fn`.
15
20
local text_edits = {}
16
21
-- contains keys
@@ -20,20 +25,37 @@ function M.apply_text_edits(snippet_or_text_edits, bufnr, offset_encoding, apply
20
25
21
26
for _ , v in ipairs (snippet_or_text_edits ) do
22
27
if v .newText and v .insertTextFormat == 2 then
23
- assert (snippet_params == nil , " Only one snippetTextEdit may be applied at once." )
28
+ assert (
29
+ snippet_params == nil ,
30
+ " Only one snippetTextEdit may be applied at once."
31
+ )
24
32
25
33
-- from vim.lsp.apply_text_edits.
26
34
local start_row = v .range .start .line
27
- local start_col = vim .lsp .util ._get_line_byte_from_position (bufnr , v .range .start , offset_encoding )
28
- local end_row = v .range [' end' ].line
29
- local end_col = vim .lsp .util ._get_line_byte_from_position (bufnr , v .range [' end' ], offset_encoding )
35
+ local start_col = vim .lsp .util ._get_line_byte_from_position (
36
+ bufnr ,
37
+ v .range .start ,
38
+ offset_encoding
39
+ )
40
+ local end_row = v .range [" end" ].line
41
+ local end_col = vim .lsp .util ._get_line_byte_from_position (
42
+ bufnr ,
43
+ v .range [" end" ],
44
+ offset_encoding
45
+ )
30
46
31
47
snippet_params = {
32
48
snippet_body = v .newText ,
33
- mark = vim .api .nvim_buf_set_extmark (bufnr , luasnip_ns_id , start_row , start_col , {
34
- end_row = end_row ,
35
- end_col = end_col
36
- }),
49
+ mark = vim .api .nvim_buf_set_extmark (
50
+ bufnr ,
51
+ luasnip_ns_id ,
52
+ start_row ,
53
+ start_col ,
54
+ {
55
+ end_row = end_row ,
56
+ end_col = end_col ,
57
+ }
58
+ ),
37
59
}
38
60
else
39
61
table.insert (text_edits , v )
@@ -44,9 +66,14 @@ function M.apply_text_edits(snippet_or_text_edits, bufnr, offset_encoding, apply
44
66
apply_text_edits_fn (text_edits , bufnr , offset_encoding )
45
67
46
68
-- ...then the snippet.
47
- local mark_info = vim .api .nvim_buf_get_extmark_by_id (bufnr , luasnip_ns_id , snippet_params .mark , {details = true })
48
- local mark_begin_pos = {mark_info [1 ], mark_info [2 ]}
49
- local mark_end_pos = {mark_info [3 ].end_row , mark_info [3 ].end_col }
69
+ local mark_info = vim .api .nvim_buf_get_extmark_by_id (
70
+ bufnr ,
71
+ luasnip_ns_id ,
72
+ snippet_params .mark ,
73
+ { details = true }
74
+ )
75
+ local mark_begin_pos = { mark_info [1 ], mark_info [2 ] }
76
+ local mark_end_pos = { mark_info [3 ].end_row , mark_info [3 ].end_col }
50
77
51
78
-- luasnip can only expand snippets in the active buffer, so switch (nop if
52
79
-- buf already active).
0 commit comments