Some language servers like "efm-langserver" configured with "prettier"
will provide multiple textedits for the same line and column, these are
actually sorted "correctly" but since we apply the changes in reverse we
need to also take the original sorting into account.
The range provided is something like:
{ start: { line: 10, character: 0 }, end: { line: 10, character: 0 } }
and this is the LSP servers way to provide an insert.
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.
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
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