aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/lsp
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-05-24 19:18:11 +0000
committerJosh Rahm <joshuarahm@gmail.com>2024-05-24 19:18:11 +0000
commitff7ed8f586589d620a806c3758fac4a47a8e7e15 (patch)
tree729bbcb92231538fa61dab6c3d890b025484b7f5 /test/functional/plugin/lsp
parent376914f419eb08fdf4c1a63a77e1f035898a0f10 (diff)
parent28c04948a1c887a1cc0cb64de79fa32631700466 (diff)
downloadrneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.gz
rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.bz2
rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'test/functional/plugin/lsp')
-rw-r--r--test/functional/plugin/lsp/codelens_spec.lua11
-rw-r--r--test/functional/plugin/lsp/completion_spec.lua10
-rw-r--r--test/functional/plugin/lsp/diagnostic_spec.lua26
-rw-r--r--test/functional/plugin/lsp/handler_spec.lua11
-rw-r--r--test/functional/plugin/lsp/incremental_sync_spec.lua13
-rw-r--r--test/functional/plugin/lsp/inlay_hint_spec.lua122
-rw-r--r--test/functional/plugin/lsp/semantic_tokens_spec.lua194
-rw-r--r--test/functional/plugin/lsp/snippet_spec.lua12
-rw-r--r--test/functional/plugin/lsp/testutil.lua (renamed from test/functional/plugin/lsp/helpers.lua)44
-rw-r--r--test/functional/plugin/lsp/utils_spec.lua13
10 files changed, 322 insertions, 134 deletions
diff --git a/test/functional/plugin/lsp/codelens_spec.lua b/test/functional/plugin/lsp/codelens_spec.lua
index 29daf7a066..cd20e95dd1 100644
--- a/test/functional/plugin/lsp/codelens_spec.lua
+++ b/test/functional/plugin/lsp/codelens_spec.lua
@@ -1,14 +1,15 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
-local exec_lua = helpers.exec_lua
-local eq = helpers.eq
+local exec_lua = n.exec_lua
+local eq = t.eq
describe('vim.lsp.codelens', function()
before_each(function()
- helpers.clear()
+ n.clear()
exec_lua('require("vim.lsp")')
end)
- after_each(helpers.clear)
+ after_each(n.clear)
it('on_codelens_stores_and_displays_lenses', function()
local fake_uri = 'file:///fake/uri'
diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua
index 655eb76be6..2798d57381 100644
--- a/test/functional/plugin/lsp/completion_spec.lua
+++ b/test/functional/plugin/lsp/completion_spec.lua
@@ -1,7 +1,9 @@
---@diagnostic disable: no-unknown
-local helpers = require('test.functional.helpers')(after_each)
-local eq = helpers.eq
-local exec_lua = helpers.exec_lua
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
+local eq = t.eq
+local exec_lua = n.exec_lua
--- Convert completion results.
---
@@ -41,7 +43,7 @@ local function complete(line, candidates, lnum)
end
describe('vim.lsp._completion', function()
- before_each(helpers.clear)
+ before_each(n.clear)
-- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
it('prefers textEdit over label as word', function()
diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua
index 705c182df7..c5e14ffdc2 100644
--- a/test/functional/plugin/lsp/diagnostic_spec.lua
+++ b/test/functional/plugin/lsp/diagnostic_spec.lua
@@ -1,12 +1,14 @@
-local helpers = require('test.functional.helpers')(after_each)
-local lsp_helpers = require('test.functional.plugin.lsp.helpers')
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
-local clear = helpers.clear
-local exec_lua = helpers.exec_lua
-local eq = helpers.eq
-local neq = require('test.helpers').neq
+local t_lsp = require('test.functional.plugin.lsp.testutil')
-local create_server_definition = lsp_helpers.create_server_definition
+local clear = n.clear
+local exec_lua = n.exec_lua
+local eq = t.eq
+local neq = t.neq
+
+local create_server_definition = t_lsp.create_server_definition
describe('vim.lsp.diagnostic', function()
local fake_uri
@@ -257,7 +259,7 @@ describe('vim.lsp.diagnostic', function()
}, {client_id=client_id})
return vim.fn.bufnr(vim.uri_to_fname("file:///fake/uri2"))
]]
- eq(bufnr, -1)
+ eq(-1, bufnr)
-- Create buffer on diagnostics
bufnr = exec_lua [[
@@ -269,8 +271,8 @@ describe('vim.lsp.diagnostic', function()
}, {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)
+ neq(-1, bufnr)
+ eq(1, exec_lua([[return #vim.diagnostic.get(...)]], bufnr))
-- Clear diagnostics after buffer was created
bufnr = exec_lua [[
@@ -280,8 +282,8 @@ describe('vim.lsp.diagnostic', function()
}, {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)
+ neq(-1, bufnr)
+ eq(0, exec_lua([[return #vim.diagnostic.get(...)]], bufnr))
end)
end)
diff --git a/test/functional/plugin/lsp/handler_spec.lua b/test/functional/plugin/lsp/handler_spec.lua
index 56e29e7337..013a5fb5e7 100644
--- a/test/functional/plugin/lsp/handler_spec.lua
+++ b/test/functional/plugin/lsp/handler_spec.lua
@@ -1,9 +1,10 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
-local eq = helpers.eq
-local exec_lua = helpers.exec_lua
-local pcall_err = helpers.pcall_err
-local matches = helpers.matches
+local eq = t.eq
+local exec_lua = n.exec_lua
+local pcall_err = t.pcall_err
+local matches = t.matches
describe('lsp-handlers', function()
describe('vim.lsp._with_extend', function()
diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua
index bd1842ceb5..238b90b57d 100644
--- a/test/functional/plugin/lsp/incremental_sync_spec.lua
+++ b/test/functional/plugin/lsp/incremental_sync_spec.lua
@@ -1,11 +1,12 @@
-- Test suite for testing interactions with the incremental sync algorithms powering the LSP client
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
-local api = helpers.api
-local clear = helpers.clear
-local eq = helpers.eq
-local exec_lua = helpers.exec_lua
-local feed = helpers.feed
+local api = n.api
+local clear = n.clear
+local eq = t.eq
+local exec_lua = n.exec_lua
+local feed = n.feed
before_each(function()
clear()
diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua
index 192797b312..d3b5ae0e4e 100644
--- a/test/functional/plugin/lsp/inlay_hint_spec.lua
+++ b/test/functional/plugin/lsp/inlay_hint_spec.lua
@@ -1,14 +1,16 @@
-local helpers = require('test.functional.helpers')(after_each)
-local lsp_helpers = require('test.functional.plugin.lsp.helpers')
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
+local t_lsp = require('test.functional.plugin.lsp.testutil')
-local eq = helpers.eq
-local dedent = helpers.dedent
-local exec_lua = helpers.exec_lua
-local insert = helpers.insert
+local eq = t.eq
+local dedent = t.dedent
+local exec_lua = n.exec_lua
+local insert = n.insert
+local api = n.api
-local clear_notrace = lsp_helpers.clear_notrace
-local create_server_definition = lsp_helpers.create_server_definition
+local clear_notrace = t_lsp.clear_notrace
+local create_server_definition = t_lsp.create_server_definition
local text = dedent([[
auto add(int a, int b) { return a + b; }
@@ -41,12 +43,12 @@ local grid_without_inlay_hints = [[
]]
local grid_with_inlay_hints = [[
- auto add(int a, int b)-> int { return a + b; } |
+ auto add(int a, int b){1:-> int} { return a + b; } |
|
int main() { |
int x = 1; |
int y = 2; |
- return add(a: x,b: y); |
+ return add({1:a:} x,{1:b:} y); |
} |
^} |
|
@@ -68,8 +70,8 @@ before_each(function()
inlayHintProvider = true,
},
handlers = {
- ['textDocument/inlayHint'] = function()
- return vim.json.decode(response)
+ ['textDocument/inlayHint'] = function(_, _, callback)
+ callback(nil, vim.json.decode(response))
end,
}
})
@@ -83,12 +85,12 @@ before_each(function()
)
insert(text)
- exec_lua([[vim.lsp.inlay_hint.enable(bufnr)]])
+ exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]])
screen:expect({ grid = grid_with_inlay_hints })
end)
after_each(function()
- exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })")
+ api.nvim_exec_autocmds('VimLeavePre', { modeline = false })
end)
describe('vim.lsp.inlay_hint', function()
@@ -104,13 +106,13 @@ describe('vim.lsp.inlay_hint', function()
inlayHintProvider = true,
},
handlers = {
- ['textDocument/inlayHint'] = function()
- return {}
+ ['textDocument/inlayHint'] = function(_, _, callback)
+ callback(nil, {})
end,
}
})
client2 = vim.lsp.start({ name = 'dummy2', cmd = server2.cmd })
- vim.lsp.inlay_hint.enable(bufnr)
+ vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
]])
exec_lua([[ vim.lsp.stop_client(client2) ]])
@@ -118,18 +120,66 @@ describe('vim.lsp.inlay_hint', function()
end)
describe('enable()', function()
- it('clears/applies inlay hints when passed false/true/nil', function()
- exec_lua([[vim.lsp.inlay_hint.enable(bufnr, false)]])
- screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
+ it('validation', function()
+ t.matches(
+ 'enable: expected boolean, got table',
+ t.pcall_err(exec_lua, [[vim.lsp.inlay_hint.enable({}, { bufnr = bufnr })]])
+ )
+ t.matches(
+ 'enable: expected boolean, got number',
+ t.pcall_err(exec_lua, [[vim.lsp.inlay_hint.enable(42)]])
+ )
+ t.matches(
+ 'filter: expected table, got number',
+ t.pcall_err(exec_lua, [[vim.lsp.inlay_hint.enable(true, 42)]])
+ )
+ end)
+
+ describe('clears/applies inlay hints when passed false/true/nil', function()
+ before_each(function()
+ exec_lua([[
+ bufnr2 = vim.api.nvim_create_buf(true, false)
+ vim.lsp.buf_attach_client(bufnr2, client_id)
+ vim.api.nvim_win_set_buf(0, bufnr2)
+ ]])
+ insert(text)
+ exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr2 })]])
+ exec_lua([[vim.api.nvim_win_set_buf(0, bufnr)]])
+ screen:expect({ grid = grid_with_inlay_hints })
+ end)
+
+ it('for one single buffer', function()
+ exec_lua([[
+ vim.lsp.inlay_hint.enable(false, { bufnr = bufnr })
+ vim.api.nvim_win_set_buf(0, bufnr2)
+ ]])
+ screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+ exec_lua([[vim.api.nvim_win_set_buf(0, bufnr)]])
+ screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
- exec_lua([[vim.lsp.inlay_hint.enable(bufnr, true)]])
- screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+ exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]])
+ screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
- exec_lua([[vim.lsp.inlay_hint.enable(bufnr, not vim.lsp.inlay_hint.is_enabled(bufnr))]])
- screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
+ exec_lua(
+ [[vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr })]]
+ )
+ screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
- exec_lua([[vim.lsp.inlay_hint.enable(bufnr)]])
- screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+ exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]])
+ screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+ end)
+
+ it('for all buffers', function()
+ exec_lua([[vim.lsp.inlay_hint.enable(false)]])
+ screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
+ exec_lua([[vim.api.nvim_win_set_buf(0, bufnr2)]])
+ screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
+
+ exec_lua([[vim.lsp.inlay_hint.enable(true)]])
+ screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+ exec_lua([[vim.api.nvim_win_set_buf(0, bufnr)]])
+ screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+ end)
end)
end)
@@ -156,25 +206,25 @@ describe('vim.lsp.inlay_hint', function()
inlayHintProvider = true,
},
handlers = {
- ['textDocument/inlayHint'] = function()
- return { expected2 }
+ ['textDocument/inlayHint'] = function(_, _, callback)
+ callback(nil, { expected2 })
end,
}
})
client2 = vim.lsp.start({ name = 'dummy2', cmd = server2.cmd })
- vim.lsp.inlay_hint.enable(bufnr)
+ vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
]],
expected2
)
--- @type vim.lsp.inlay_hint.get.ret
local res = exec_lua([[return vim.lsp.inlay_hint.get()]])
- eq(res, {
+ eq({
{ bufnr = 1, client_id = 1, inlay_hint = expected[1] },
{ bufnr = 1, client_id = 1, inlay_hint = expected[2] },
{ bufnr = 1, client_id = 1, inlay_hint = expected[3] },
{ bufnr = 1, client_id = 2, inlay_hint = expected2 },
- })
+ }, res)
--- @type vim.lsp.inlay_hint.get.ret
res = exec_lua([[return vim.lsp.inlay_hint.get({
@@ -183,9 +233,9 @@ describe('vim.lsp.inlay_hint', function()
["end"] = { line = 2, character = 10 },
},
})]])
- eq(res, {
+ eq({
{ bufnr = 1, client_id = 2, inlay_hint = expected2 },
- })
+ }, res)
--- @type vim.lsp.inlay_hint.get.ret
res = exec_lua([[return vim.lsp.inlay_hint.get({
@@ -195,16 +245,16 @@ describe('vim.lsp.inlay_hint', function()
["end"] = { line = 5, character = 17 },
},
})]])
- eq(res, {
+ eq({
{ bufnr = 1, client_id = 1, inlay_hint = expected[2] },
{ bufnr = 1, client_id = 1, inlay_hint = expected[3] },
- })
+ }, res)
--- @type vim.lsp.inlay_hint.get.ret
res = exec_lua([[return vim.lsp.inlay_hint.get({
bufnr = vim.api.nvim_get_current_buf() + 1,
})]])
- eq(res, {})
+ eq({}, res)
end)
end)
end)
diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua
index 77e39c81c8..7908c5d2e7 100644
--- a/test/functional/plugin/lsp/semantic_tokens_spec.lua
+++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua
@@ -1,25 +1,27 @@
-local helpers = require('test.functional.helpers')(after_each)
-local lsp_helpers = require('test.functional.plugin.lsp.helpers')
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
+local t_lsp = require('test.functional.plugin.lsp.testutil')
-local command = helpers.command
-local dedent = helpers.dedent
-local eq = helpers.eq
-local exec_lua = helpers.exec_lua
-local feed = helpers.feed
-local feed_command = helpers.feed_command
-local insert = helpers.insert
-local matches = helpers.matches
+local command = n.command
+local dedent = t.dedent
+local eq = t.eq
+local exec_lua = n.exec_lua
+local feed = n.feed
+local feed_command = n.feed_command
+local insert = n.insert
+local matches = t.matches
+local api = n.api
-local clear_notrace = lsp_helpers.clear_notrace
-local create_server_definition = lsp_helpers.create_server_definition
+local clear_notrace = t_lsp.clear_notrace
+local create_server_definition = t_lsp.create_server_definition
before_each(function()
clear_notrace()
end)
after_each(function()
- exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })")
+ api.nvim_exec_autocmds('VimLeavePre', { modeline = false })
end)
describe('semantic token highlighting', function()
@@ -37,6 +39,8 @@ describe('semantic token highlighting', function()
[7] = { bold = true, foreground = Screen.colors.DarkCyan },
[8] = { bold = true, foreground = Screen.colors.SlateBlue },
[9] = { bold = true, foreground = tonumber('0x6a0dad') },
+ [10] = { bold = true, foreground = Screen.colors.Brown },
+ [11] = { foreground = Screen.colors.Magenta1 },
}
command([[ hi link @lsp.type.namespace Type ]])
command([[ hi link @lsp.type.function Special ]])
@@ -91,11 +95,11 @@ describe('semantic token highlighting', function()
},
},
handlers = {
- ['textDocument/semanticTokens/full'] = function()
- return vim.fn.json_decode(response)
+ ['textDocument/semanticTokens/full'] = function(_, _, callback)
+ callback(nil, vim.fn.json_decode(response))
end,
- ['textDocument/semanticTokens/full/delta'] = function()
- return vim.fn.json_decode(edit_response)
+ ['textDocument/semanticTokens/full/delta'] = function(_, _, callback)
+ callback(nil, vim.fn.json_decode(edit_response))
end,
}
})
@@ -269,6 +273,63 @@ describe('semantic token highlighting', function()
end
)
+ it('highlights start and stop when using "0" for current buffer', function()
+ exec_lua([[
+ bufnr = vim.api.nvim_get_current_buf()
+ vim.api.nvim_win_set_buf(0, bufnr)
+ client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
+ ]])
+
+ insert(text)
+
+ exec_lua([[
+ vim.notify = function() end
+ vim.lsp.semantic_tokens.stop(0, client_id)
+ ]])
+
+ screen:expect {
+ grid = [[
+ #include <iostream> |
+ |
+ int main() |
+ { |
+ int x; |
+ #ifdef __cplusplus |
+ std::cout << x << "\n"; |
+ #else |
+ printf("%d\n", x); |
+ #endif |
+ } |
+ ^} |
+ {1:~ }|*3
+ |
+ ]],
+ }
+
+ exec_lua([[
+ vim.lsp.semantic_tokens.start(0, client_id)
+ ]])
+
+ screen:expect {
+ grid = [[
+ #include <iostream> |
+ |
+ int {8:main}() |
+ { |
+ int {7:x}; |
+ #ifdef {5:__cplusplus} |
+ {4:std}::{2:cout} << {2:x} << "\n"; |
+ {6:#else} |
+ {6: printf("%d\n", x);} |
+ {6:#endif} |
+ } |
+ ^} |
+ {1:~ }|*3
+ |
+ ]],
+ }
+ end)
+
it('buffer is re-highlighted when force refreshed', function()
exec_lua([[
bufnr = vim.api.nvim_get_current_buf()
@@ -499,11 +560,11 @@ describe('semantic token highlighting', function()
},
},
handlers = {
- ['textDocument/semanticTokens/full'] = function()
- return nil
+ ['textDocument/semanticTokens/full'] = function(_, _, callback)
+ callback(nil, nil)
end,
['textDocument/semanticTokens/full/delta'] = function()
- return nil
+ callback(nil, nil)
end,
}
})
@@ -547,11 +608,11 @@ describe('semantic token highlighting', function()
},
},
handlers = {
- ['textDocument/semanticTokens/full'] = function()
- return vim.fn.json_decode(response)
+ ['textDocument/semanticTokens/full'] = function(_, _, callback)
+ callback(nil, vim.fn.json_decode(response))
end,
- ['textDocument/semanticTokens/full/delta'] = function()
- return vim.fn.json_decode(edit_response)
+ ['textDocument/semanticTokens/full/delta'] = function(_, _, callback)
+ callback(nil, vim.fn.json_decode(edit_response))
end,
}
})
@@ -837,11 +898,13 @@ b = "as"]],
{
it = 'rust-analyzer',
text = [[pub fn main() {
- break rust;
- /// what?
+ println!("Hello world!");
+ break rust;
+ /// what?
}
]],
- response = [[{"data": [0, 0, 3, 1, 0, 0, 4, 2, 1, 0, 0, 3, 4, 14, 524290, 0, 4, 1, 45, 0, 0, 1, 1, 45, 0, 0, 2, 1, 26, 0, 1, 4, 5, 1, 8192, 0, 6, 4, 52, 0, 0, 4, 1, 48, 0, 1, 4, 9, 0, 1, 1, 0, 1, 26, 0], "resultId": "1"}]],
+ response = [[{"data": [0, 0, 3, 1, 0, 0, 4, 2, 1, 0, 0, 3, 4, 14, 524290, 0, 4, 1, 45, 0, 0, 1, 1, 45, 0, 0, 2, 1, 26, 0, 1, 4, 8, 17, 0, 0, 8, 1, 45, 0, 0, 1, 14, 2, 0, 0, 14, 1, 45, 0, 0, 1, 1, 48, 0, 1, 4, 5, 1, 8192, 0, 6, 4, 52, 0, 0, 4, 1, 48, 0, 1, 4, 9, 0, 1, 1, 0, 1, 26, 0 ], "resultId": "1"}]],
+
legend = [[{
"tokenTypes": [
"comment", "keyword", "string", "number", "regexp", "operator", "namespace", "type", "struct", "class", "interface", "enum", "enumMember", "typeParameter", "function", "method", "property", "macro", "variable",
@@ -904,6 +967,46 @@ b = "as"]],
},
{
line = 1,
+ modifiers = {},
+ start_col = 4,
+ end_col = 12,
+ type = 'macro', -- println!
+ marked = true,
+ },
+ {
+ line = 1,
+ modifiers = {},
+ start_col = 12,
+ end_col = 13,
+ type = 'parenthesis',
+ marked = true,
+ },
+ {
+ line = 1,
+ modifiers = {},
+ start_col = 13,
+ end_col = 27,
+ type = 'string', -- "Hello world!"
+ marked = true,
+ },
+ {
+ line = 1,
+ modifiers = {},
+ start_col = 27,
+ end_col = 28,
+ type = 'parenthesis',
+ marked = true,
+ },
+ {
+ line = 1,
+ modifiers = {},
+ start_col = 28,
+ end_col = 29,
+ type = 'semicolon',
+ marked = true,
+ },
+ {
+ line = 2,
modifiers = { controlFlow = true },
start_col = 4,
end_col = 9, -- break
@@ -911,31 +1014,31 @@ b = "as"]],
marked = true,
},
{
- line = 1,
+ line = 2,
modifiers = {},
start_col = 10,
- end_col = 13, -- rust
+ end_col = 14, -- rust
type = 'unresolvedReference',
marked = true,
},
{
- line = 1,
+ line = 2,
modifiers = {},
- start_col = 13,
- end_col = 13,
+ start_col = 14,
+ end_col = 15,
type = 'semicolon',
marked = true,
},
{
- line = 2,
+ line = 3,
modifiers = { documentation = true },
start_col = 4,
- end_col = 11,
+ end_col = 13,
type = 'comment', -- /// what?
marked = true,
},
{
- line = 3,
+ line = 4,
modifiers = {},
start_col = 0,
end_col = 1,
@@ -946,12 +1049,13 @@ b = "as"]],
expected_screen = function()
screen:expect {
grid = [[
- pub fn {8:main}() { |
- break rust; |
- //{6:/ what?} |
+ {10:pub} {10:fn} {8:main}() { |
+ {5:println!}({11:"Hello world!"}); |
+ {10:break} rust; |
+ {6:/// what?} |
} |
^ |
- {1:~ }|*10
+ {1:~ }|*9
|
]],
}
@@ -971,8 +1075,8 @@ b = "as"]],
},
},
handlers = {
- ['textDocument/semanticTokens/full'] = function()
- return vim.fn.json_decode(resp)
+ ['textDocument/semanticTokens/full'] = function(_, _, callback)
+ callback(nil, vim.fn.json_decode(resp))
end,
}
})
@@ -1357,11 +1461,11 @@ int main()
},
},
handlers = {
- ['textDocument/semanticTokens/full'] = function()
- return vim.fn.json_decode(resp1)
+ ['textDocument/semanticTokens/full'] = function(_, _, callback)
+ callback(nil, vim.fn.json_decode(resp1))
end,
- ['textDocument/semanticTokens/full/delta'] = function()
- return vim.fn.json_decode(resp2)
+ ['textDocument/semanticTokens/full/delta'] = function(_, _, callback)
+ callback(nil, vim.fn.json_decode(resp2))
end,
}
})
diff --git a/test/functional/plugin/lsp/snippet_spec.lua b/test/functional/plugin/lsp/snippet_spec.lua
index ba8bc7fe04..e60c36cd23 100644
--- a/test/functional/plugin/lsp/snippet_spec.lua
+++ b/test/functional/plugin/lsp/snippet_spec.lua
@@ -1,13 +1,15 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
local snippet = require('vim.lsp._snippet_grammar')
local type = snippet.NodeType
-local eq = helpers.eq
-local exec_lua = helpers.exec_lua
+local eq = t.eq
+local exec_lua = n.exec_lua
describe('vim.lsp._snippet_grammar', function()
- before_each(helpers.clear)
- after_each(helpers.clear)
+ before_each(n.clear)
+ after_each(n.clear)
local parse = function(...)
local res = exec_lua('return require("vim.lsp._snippet_grammar").parse(...)', ...)
diff --git a/test/functional/plugin/lsp/helpers.lua b/test/functional/plugin/lsp/testutil.lua
index 97fa108500..3430a1e1a3 100644
--- a/test/functional/plugin/lsp/helpers.lua
+++ b/test/functional/plugin/lsp/testutil.lua
@@ -1,9 +1,10 @@
-local helpers = require('test.functional.helpers')(nil)
+local n = require('test.functional.testnvim')()
-local clear = helpers.clear
-local exec_lua = helpers.exec_lua
-local run = helpers.run
-local stop = helpers.stop
+local clear = n.clear
+local exec_lua = n.exec_lua
+local run = n.run
+local stop = n.stop
+local api = n.api
local NIL = vim.NIL
local M = {}
@@ -38,8 +39,7 @@ M.create_server_definition = [[
})
local handler = handlers[method]
if handler then
- local response, err = handler(method, params)
- callback(err, response)
+ handler(method, params, callback)
elseif method == 'initialize' then
callback(nil, {
capabilities = opts.capabilities or {}
@@ -105,6 +105,11 @@ local function fake_lsp_server_setup(test_name, timeout_ms, options, settings)
uri = 'file://' .. vim.uv.cwd(),
name = 'test_folder',
}};
+ before_init = function(params, config)
+ vim.schedule(function()
+ vim.rpcrequest(1, "setup")
+ end)
+ end,
on_init = function(client, result)
TEST_RPC_CLIENT = client
vim.rpcrequest(1, "init", result)
@@ -128,6 +133,18 @@ local function fake_lsp_server_setup(test_name, timeout_ms, options, settings)
)
end
+--- @class test.lsp.Config
+--- @field test_name string
+--- @field timeout_ms? integer
+--- @field options? table
+--- @field settings? table
+---
+--- @field on_setup? fun()
+--- @field on_init? fun(client: vim.lsp.Client, ...)
+--- @field on_handler? fun(...)
+--- @field on_exit? fun(code: integer, signal: integer)
+
+--- @param config test.lsp.Config
function M.test_rpc_server(config)
if config.test_name then
M.clear_notrace()
@@ -158,8 +175,15 @@ function M.test_rpc_server(config)
end
end,
})
+ --- @type integer, integer
local code, signal
local function on_request(method, args)
+ if method == 'setup' then
+ if config.on_setup then
+ config.on_setup()
+ end
+ return NIL
+ end
if method == 'init' then
if config.on_init then
config.on_init(client, unpack(args))
@@ -180,14 +204,14 @@ function M.test_rpc_server(config)
end
end
-- TODO specify timeout?
- -- run(on_request, on_notify, config.on_setup, 1000)
- run(on_request, on_notify, config.on_setup)
+ -- run(on_request, on_notify, nil, 1000)
+ run(on_request, on_notify, nil)
if config.on_exit then
config.on_exit(code, signal)
end
stop()
if config.test_name then
- exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })")
+ api.nvim_exec_autocmds('VimLeavePre', { modeline = false })
end
end
diff --git a/test/functional/plugin/lsp/utils_spec.lua b/test/functional/plugin/lsp/utils_spec.lua
index bb9cdb8390..6c6dec0667 100644
--- a/test/functional/plugin/lsp/utils_spec.lua
+++ b/test/functional/plugin/lsp/utils_spec.lua
@@ -1,12 +1,13 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
-local feed = helpers.feed
-local eq = helpers.eq
-local exec_lua = helpers.exec_lua
+local feed = n.feed
+local eq = t.eq
+local exec_lua = n.exec_lua
describe('vim.lsp.util', function()
- before_each(helpers.clear)
+ before_each(n.clear)
describe('stylize_markdown', function()
local stylize_markdown = function(content, opts)
@@ -142,7 +143,7 @@ describe('vim.lsp.util', function()
local screen
before_each(function()
- helpers.clear()
+ n.clear()
screen = Screen.new(80, 80)
screen:attach()
feed('79i<CR><Esc>') -- fill screen with empty lines