lsp: Make apply_text_edits non-ASCII safe (#12223)

* Make apply_text_edits non-ASCII safe

Use `vim.str_byteindex` to correct starting and ending positions for text edits if the line contains non-ASCII characters.

Fixes #12221

* text_edit may be applied to other buffers

* make sure the buffer is loaded

* add comments

* add test for non-ASCII edits
This commit is contained in:
Christian Clason
2020-05-08 16:04:41 +02:00
committed by GitHub
parent 9a67b030d9
commit 281e44f7bb
2 changed files with 19 additions and 11 deletions

View File

@@ -779,7 +779,7 @@ describe('LSP', function()
Fourth line of text
å å ɧ 汉语 ↥ 🤦 🦄]]))
end)
it('applies apply simple edits', function()
it('applies simple edits', function()
local edits = {
make_edit(0, 0, 0, 0, {"123"});
make_edit(1, 0, 1, 1, {"2"});
@@ -818,10 +818,9 @@ describe('LSP', function()
'å å ɧ 汉语 ↥ 🤦 🦄';
}, buf_lines(1))
end)
pending('applies non-ASCII characters edits', function()
-- FIXME: We don't handle non-ASCII characters well in UTF-16
it('applies non-ASCII characters edits', function()
local edits = {
make_edit(4, 0, 4, 14, {"a a h"});
make_edit(4, 3, 4, 4, {"ä"});
}
exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1)
eq({
@@ -829,7 +828,7 @@ describe('LSP', function()
'Second line of text';
'Third line of text';
'Fourth line of text';
'a a h';
'å ä ɧ 汉语 ↥ 🤦 🦄';
}, buf_lines(1))
end)
end)