diff options
author | Michael Lingelbach <m.j.lbach@gmail.com> | 2022-03-06 07:52:11 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-06 07:52:11 -0800 |
commit | 3800615da9eaf9e8b26d9040c882c74084d688e4 (patch) | |
tree | bb2388a2c25a7d7d02d139a4890abfb31fba74d3 | |
parent | 24d56116f70fff655282169ad010298349e0023b (diff) | |
download | rneovim-3800615da9eaf9e8b26d9040c882c74084d688e4.tar.gz rneovim-3800615da9eaf9e8b26d9040c882c74084d688e4.tar.bz2 rneovim-3800615da9eaf9e8b26d9040c882c74084d688e4.zip |
fix(lsp): handle insertion of previous line (#17618)
-rw-r--r-- | runtime/lua/vim/lsp/sync.lua | 14 | ||||
-rw-r--r-- | test/functional/plugin/lsp/incremental_sync_spec.lua | 19 |
2 files changed, 30 insertions, 3 deletions
diff --git a/runtime/lua/vim/lsp/sync.lua b/runtime/lua/vim/lsp/sync.lua index e500be46c2..9955fff3e2 100644 --- a/runtime/lua/vim/lsp/sync.lua +++ b/runtime/lua/vim/lsp/sync.lua @@ -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_lastline. if firstline == lastline then + local line_idx local line = prev_lines[firstline - 1] - byte_idx = #line + 1 - char_idx = compute_line_length(line, offset_encoding) + 1 - return { line_idx = firstline - 1, byte_idx = byte_idx, char_idx = char_idx } + if line then + line_idx = firstline - 1 + byte_idx = #line + 1 + char_idx = compute_line_length(line, offset_encoding) + 1 + 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 -- If firstline == new_lastline, the first change occurred on a line that was deleted. diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua index da54f3c649..4985da9cd7 100644 --- a/test/functional/plugin/lsp/incremental_sync_spec.lua +++ b/test/functional/plugin/lsp/incremental_sync_spec.lua @@ -259,6 +259,25 @@ describe('incremental synchronization', function() } test_edit({""}, {"o"}, expected_text_changes, 'utf-16', '\n') 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) describe('multi line edit', function() it('deletion and insertion', function() |