diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/lua/diagnostic_spec.lua | 267 | ||||
-rw-r--r-- | test/functional/plugin/lsp/incremental_sync_spec.lua | 150 |
2 files changed, 364 insertions, 53 deletions
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index bd513208e8..6414483c0d 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -271,6 +271,8 @@ describe('vim.diagnostic', function() describe('show() and hide()', function() it('works', function() local result = exec_lua [[ + local other_bufnr = vim.api.nvim_create_buf(true, false) + vim.api.nvim_win_set_buf(0, diagnostic_bufnr) local result = {} @@ -284,36 +286,279 @@ describe('vim.diagnostic', function() local ns_2_diags = { make_warning("Warning 1", 2, 1, 2, 5), } + local other_buffer_diags = { + make_info("This is interesting", 0, 0, 0, 0) + } vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diags) vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diags) + vim.diagnostic.set(diagnostic_ns, other_bufnr, other_buffer_diags) - -- Both - table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + count_extmarks(diagnostic_bufnr, other_ns)) + -- All buffers and namespaces + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) -- Hide one namespace vim.diagnostic.hide(diagnostic_ns) - table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns)) + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) -- Show one namespace vim.diagnostic.show(diagnostic_ns) - table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns)) + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) - -- Hide all namespaces + -- Hide one buffer + vim.diagnostic.hide(nil, other_bufnr) + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) + + -- Hide everything vim.diagnostic.hide() - table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + count_extmarks(diagnostic_bufnr, other_ns)) + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) + + -- Show one buffer + vim.diagnostic.show(nil, diagnostic_bufnr) + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) + + return result + ]] + + eq(4, result[1]) + eq(1, result[2]) + eq(4, result[3]) + eq(3, result[4]) + eq(0, result[5]) + eq(3, result[6]) + end) + end) + + describe('enable() and disable()', function() + it('works without arguments', function() + local result = exec_lua [[ + vim.api.nvim_win_set_buf(0, diagnostic_bufnr) + + local result = {} + + vim.diagnostic.config({ underline = false, virtual_text = true }) + + local ns_1_diags = { + make_error("Error 1", 1, 1, 1, 5), + make_warning("Warning on Server 1", 2, 1, 2, 5), + } + local ns_2_diags = { + make_warning("Warning 1", 2, 1, 2, 5), + } + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diags) + vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diags) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns)) + + vim.diagnostic.disable() + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns)) + + -- Create a new buffer + local other_bufnr = vim.api.nvim_create_buf(true, false) + local other_buffer_diags = { + make_info("This is interesting", 0, 0, 0, 0) + } - -- Show all namespaces - vim.diagnostic.show() - table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + count_extmarks(diagnostic_bufnr, other_ns)) + vim.diagnostic.set(diagnostic_ns, other_bufnr, other_buffer_diags) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) + + vim.diagnostic.enable() + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) return result ]] eq(3, result[1]) eq(0, result[2]) - eq(2, result[3]) - eq(0, result[4]) + eq(0, result[3]) + eq(4, result[4]) + end) + + it('works with only a buffer argument', function() + local result = exec_lua [[ + local other_bufnr = vim.api.nvim_create_buf(true, false) + + vim.api.nvim_win_set_buf(0, diagnostic_bufnr) + + local result = {} + + vim.diagnostic.config({ underline = false, virtual_text = true }) + + local ns_1_diags = { + make_error("Error 1", 1, 1, 1, 5), + make_warning("Warning on Server 1", 2, 1, 2, 5), + } + local ns_2_diags = { + make_warning("Warning 1", 2, 1, 2, 5), + } + local other_buffer_diags = { + make_info("This is interesting", 0, 0, 0, 0) + } + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diags) + vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diags) + vim.diagnostic.set(diagnostic_ns, other_bufnr, other_buffer_diags) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) + + vim.diagnostic.disable(diagnostic_bufnr) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) + + vim.diagnostic.enable(diagnostic_bufnr) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) + + vim.diagnostic.disable(other_bufnr) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) + + return result + ]] + + eq(4, result[1]) + eq(1, result[2]) + eq(4, result[3]) + eq(3, result[4]) + end) + + it('works with only a namespace argument', function() + local result = exec_lua [[ + vim.api.nvim_win_set_buf(0, diagnostic_bufnr) + + local result = {} + + vim.diagnostic.config({ underline = false, virtual_text = true }) + + local ns_1_diags = { + make_error("Error 1", 1, 1, 1, 5), + make_warning("Warning on Server 1", 2, 1, 2, 5), + } + local ns_2_diags = { + make_warning("Warning 1", 2, 1, 2, 5), + } + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diags) + vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diags) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns)) + + vim.diagnostic.disable(nil, diagnostic_ns) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns)) + + vim.diagnostic.enable(nil, diagnostic_ns) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns)) + + vim.diagnostic.disable(nil, other_ns) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns)) + + return result + ]] + + eq(3, result[1]) + eq(1, result[2]) + eq(3, result[3]) + eq(2, result[4]) + end) + + it('works with both a buffer and a namespace argument', function() + local result = exec_lua [[ + local other_bufnr = vim.api.nvim_create_buf(true, false) + + vim.api.nvim_win_set_buf(0, diagnostic_bufnr) + + local result = {} + + vim.diagnostic.config({ underline = false, virtual_text = true }) + + local ns_1_diags = { + make_error("Error 1", 1, 1, 1, 5), + make_warning("Warning on Server 1", 2, 1, 2, 5), + } + local ns_2_diags = { + make_warning("Warning 1", 2, 1, 2, 5), + } + local other_buffer_diags = { + make_info("This is interesting", 0, 0, 0, 0) + } + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diags) + vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diags) + vim.diagnostic.set(diagnostic_ns, other_bufnr, other_buffer_diags) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) + + vim.diagnostic.disable(diagnostic_bufnr, diagnostic_ns) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) + + vim.diagnostic.disable(diagnostic_bufnr, other_ns) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) + + vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) + + -- Should have no effect + vim.diagnostic.disable(other_bufnr, other_ns) + + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + + count_extmarks(diagnostic_bufnr, other_ns) + + count_extmarks(other_bufnr, diagnostic_ns)) + + return result + ]] + + eq(4, result[1]) + eq(2, result[2]) + eq(1, result[3]) + eq(3, result[4]) eq(3, result[5]) end) end) diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua index fe4f8f3593..890db4abf5 100644 --- a/test/functional/plugin/lsp/incremental_sync_spec.lua +++ b/test/functional/plugin/lsp/incremental_sync_spec.lua @@ -66,6 +66,7 @@ local function test_edit(prev_buffer, edit_operations, expected_text_changes, of exec_lua("test_unreg = 'test1'") end + describe('incremental synchronization', function() describe('single line edit', function() it('inserting a character in an empty buffer', function() @@ -163,54 +164,119 @@ describe('incremental synchronization', function() } test_edit({"a"}, {"rb"}, expected_text_changes, 'utf-16', '\n') end) - describe('multi-byte edits', function() - it('join and undo', function() - local expected_text_changes = { - { - range = { - ['start'] = { - character = 11, - line = 0 - }, - ['end'] = { - character = 11, - line = 0 - } + end) + + describe('multi-operation edits', function() + it('mult-line substitution', function() + local expected_text_changes = { + { + range = { + ["end"] = { + character = 11, + line = 2 }, + ["start"] = { + character = 10, + line = 2 } }, + rangeLength = 1, + text = '', + },{ + range = { + ["end"] = { + character = 10, + line = 2 }, + start = { + character = 10, + line = 2 } }, + rangeLength = 0, + text = '2', + },{ + range = { + ["end"] = { + character = 11, + line = 3 }, + ["start"] = { + character = 10, + line = 3 } }, + rangeLength = 1, + text = '' + },{ + range = { + ['end'] = { + character = 10, + line = 3 }, + ['start'] = { + character = 10, + line = 3 } }, + rangeLength = 0, + text = '3' }, + { + range = { + ['end'] = { + character = 0, + line = 3 }, + ['start'] = { + character = 12, + line = 2 } }, + rangeLength = 1, + text = '\n' + } + } + local original_lines = { + "\\begin{document}", + "\\section*{1}", + "\\section*{1}", + "\\section*{1}", + "\\end{document}" + } + test_edit(original_lines, {"3gg$h<C-V>jg<C-A>"}, expected_text_changes, 'utf-16', '\n') + end) + it('join and undo', function() + local expected_text_changes = { + { + range = { + ['start'] = { + character = 11, + line = 0 }, - rangeLength = 0, - text = ' test3' - },{ - range = { - ['start'] = { - character = 0, - line = 1 - }, - ['end'] = { - character = 0, - line = 2 - } + ['end'] = { + character = 11, + line = 0 + } + }, + rangeLength = 0, + text = ' test3' + },{ + range = { + ['start'] = { + character = 0, + line = 1 }, - rangeLength = 6, - text = '' - },{ - range = { - ['start'] = { - character = 11, - line = 0 - }, - ['end'] = { - character = 17, - line = 0 - } + ['end'] = { + character = 0, + line = 2 + } + }, + rangeLength = 6, + text = '' + },{ + range = { + ['start'] = { + character = 11, + line = 0 }, - rangeLength = 6, - text = '\ntest3' + ['end'] = { + character = 17, + line = 0 + } }, - } - test_edit({"test1 test2", "test3"}, {"J", "u"}, expected_text_changes, 'utf-16', '\n') - end) + rangeLength = 6, + text = '\ntest3' + }, + } + test_edit({"test1 test2", "test3"}, {"J", "u"}, expected_text_changes, 'utf-16', '\n') end) end) + describe('multi-byte edits', function() it('deleting a multibyte character', function() local expected_text_changes = { |