fix(lsp): out of bounds error in lsp.util.apply_text_edits (#20137)

Co-authored-by: Jonas Strittmatter <40792180+smjonas@users.noreply.github.com>
This commit is contained in:
ofwinterpassed
2022-09-20 22:14:58 +02:00
committed by GitHub
parent 62db91f06c
commit ec94014cd1
2 changed files with 80 additions and 23 deletions

View File

@@ -1719,6 +1719,46 @@ describe('LSP', function()
end)
end)
describe('apply_text_edits regression tests for #20116', function()
before_each(function()
insert(dedent([[
Test line one
Test line two 21 char]]))
end)
describe('with LSP end column out of bounds and start column at 0', function()
it('applies edits at the end of the buffer', function()
local edits = {
make_edit(0, 0, 1, 22, {'#include "whatever.h"\r\n#include <algorithm>\r'});
}
exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8")
eq({'#include "whatever.h"', '#include <algorithm>'}, buf_lines(1))
end)
it('applies edits in the middle of the buffer', function()
local edits = {
make_edit(0, 0, 0, 22, {'#include "whatever.h"\r\n#include <algorithm>\r'});
}
exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8")
eq({'#include "whatever.h"', '#include <algorithm>', 'Test line two 21 char'}, buf_lines(1))
end)
end)
describe('with LSP end column out of bounds and start column NOT at 0', function()
it('applies edits at the end of the buffer', function()
local edits = {
make_edit(0, 2, 1, 22, {'#include "whatever.h"\r\n#include <algorithm>\r'});
}
exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8")
eq({'Te#include "whatever.h"', '#include <algorithm>'}, buf_lines(1))
end)
it('applies edits in the middle of the buffer', function()
local edits = {
make_edit(0, 2, 0, 22, {'#include "whatever.h"\r\n#include <algorithm>\r'});
}
exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8")
eq({'Te#include "whatever.h"', '#include <algorithm>', 'Test line two 21 char'}, buf_lines(1))
end)
end)
end)
describe('apply_text_document_edit', function()
local target_bufnr
local text_document_edit = function(editVersion)