aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/core/startup_spec.lua2
-rw-r--r--test/functional/lua/diagnostic_spec.lua142
-rw-r--r--test/functional/plugin/lsp/diagnostic_spec.lua26
-rw-r--r--test/functional/plugin/lsp_spec.lua42
4 files changed, 182 insertions, 30 deletions
diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua
index f057420dde..ff93f88a2d 100644
--- a/test/functional/core/startup_spec.lua
+++ b/test/functional/core/startup_spec.lua
@@ -472,7 +472,7 @@ describe('user config init', function()
clear{ args_rm={'-u' }, env=xenv }
eq(1, eval('g:lua_rc'))
- eq(init_lua_path, eval('$MYVIMRC'))
+ eq(funcs.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC'))
end)
describe 'with explicitly provided config'(function()
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index e542b02abe..7c5a52827c 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -14,48 +14,32 @@ describe('vim.diagnostic', function()
exec_lua [[
require('vim.diagnostic')
- function make_error(msg, x1, y1, x2, y2)
+ function make_diagnostic(msg, x1, y1, x2, y2, severity, source)
return {
lnum = x1,
col = y1,
end_lnum = x2,
end_col = y2,
message = msg,
- severity = vim.diagnostic.severity.ERROR,
+ severity = severity,
+ source = source,
}
end
- function make_warning(msg, x1, y1, x2, y2)
- return {
- lnum = x1,
- col = y1,
- end_lnum = x2,
- end_col = y2,
- message = msg,
- severity = vim.diagnostic.severity.WARN,
- }
+ function make_error(msg, x1, y1, x2, y2, source)
+ return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.ERROR, source)
end
- function make_info(msg, x1, y1, x2, y2)
- return {
- lnum = x1,
- col = y1,
- end_lnum = x2,
- end_col = y2,
- message = msg,
- severity = vim.diagnostic.severity.INFO,
- }
+ function make_warning(msg, x1, y1, x2, y2, source)
+ return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.WARN, source)
end
- function make_hint(msg, x1, y1, x2, y2)
- return {
- lnum = x1,
- col = y1,
- end_lnum = x2,
- end_col = y2,
- message = msg,
- severity = vim.diagnostic.severity.HINT,
- }
+ function make_info(msg, x1, y1, x2, y2, source)
+ return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.INFO, source)
+ end
+
+ function make_hint(msg, x1, y1, x2, y2, source)
+ return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.HINT, source)
end
function count_diagnostics(bufnr, severity, namespace)
@@ -590,6 +574,63 @@ describe('vim.diagnostic', function()
eq({'Error', 'Warn', 'Info'}, result[1])
eq({'Info', 'Warn', 'Error'}, result[2])
end)
+
+ it('can show diagnostic sources in virtual text', function()
+ local result = exec_lua [[
+ local diagnostics = {
+ make_error('Some error', 0, 0, 0, 0, 'source x'),
+ }
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics, {
+ underline = false,
+ virtual_text = {
+ prefix = '',
+ source = 'always',
+ }
+ })
+
+ local extmarks = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, diagnostic_ns, 0, -1, {details = true})
+ local virt_text = extmarks[1][4].virt_text[2][1]
+ return virt_text
+ ]]
+ eq(' source x: Some error', result)
+
+ result = exec_lua [[
+ vim.diagnostic.config({
+ underline = false,
+ virtual_text = {
+ prefix = '',
+ source = 'if_many',
+ }
+ }, diagnostic_ns)
+
+ local extmarks = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, diagnostic_ns, 0, -1, {details = true})
+ local virt_text = extmarks[1][4].virt_text[2][1]
+ return virt_text
+ ]]
+ eq(' Some error', result)
+
+ result = exec_lua [[
+ local diagnostics = {
+ make_error('Some error', 0, 0, 0, 0, 'source x'),
+ make_error('Another error', 1, 1, 1, 1, 'source y'),
+ }
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics, {
+ underline = false,
+ virtual_text = {
+ prefix = '',
+ source = 'if_many',
+ }
+ })
+
+ local extmarks = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, diagnostic_ns, 0, -1, {details = true})
+ local virt_text = {extmarks[1][4].virt_text[2][1], extmarks[2][4].virt_text[2][1]}
+ return virt_text
+ ]]
+ eq(' source x: Some error', result[1])
+ eq(' source y: Another error', result[2])
+ end)
end)
describe('set()', function()
@@ -854,6 +895,49 @@ describe('vim.diagnostic', function()
return #vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
]])
end)
+
+ it('can show diagnostic source', function()
+ exec_lua [[vim.api.nvim_win_set_buf(0, diagnostic_bufnr)]]
+
+ eq({"1. Syntax error"}, exec_lua [[
+ local diagnostics = {
+ make_error("Syntax error", 0, 1, 0, 3, "source x"),
+ }
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
+ local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics {
+ show_header = false,
+ source = "if_many",
+ }
+ local lines = vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return lines
+ ]])
+
+ eq({"1. source x: Syntax error"}, exec_lua [[
+ local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics {
+ show_header = false,
+ source = "always",
+ }
+ local lines = vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return lines
+ ]])
+
+ eq({"1. source x: Syntax error", "2. source y: Another error"}, exec_lua [[
+ local diagnostics = {
+ make_error("Syntax error", 0, 1, 0, 3, "source x"),
+ make_error("Another error", 0, 1, 0, 3, "source y"),
+ }
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
+ local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics {
+ show_header = false,
+ source = "if_many",
+ }
+ local lines = vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return lines
+ ]])
+ end)
end)
describe('set_signs()', function()
diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua
index 353de667ea..243ad6bdb8 100644
--- a/test/functional/plugin/lsp/diagnostic_spec.lua
+++ b/test/functional/plugin/lsp/diagnostic_spec.lua
@@ -428,6 +428,32 @@ describe('vim.lsp.diagnostic', function()
end)
end)
end)
+
+ it('maintains LSP information when translating diagnostics', function()
+ local result = exec_lua [[
+ local diagnostics = {
+ make_error("Error 1", 1, 1, 1, 5),
+ }
+
+ diagnostics[1].code = 42
+ diagnostics[1].tags = {"foo", "bar"}
+ diagnostics[1].data = "Hello world"
+
+ vim.lsp.diagnostic.on_publish_diagnostics(nil, {
+ uri = fake_uri,
+ diagnostics = diagnostics,
+ }, {client_id=1})
+
+ return {
+ vim.diagnostic.get(diagnostic_bufnr, {lnum=1})[1],
+ vim.lsp.diagnostic.get_line_diagnostics(diagnostic_bufnr, 1)[1],
+ }
+ ]]
+ eq({code = 42, tags = {"foo", "bar"}, data = "Hello world"}, result[1].user_data.lsp)
+ eq(42, result[2].code)
+ eq({"foo", "bar"}, result[2].tags)
+ eq("Hello world", result[2].data)
+ end)
end)
describe("vim.lsp.diagnostic.get_line_diagnostics", function()
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 6ad37110c7..27f2d2536f 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -2353,6 +2353,10 @@ describe('LSP', function()
eq(0, signal, "exit signal", fake_lsp_logfile)
end;
on_handler = function(err, result, ctx)
+ -- Don't compare & assert params, they're not relevant for the testcase
+ -- This allows us to be lazy and avoid declaring them
+ ctx.params = nil
+
eq(table.remove(test.expected_handlers), {err, result, ctx}, "expected handler")
if ctx.method == 'start' then
exec_lua("vim.lsp.buf.rename()")
@@ -2370,4 +2374,42 @@ describe('LSP', function()
end
end)
+ describe('vim.lsp.buf.code_action', function()
+ it('Calls client side command if available', function()
+ eq(1, exec_lua [[
+ local dummy_calls = 0
+ vim.lsp.commands.dummy = function()
+ dummy_calls = dummy_calls + 1
+ end
+ local actions = {
+ {
+ title = 'Dummy command',
+ command = 'dummy',
+ },
+ }
+ -- inputlist would require input and block the test;
+ vim.fn.inputlist = function()
+ return 1
+ end
+ local params = {}
+ local handler = require'vim.lsp.handlers'['textDocument/codeAction']
+ handler(nil, actions, { method = 'textDocument/codeAction', params = params }, nil)
+ return dummy_calls
+ ]])
+ end)
+ end)
+ describe('vim.lsp.commands', function()
+ it('Accepts only string keys', function()
+ matches(
+ '.*The key for commands in `vim.lsp.commands` must be a string',
+ pcall_err(exec_lua, 'vim.lsp.commands[1] = function() end')
+ )
+ end)
+ it('Accepts only function values', function()
+ matches(
+ '.*Command added to `vim.lsp.commands` must be a function',
+ pcall_err(exec_lua, 'vim.lsp.commands.dummy = 10')
+ )
+ end)
+ end)
end)