@@ -102,9 +102,6 @@ function text_edits.get_from_item(item)
102
102
text_edit .replace = nil
103
103
--- @cast text_edit lsp.TextEdit
104
104
105
- local client = vim .lsp .get_client_by_id (item .client_id )
106
- local offset_encoding = client ~= nil and client .offset_encoding or ' utf-8'
107
-
108
105
-- Adjust the position of the text edit to be the current cursor position
109
106
-- since the data might be outdated. We compare the cursor column position
110
107
-- from when the items were fetched versus the current.
@@ -113,14 +110,25 @@ function text_edits.get_from_item(item)
113
110
local offset = vim .api .nvim_win_get_cursor (0 )[2 ] - item .cursor_column
114
111
text_edit .range [' end' ].character = text_edit .range [' end' ].character + offset
115
112
116
- -- convert the offset encoding to utf-8 if necessary
113
+ -- convert the offset encoding to utf-8
117
114
-- TODO: we have to do this last because it applies a max on the position based on the length of the line
118
115
-- so it would break the offset code when removing characters at the end of the line
119
- if offset_encoding ~= ' utf-8' then
120
- text_edit .range .start .character = get_line_byte_from_position (text_edit .range .start , offset_encoding )
121
- text_edit .range [' end' ].character = get_line_byte_from_position (text_edit .range [' end' ], offset_encoding )
122
- end
116
+ local offset_encoding = text_edits .offset_encoding_from_item (item )
117
+ text_edit = text_edits .to_utf_8 (text_edit , offset_encoding )
118
+
119
+ return text_edit
120
+ end
123
121
122
+ function text_edits .offset_encoding_from_item (item )
123
+ local client = vim .lsp .get_client_by_id (item .client_id )
124
+ return client ~= nil and client .offset_encoding or ' utf-8'
125
+ end
126
+
127
+ function text_edits .to_utf_8 (text_edit , offset_encoding )
128
+ if offset_encoding == ' utf-8' then return text_edit end
129
+ text_edit = vim .deepcopy (text_edit )
130
+ text_edit .range .start .character = get_line_byte_from_position (text_edit .range .start , offset_encoding )
131
+ text_edit .range [' end' ].character = get_line_byte_from_position (text_edit .range [' end' ], offset_encoding )
124
132
return text_edit
125
133
end
126
134
@@ -131,8 +139,11 @@ function text_edits.guess(item)
131
139
local word = item .insertText or item .label
132
140
133
141
local keyword = config .completion .keyword
134
- local range =
135
- require (' blink.cmp.lib.utils' ).get_regex_around_cursor (keyword .range , keyword .regex , keyword .exclude_from_prefix_regex )
142
+ local range = require (' blink.cmp.lib.utils' ).get_regex_around_cursor (
143
+ keyword .range ,
144
+ keyword .regex ,
145
+ keyword .exclude_from_prefix_regex
146
+ )
136
147
local current_line = vim .api .nvim_win_get_cursor (0 )[1 ]
137
148
138
149
-- convert to 0-index
0 commit comments