diff options
author | Josh Rahm <rahm@google.com> | 2022-07-18 19:37:18 +0000 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2022-07-18 19:37:18 +0000 |
commit | 308e1940dcd64aa6c344c403d4f9e0dda58d9c5c (patch) | |
tree | 35fe43e01755e0f312650667004487a44d6b7941 /test/functional/plugin/lsp | |
parent | 96a00c7c588b2f38a2424aeeb4ea3581d370bf2d (diff) | |
parent | e8c94697bcbe23a5c7b07c292b90a6b70aadfa87 (diff) | |
download | rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.tar.gz rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.tar.bz2 rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.zip |
Merge remote-tracking branch 'upstream/master' into rahm
Diffstat (limited to 'test/functional/plugin/lsp')
-rw-r--r-- | test/functional/plugin/lsp/diagnostic_spec.lua | 42 | ||||
-rw-r--r-- | test/functional/plugin/lsp/incremental_sync_spec.lua | 48 | ||||
-rw-r--r-- | test/functional/plugin/lsp/snippet_spec.lua | 134 |
3 files changed, 193 insertions, 31 deletions
diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua index 1269a2350c..f73ffc29b0 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -3,6 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local exec_lua = helpers.exec_lua local eq = helpers.eq +local neq = require('test.helpers').neq describe('vim.lsp.diagnostic', function() local fake_uri @@ -110,6 +111,7 @@ describe('vim.lsp.diagnostic', function() } ]] eq({code = 42, tags = {"foo", "bar"}, data = "Hello world"}, result[1].user_data.lsp) + eq(42, result[1].code) eq(42, result[2].code) eq({"foo", "bar"}, result[2].tags) eq("Hello world", result[2].data) @@ -219,12 +221,50 @@ describe('vim.lsp.diagnostic', function() local diags = vim.diagnostic.get(diagnostic_bufnr) vim.lsp.stop_client(client_id) - vim.lsp._vim_exit_handler() + vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false }) return diags ]], line) eq(1, #result) eq(exec_lua([[return vim.str_byteindex(..., 7, true)]], line), result[1].col) eq(exec_lua([[return vim.str_byteindex(..., 8, true)]], line), result[1].end_col) end) + + it('does not create buffer on empty diagnostics', function() + local bufnr + + -- No buffer is created without diagnostics + bufnr = exec_lua [[ + vim.lsp.diagnostic.on_publish_diagnostics(nil, { + uri = "file:///fake/uri2", + diagnostics = {}, + }, {client_id=client_id}) + return vim.fn.bufnr(vim.uri_to_fname("file:///fake/uri2")) + ]] + eq(bufnr, -1) + + -- Create buffer on diagnostics + bufnr = exec_lua [[ + vim.lsp.diagnostic.on_publish_diagnostics(nil, { + uri = "file:///fake/uri2", + diagnostics = { + make_error('Diagnostic', 0, 0, 0, 0), + }, + }, {client_id=client_id}) + return vim.fn.bufnr(vim.uri_to_fname("file:///fake/uri2")) + ]] + neq(bufnr, -1) + eq(exec_lua([[return #vim.diagnostic.get(...)]], bufnr), 1) + + -- Clear diagnostics after buffer was created + bufnr = exec_lua [[ + vim.lsp.diagnostic.on_publish_diagnostics(nil, { + uri = "file:///fake/uri2", + diagnostics = {}, + }, {client_id=client_id}) + return vim.fn.bufnr(vim.uri_to_fname("file:///fake/uri2")) + ]] + neq(bufnr, -1) + eq(exec_lua([[return #vim.diagnostic.get(...)]], bufnr), 0) + end) end) end) diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua index 4e3eddb960..4985da9cd7 100644 --- a/test/functional/plugin/lsp/incremental_sync_spec.lua +++ b/test/functional/plugin/lsp/incremental_sync_spec.lua @@ -207,16 +207,16 @@ describe('incremental synchronization', function() { range = { ['start'] = { - character = 0, - line = 1 + character = 11, + line = 0, }, ['end'] = { character = 0, line = 1 } }, - rangeLength = 0, - text = 'hello world\n' + rangeLength = 1, + text = '\nhello world\n' } } test_edit({"hello world"}, {"yyp"}, expected_text_changes, 'utf-16', '\n') @@ -226,19 +226,57 @@ describe('incremental synchronization', function() { range = { ['start'] = { + character = 11, + line = 0 + }, + ['end'] = { character = 0, line = 1 + } + }, + rangeLength = 1, + text = '\n\n' + } + } + test_edit({"hello world"}, {"o"}, expected_text_changes, 'utf-16', '\n') + end) + it('adding a line to an empty buffer', function() + local expected_text_changes = { + { + range = { + ['start'] = { + character = 0, + line = 0 }, ['end'] = { character = 0, line = 1 } }, + rangeLength = 1, + text = '\n\n' + } + } + 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({"hello world"}, {"o"}, expected_text_changes, 'utf-16', '\n') + test_edit({""}, {"O"}, expected_text_changes, 'utf-16', '\n') end) end) describe('multi line edit', function() diff --git a/test/functional/plugin/lsp/snippet_spec.lua b/test/functional/plugin/lsp/snippet_spec.lua index 4e127743eb..7903885420 100644 --- a/test/functional/plugin/lsp/snippet_spec.lua +++ b/test/functional/plugin/lsp/snippet_spec.lua @@ -19,9 +19,9 @@ describe('vim.lsp._snippet', function() { type = snippet.NodeType.TEXT, raw = 'TE\\$\\}XT', - esc = 'TE$}XT' - } - } + esc = 'TE$}XT', + }, + }, }, parse('TE\\$\\}XT')) end) @@ -36,8 +36,8 @@ describe('vim.lsp._snippet', function() { type = snippet.NodeType.TABSTOP, tabstop = 2, - } - } + }, + }, }, parse('$1${2}')) end) @@ -56,7 +56,7 @@ describe('vim.lsp._snippet', function() { type = snippet.NodeType.TEXT, raw = 'TE\\$\\}XT', - esc = 'TE$}XT' + esc = 'TE$}XT', }, { type = snippet.NodeType.TABSTOP, @@ -73,21 +73,21 @@ describe('vim.lsp._snippet', function() { type = snippet.NodeType.FORMAT, capture_index = 1, - modifier = 'upcase' - } - } + modifier = 'upcase', + }, + }, }, }, { type = snippet.NodeType.TEXT, raw = 'TE\\$\\}XT', - esc = 'TE$}XT' + esc = 'TE$}XT', }, - } - } - } + }, + }, + }, }, - } + }, }, parse('${1:${2:TE\\$\\}XT$3${1/regex/${1:/upcase}/i}TE\\$\\}XT}}')) end) @@ -110,8 +110,8 @@ describe('vim.lsp._snippet', function() { type = snippet.NodeType.TABSTOP, tabstop = 1, - } - } + }, + }, }, { type = snippet.NodeType.VARIABLE, @@ -124,11 +124,11 @@ describe('vim.lsp._snippet', function() type = snippet.NodeType.FORMAT, capture_index = 1, modifier = 'upcase', - } - } - } + }, + }, + }, }, - } + }, }, parse('$VAR${VAR}${VAR:$1}${VAR/regex/${1:/upcase}/}')) end) @@ -141,12 +141,96 @@ describe('vim.lsp._snippet', function() tabstop = 1, items = { ',', - '|' - } - } - } + '|', + }, + }, + }, }, parse('${1|\\,,\\||}')) end) -end) + it('should parse format', function() + eq({ + type = snippet.NodeType.SNIPPET, + children = { + { + type = snippet.NodeType.VARIABLE, + name = 'VAR', + transform = { + type = snippet.NodeType.TRANSFORM, + pattern = 'regex', + format = { + { + type = snippet.NodeType.FORMAT, + capture_index = 1, + modifier = 'upcase', + }, + { + type = snippet.NodeType.FORMAT, + capture_index = 1, + if_text = 'if_text', + else_text = '', + }, + { + type = snippet.NodeType.FORMAT, + capture_index = 1, + if_text = '', + else_text = 'else_text', + }, + { + type = snippet.NodeType.FORMAT, + capture_index = 1, + else_text = 'else_text', + if_text = 'if_text', + }, + { + type = snippet.NodeType.FORMAT, + capture_index = 1, + if_text = '', + else_text = 'else_text', + }, + }, + }, + }, + }, + }, parse('${VAR/regex/${1:/upcase}${1:+if_text}${1:-else_text}${1:?if_text:else_text}${1:else_text}/}')) + end) + it('should parse empty strings', function() + eq({ + children = { + { + children = { { + esc = '', + raw = '', + type = 7, + } }, + tabstop = 1, + type = 2, + }, + { + esc = ' ', + raw = ' ', + type = 7, + }, + { + name = 'VAR', + transform = { + format = { + { + capture_index = 1, + else_text = '', + if_text = '', + type = 6, + }, + }, + option = 'g', + pattern = 'erg', + type = 5, + }, + type = 3, + }, + }, + type = 0, + }, parse('${1:} ${VAR/erg/${1:?:}/g}')) + end) +end) |