aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/lsp
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/plugin/lsp')
-rw-r--r--test/functional/plugin/lsp/diagnostic_spec.lua42
-rw-r--r--test/functional/plugin/lsp/incremental_sync_spec.lua48
-rw-r--r--test/functional/plugin/lsp/snippet_spec.lua134
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)