mirror of
https://github.com/neovim/neovim.git
synced 2025-12-04 21:52:41 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user