Skip to content

Commit 632e625

Browse files
committed
lsp: fix applyTextEdits
Fix applyTextEdits to correctly calculate the prefix of the replacement text. Fixes fatih#3231
1 parent 8c883d7 commit 632e625

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

autoload/go/lsp.vim

+6-7
Original file line numberDiff line numberDiff line change
@@ -1741,15 +1741,14 @@ function s:applyTextEdits(bufnr, msg) abort
17411741
continue
17421742
endif
17431743

1744-
let l:startcontent = getline(l:startline)
1745-
let l:preSliceEnd = 0
1744+
" Assume that l:startcontent will be an empty string. When the replacement
1745+
" is not at the beginning of the line, then l:startcontent must be what
1746+
" comes before the start position on the start line.
1747+
let l:startcontent = ''
17461748
if l:msg.range.start.character > 0
1749+
let l:startcontent = getline(l:startline)
17471750
let l:preSliceEnd = go#lsp#lsp#PositionOf(l:startcontent, l:msg.range.start.character-1) - 1
17481751
let l:startcontent = l:startcontent[:l:preSliceEnd]
1749-
elseif l:endline == l:startline && (l:msg.range.end.character == 0 || l:msg.range.start.character == 0)
1750-
" l:startcontent should be the empty string when l:text is a
1751-
" replacement at the beginning of the line.
1752-
let l:startcontent = ''
17531752
endif
17541753

17551754
let l:endcontent = getline(l:endline)
@@ -1820,7 +1819,7 @@ function! s:textEditLess(left, right) abort
18201819
endif
18211820
endif
18221821

1823-
" return 0, because a:left an a:right refer to the same position.
1822+
" return 0, because a:left and a:right refer to the same position.
18241823
return 0
18251824
endfunction
18261825

0 commit comments

Comments
 (0)