Skip to content

Commit 3a6def0

Browse files
committed
Add test
1 parent e9a428d commit 3a6def0

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

autoload/lsp/utils/text_edit.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ function! s:generate_sub_cmd_replace(text_edit) abort
193193

194194
if len(l:new_text) == 0
195195
let l:sub_cmd .= 'x'
196+
elseif l:end_character == 0
197+
let l:sub_cmd .= "c\<C-R>=substitute(l:merged_text_edit['merged']['newText'], '\\n$', '', '')\<CR>"
196198
else
197199
let l:sub_cmd .= "c\<C-R>=l:merged_text_edit['merged']['newText']\<CR>"
198200
endif

test/lsp/utils/text_edit.vimspec

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,59 @@ Describe lsp#utils#text_edit
390390
Assert Equals(l:buffer_text, ['x', 'y', 'z', ''])
391391
End
392392

393+
It multiple textEdit with inserting \r.
394+
" Add some text to buffer
395+
call s:set_text(['class ABC {', ' private:', ' ', 'int a;};', ])
396+
397+
" Format
398+
call lsp#utils#text_edit#apply_text_edits(
399+
\ expand('%'),
400+
\ [
401+
\ {
402+
\ "range": {
403+
\ "end": {
404+
\ "character": 2,
405+
\ "line": 1
406+
\ },
407+
\ "start": {
408+
\ "character": 11,
409+
\ "line": 0
410+
\ }
411+
\ },
412+
\ "newText": "\n"
413+
\ },
414+
\ {
415+
\ "range": {
416+
\ "end": {
417+
\ "character": 0,
418+
\ "line": 3
419+
\ },
420+
\ "start": {
421+
\ "character": 10,
422+
\ "line": 1
423+
\ }
424+
\ },
425+
\ "newText": "\n "
426+
\ },
427+
\ {
428+
\ "range": {
429+
\ "end": {
430+
\ "character": 6,
431+
\ "line": 3
432+
\ },
433+
\ "start": {
434+
\ "character": 6,
435+
\ "line": 3
436+
\ }
437+
\ },
438+
\ "newText": "\n"
439+
\ }
440+
\ ])
441+
442+
let l:buffer_text = s:get_text()
443+
Assert Equals(l:buffer_text, ['class ABC {', 'private:', ' int a;', '};', ''])
444+
End
445+
393446
It preserves v:completed_item
394447
" Add some text to buffer
395448
call s:set_text(['foo', 'bar'])

0 commit comments

Comments
 (0)