aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/ex_cmds/source_spec.lua47
-rw-r--r--test/functional/plugin/lsp/diagnostic_spec.lua63
-rw-r--r--test/functional/plugin/lsp_spec.lua14
3 files changed, 124 insertions, 0 deletions
diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua
new file mode 100644
index 0000000000..16d0dfb6a1
--- /dev/null
+++ b/test/functional/ex_cmds/source_spec.lua
@@ -0,0 +1,47 @@
+local helpers = require('test.functional.helpers')(after_each)
+local command = helpers.command
+local insert = helpers.insert
+local eq = helpers.eq
+local clear = helpers.clear
+local meths = helpers.meths
+local feed = helpers.feed
+local feed_command = helpers.feed_command
+
+describe(':source', function()
+ before_each(function()
+ clear()
+ end)
+
+ it('current buffer', function()
+ insert('let a = 2')
+ command('source')
+ eq('2', meths.exec('echo a', true))
+ end)
+
+ it('selection in current buffer', function()
+ insert(
+ 'let a = 2\n'..
+ 'let a = 3\n'..
+ 'let a = 4\n')
+
+ -- Source the 2nd line only
+ feed('ggjV')
+ feed_command(':source')
+ eq('3', meths.exec('echo a', true))
+
+ -- Source from 2nd line to end of file
+ feed('ggjVG')
+ feed_command(':source')
+ eq('4', meths.exec('echo a', true))
+ end)
+
+ it('multiline heredoc command', function()
+ insert(
+ 'lua << EOF\n'..
+ 'y = 4\n'..
+ 'EOF\n')
+
+ command('source')
+ eq('4', meths.exec('echo luaeval("y")', true))
+ end)
+end)
diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua
index 4705a76465..8c91c4ab2c 100644
--- a/test/functional/plugin/lsp/diagnostic_spec.lua
+++ b/test/functional/plugin/lsp/diagnostic_spec.lua
@@ -208,6 +208,69 @@ describe('vim.lsp.diagnostic', function()
]]))
end)
+ describe('reset', function()
+ it('diagnostic count is 0 and displayed diagnostics are 0 after call', function()
+ -- 1 Error (1)
+ -- 1 Warning (2)
+ -- 1 Warning (2) + 1 Warning (1)
+ -- 2 highlights and 2 underlines (since error)
+ -- 1 highlight + 1 underline
+ local all_highlights = {1, 1, 2, 4, 2}
+ eq(all_highlights, exec_lua [[
+ local server_1_diags = {
+ make_error("Error 1", 1, 1, 1, 5),
+ make_warning("Warning on Server 1", 2, 1, 2, 5),
+ }
+ local server_2_diags = {
+ make_warning("Warning 1", 2, 1, 2, 5),
+ }
+
+ vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { uri = fake_uri, diagnostics = server_1_diags }, 1)
+ vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { uri = fake_uri, diagnostics = server_2_diags }, 2)
+ return {
+ vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1),
+ vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", 2),
+ vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", nil),
+ count_of_extmarks_for_client(diagnostic_bufnr, 1),
+ count_of_extmarks_for_client(diagnostic_bufnr, 2),
+ }
+ ]])
+
+ -- Reset diagnostics from server 1
+ exec_lua([[ vim.lsp.diagnostic.reset(1, { [ diagnostic_bufnr ] = { [ 1 ] = true ; [ 2 ] = true } } )]])
+
+ -- Make sure we have the right diagnostic count
+ eq({0, 1, 1, 0, 2} , exec_lua [[
+ local diagnostic_count = {}
+ vim.wait(100, function () diagnostic_count = {
+ vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1),
+ vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", 2),
+ vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", nil),
+ count_of_extmarks_for_client(diagnostic_bufnr, 1),
+ count_of_extmarks_for_client(diagnostic_bufnr, 2),
+ } end )
+ return diagnostic_count
+ ]])
+
+ -- Reset diagnostics from server 2
+ exec_lua([[ vim.lsp.diagnostic.reset(2, { [ diagnostic_bufnr ] = { [ 1 ] = true ; [ 2 ] = true } } )]])
+
+ -- Make sure we have the right diagnostic count
+ eq({0, 0, 0, 0, 0}, exec_lua [[
+ local diagnostic_count = {}
+ vim.wait(100, function () diagnostic_count = {
+ vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1),
+ vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", 2),
+ vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", nil),
+ count_of_extmarks_for_client(diagnostic_bufnr, 1),
+ count_of_extmarks_for_client(diagnostic_bufnr, 2),
+ } end )
+ return diagnostic_count
+ ]])
+
+ end)
+ end)
+
describe('get_next_diagnostic_pos', function()
it('can find the next pos with only one client', function()
eq({1, 1}, exec_lua [[
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 981e2a96a8..cec306eb39 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -1032,6 +1032,20 @@ describe('LSP', function()
'å ä ɧ 汉语 ↥ 🤦 🦄';
}, buf_lines(1))
end)
+ it('applies text edits at the end of the document', function()
+ local edits = {
+ make_edit(5, 0, 5, 0, "foobar");
+ }
+ exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1)
+ eq({
+ 'First line of text';
+ 'Second line of text';
+ 'Third line of text';
+ 'Fourth line of text';
+ 'å å ɧ 汉语 ↥ 🤦 🦄';
+ 'foobar';
+ }, buf_lines(1))
+ end)
describe('with LSP end line after what Vim considers to be the end line', function()
it('applies edits when the last linebreak is considered a new line', function()