@@ -93,7 +93,7 @@ Describe lsp#utils#text_edit
93
93
Assert Equals(l:buffer_text, ['foo', 'replacedar', ''])
94
94
End
95
95
96
- It delete range string
96
+ It replace range string to empty newText
97
97
call s:set_text(['foo', 'bar'])
98
98
99
99
call lsp#utils#text_edit#apply_text_edits(
@@ -116,6 +116,257 @@ Describe lsp#utils#text_edit
116
116
Assert Equals(l:buffer_text, ['foo', 'ar', ''])
117
117
End
118
118
119
+ It single line start character is -1
120
+ call s:set_text(['foo', 'bar'])
121
+
122
+ call lsp#utils#text_edit#apply_text_edits(
123
+ \ expand('%'),
124
+ \ [{
125
+ \ 'range': {
126
+ \ 'start': {
127
+ \ 'line': 1,
128
+ \ 'character': -1
129
+ \ },
130
+ \ 'end': {
131
+ \ 'line': 1,
132
+ \ 'character': 3
133
+ \ }
134
+ \ },
135
+ \ 'newText': ''
136
+ \ }])
137
+
138
+ let l:buffer_text = s:get_text()
139
+ Assert Equals(l:buffer_text, ['foo', '', ''])
140
+ End
141
+
142
+ It single line start character is 0
143
+ call s:set_text(['foo', 'bar'])
144
+
145
+ call lsp#utils#text_edit#apply_text_edits(
146
+ \ expand('%'),
147
+ \ [{
148
+ \ 'range': {
149
+ \ 'start': {
150
+ \ 'line': 1,
151
+ \ 'character': 0
152
+ \ },
153
+ \ 'end': {
154
+ \ 'line': 1,
155
+ \ 'character': 3
156
+ \ }
157
+ \ },
158
+ \ 'newText': ''
159
+ \ }])
160
+
161
+ let l:buffer_text = s:get_text()
162
+ Assert Equals(l:buffer_text, ['foo', '', ''])
163
+ End
164
+
165
+ It single line start character is 1
166
+ call s:set_text(['foo', 'bar'])
167
+
168
+ call lsp#utils#text_edit#apply_text_edits(
169
+ \ expand('%'),
170
+ \ [{
171
+ \ 'range': {
172
+ \ 'start': {
173
+ \ 'line': 1,
174
+ \ 'character': 1
175
+ \ },
176
+ \ 'end': {
177
+ \ 'line': 1,
178
+ \ 'character': 3
179
+ \ }
180
+ \ },
181
+ \ 'newText': ''
182
+ \ }])
183
+
184
+ let l:buffer_text = s:get_text()
185
+ Assert Equals(l:buffer_text, ['foo', 'b', ''])
186
+ End
187
+
188
+ It single line end character is `len(getline('.')) - 1`
189
+ call s:set_text(['foo', 'bar'])
190
+
191
+ call lsp#utils#text_edit#apply_text_edits(
192
+ \ expand('%'),
193
+ \ [{
194
+ \ 'range': {
195
+ \ 'start': {
196
+ \ 'line': 1,
197
+ \ 'character': 0
198
+ \ },
199
+ \ 'end': {
200
+ \ 'line': 1,
201
+ \ 'character': 2
202
+ \ }
203
+ \ },
204
+ \ 'newText': ''
205
+ \ }])
206
+
207
+ let l:buffer_text = s:get_text()
208
+ Assert Equals(l:buffer_text, ['foo', 'r', ''])
209
+ End
210
+
211
+ It single line end character is `len(getline('.'))`
212
+ call s:set_text(['foo', 'bar'])
213
+
214
+ call lsp#utils#text_edit#apply_text_edits(
215
+ \ expand('%'),
216
+ \ [{
217
+ \ 'range': {
218
+ \ 'start': {
219
+ \ 'line': 1,
220
+ \ 'character': 0
221
+ \ },
222
+ \ 'end': {
223
+ \ 'line': 1,
224
+ \ 'character': 3
225
+ \ }
226
+ \ },
227
+ \ 'newText': ''
228
+ \ }])
229
+
230
+ let l:buffer_text = s:get_text()
231
+ Assert Equals(l:buffer_text, ['foo', '', ''])
232
+ End
233
+
234
+ It single line end character is `len(getline('.')) + 1`
235
+ call s:set_text(['foo', 'bar'])
236
+
237
+ call lsp#utils#text_edit#apply_text_edits(
238
+ \ expand('%'),
239
+ \ [{
240
+ \ 'range': {
241
+ \ 'start': {
242
+ \ 'line': 1,
243
+ \ 'character': 0
244
+ \ },
245
+ \ 'end': {
246
+ \ 'line': 1,
247
+ \ 'character': 4
248
+ \ }
249
+ \ },
250
+ \ 'newText': ''
251
+ \ }])
252
+
253
+ " if newline character deleting, need end position is next line zero character.
254
+ let l:buffer_text = s:get_text()
255
+ Assert Equals(l:buffer_text, ['foo', '', ''])
256
+ End
257
+
258
+ It replace range string to empty newText, multiline top to top
259
+ call s:set_text(['foo', 'bar', 'baz'])
260
+
261
+ call lsp#utils#text_edit#apply_text_edits(
262
+ \ expand('%'),
263
+ \ [{
264
+ \ 'range': {
265
+ \ 'start': {
266
+ \ 'line': 0,
267
+ \ 'character': 0
268
+ \ },
269
+ \ 'end': {
270
+ \ 'line': 1,
271
+ \ 'character': 0
272
+ \ }
273
+ \ },
274
+ \ 'newText': ''
275
+ \ }])
276
+
277
+ let l:buffer_text = s:get_text()
278
+ Assert Equals(l:buffer_text, ['bar', 'baz', ''])
279
+ End
280
+
281
+ It replace range string to empty newText, multiline top to tail
282
+ call s:set_text(['foo', 'bar', 'baz'])
283
+
284
+ call lsp#utils#text_edit#apply_text_edits(
285
+ \ expand('%'),
286
+ \ [{
287
+ \ 'range': {
288
+ \ 'start': {
289
+ \ 'line': 0,
290
+ \ 'character': 0
291
+ \ },
292
+ \ 'end': {
293
+ \ 'line': 1,
294
+ \ 'character': 2
295
+ \ }
296
+ \ },
297
+ \ 'newText': ''
298
+ \ }])
299
+
300
+ let l:buffer_text = s:get_text()
301
+ Assert Equals(l:buffer_text, ['r', 'baz', ''])
302
+
303
+ call s:set_text(['foo', 'bar', 'baz'])
304
+
305
+ call lsp#utils#text_edit#apply_text_edits(
306
+ \ expand('%'),
307
+ \ [{
308
+ \ 'range': {
309
+ \ 'start': {
310
+ \ 'line': 0,
311
+ \ 'character': 0
312
+ \ },
313
+ \ 'end': {
314
+ \ 'line': 1,
315
+ \ 'character': 3
316
+ \ }
317
+ \ },
318
+ \ 'newText': ''
319
+ \ }])
320
+
321
+ let l:buffer_text = s:get_text()
322
+ Assert Equals(l:buffer_text, ['', 'baz', ''])
323
+
324
+ call s:set_text(['foo', 'bar', 'baz'])
325
+
326
+ call lsp#utils#text_edit#apply_text_edits(
327
+ \ expand('%'),
328
+ \ [{
329
+ \ 'range': {
330
+ \ 'start': {
331
+ \ 'line': 0,
332
+ \ 'character': 0
333
+ \ },
334
+ \ 'end': {
335
+ \ 'line': 1,
336
+ \ 'character': 4
337
+ \ }
338
+ \ },
339
+ \ 'newText': ''
340
+ \ }])
341
+
342
+ " if newline character deleting, need end position is next line zero character.
343
+ let l:buffer_text = s:get_text()
344
+ Assert Equals(l:buffer_text, ['', 'baz', ''])
345
+ End
346
+
347
+ It replace range string to empty newText, multiline middle to middle
348
+ call s:set_text(['foo', 'bar', 'baz'])
349
+
350
+ call lsp#utils#text_edit#apply_text_edits(
351
+ \ expand('%'),
352
+ \ [{
353
+ \ 'range': {
354
+ \ 'start': {
355
+ \ 'line': 0,
356
+ \ 'character': 1
357
+ \ },
358
+ \ 'end': {
359
+ \ 'line': 1,
360
+ \ 'character': 2
361
+ \ }
362
+ \ },
363
+ \ 'newText': ''
364
+ \ }])
365
+
366
+ let l:buffer_text = s:get_text()
367
+ Assert Equals(l:buffer_text, ['fr', 'baz', ''])
368
+ End
369
+
119
370
It preserves v:completed_item
120
371
" Add some text to buffer
121
372
call s:set_text(['foo', 'bar'])
0 commit comments