autoload/lsp/textedit.vim | 6 +++++- diff --git a/autoload/lsp/textedit.vim b/autoload/lsp/textedit.vim index 257ec53c77e2841a35e30441db43bf4c26ffb341..4fdc615824a8a0efbd4e0be1d592145b315246d8 100644 --- a/autoload/lsp/textedit.vim +++ b/autoload/lsp/textedit.vim @@ -16,7 +16,8 @@ if a.A[1] != b.A[1] return b.A[1] - a.A[1] endif - return 0 + # Assume that the LSP sorted the lines correctly to begin with + return b.idx - a.idx enddef # Replaces text in a range with new text. @@ -117,6 +118,7 @@ var end_row: number var end_col: number # create a list of buffer positions where the edits have to be applied. + var idx = 0 for e in text_edits # Adjust the start and end columns for multibyte characters start_row = e.range.start.line @@ -128,7 +130,9 @@ finish_line = [e.range.end.line, finish_line]->max() updated_edits->add({A: [start_row, start_col], B: [end_row, end_col], + idx: idx, lines: e.newText->split("\n", true)}) + idx += 1 endfor # Reverse sort the edit operations by descending line and column numbers so