fix(lsp): handle insertion of previous line (#17618)

This commit is contained in:
Michael Lingelbach 2022-03-06 07:52:11 -08:00 committed by GitHub
parent 24d56116f7
commit 3800615da9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 3 deletions

View File

@ -138,10 +138,18 @@ local function compute_start_range(prev_lines, curr_lines, firstline, lastline,
-- new lines(O), the new newline is inserted at the line indicated by -- new lines(O), the new newline is inserted at the line indicated by
-- new_lastline. -- new_lastline.
if firstline == lastline then if firstline == lastline then
local line_idx
local line = prev_lines[firstline - 1] local line = prev_lines[firstline - 1]
if line then
line_idx = firstline - 1
byte_idx = #line + 1 byte_idx = #line + 1
char_idx = compute_line_length(line, offset_encoding) + 1 char_idx = compute_line_length(line, offset_encoding) + 1
return { line_idx = firstline - 1, byte_idx = byte_idx, char_idx = char_idx } else
line_idx = firstline
byte_idx = 1
char_idx = 1
end
return { line_idx = line_idx, byte_idx = byte_idx, char_idx = char_idx }
end end
-- If firstline == new_lastline, the first change occurred on a line that was deleted. -- If firstline == new_lastline, the first change occurred on a line that was deleted.

View File

@ -259,6 +259,25 @@ describe('incremental synchronization', function()
} }
test_edit({""}, {"o"}, expected_text_changes, 'utf-16', '\n') test_edit({""}, {"o"}, expected_text_changes, 'utf-16', '\n')
end) end)
it('insert a line above the current line', function()
local expected_text_changes = {
{
range = {
['start'] = {
character = 0,
line = 0
},
['end'] = {
character = 0,
line = 0
}
},
rangeLength = 0,
text = '\n'
}
}
test_edit({""}, {"O"}, expected_text_changes, 'utf-16', '\n')
end)
end) end)
describe('multi line edit', function() describe('multi line edit', function()
it('deletion and insertion', function() it('deletion and insertion', function()