aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/lsp/inlay_hint_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/plugin/lsp/inlay_hint_spec.lua')
-rw-r--r--test/functional/plugin/lsp/inlay_hint_spec.lua335
1 files changed, 226 insertions, 109 deletions
diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua
index d3b5ae0e4e..471f2cc3e8 100644
--- a/test/functional/plugin/lsp/inlay_hint_spec.lua
+++ b/test/functional/plugin/lsp/inlay_hint_spec.lua
@@ -12,7 +12,8 @@ local api = n.api
local clear_notrace = t_lsp.clear_notrace
local create_server_definition = t_lsp.create_server_definition
-local text = dedent([[
+describe('vim.lsp.inlay_hint', function()
+ local text = dedent([[
auto add(int a, int b) { return a + b; }
int main() {
@@ -22,7 +23,7 @@ int main() {
}
}]])
-local response = [==[
+ local response = [==[
[
{"kind":1,"paddingLeft":false,"label":"-> int","position":{"character":22,"line":0},"paddingRight":false},
{"kind":2,"paddingLeft":false,"label":"a:","position":{"character":15,"line":5},"paddingRight":true},
@@ -30,7 +31,7 @@ local response = [==[
]
]==]
-local grid_without_inlay_hints = [[
+ local grid_without_inlay_hints = [[
auto add(int a, int b) { return a + b; } |
|
int main() { |
@@ -42,7 +43,7 @@ local grid_without_inlay_hints = [[
|
]]
-local grid_with_inlay_hints = [[
+ local grid_with_inlay_hints = [[
auto add(int a, int b){1:-> int} { return a + b; } |
|
int main() { |
@@ -54,54 +55,58 @@ local grid_with_inlay_hints = [[
|
]]
---- @type test.functional.ui.screen
-local screen
-before_each(function()
- clear_notrace()
- screen = Screen.new(50, 9)
- screen:attach()
-
- exec_lua(create_server_definition)
- exec_lua(
- [[
- local response = ...
- server = _create_server({
- capabilities = {
- inlayHintProvider = true,
- },
- handlers = {
- ['textDocument/inlayHint'] = function(_, _, callback)
- callback(nil, vim.json.decode(response))
- end,
- }
- })
+ --- @type test.functional.ui.screen
+ local screen
- bufnr = vim.api.nvim_get_current_buf()
- vim.api.nvim_win_set_buf(0, bufnr)
+ --- @type integer
+ local client_id
- client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
- ]],
- response
- )
+ --- @type integer
+ local bufnr
- insert(text)
- exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]])
- screen:expect({ grid = grid_with_inlay_hints })
-end)
+ before_each(function()
+ clear_notrace()
+ screen = Screen.new(50, 9)
+ screen:attach()
-after_each(function()
- api.nvim_exec_autocmds('VimLeavePre', { modeline = false })
-end)
+ bufnr = n.api.nvim_get_current_buf()
+ exec_lua(create_server_definition)
+ client_id = exec_lua(function()
+ _G.server = _G._create_server({
+ capabilities = {
+ inlayHintProvider = true,
+ },
+ handlers = {
+ ['textDocument/inlayHint'] = function(_, _, callback)
+ callback(nil, vim.json.decode(response))
+ end,
+ },
+ })
+
+ return vim.lsp.start({ name = 'dummy', cmd = _G.server.cmd })
+ end)
+
+ insert(text)
+ exec_lua(function()
+ vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
+ end)
+ screen:expect({ grid = grid_with_inlay_hints })
+ end)
+
+ after_each(function()
+ api.nvim_exec_autocmds('VimLeavePre', { modeline = false })
+ end)
-describe('vim.lsp.inlay_hint', function()
it('clears inlay hints when sole client detaches', function()
- exec_lua([[vim.lsp.stop_client(client_id)]])
+ exec_lua(function()
+ vim.lsp.stop_client(client_id)
+ end)
screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
end)
it('does not clear inlay hints when one of several clients detaches', function()
- exec_lua([[
- server2 = _create_server({
+ local client_id2 = exec_lua(function()
+ _G.server2 = _G._create_server({
capabilities = {
inlayHintProvider = true,
},
@@ -109,13 +114,16 @@ describe('vim.lsp.inlay_hint', function()
['textDocument/inlayHint'] = function(_, _, callback)
callback(nil, {})
end,
- }
+ },
})
- client2 = vim.lsp.start({ name = 'dummy2', cmd = server2.cmd })
+ local client_id2 = vim.lsp.start({ name = 'dummy2', cmd = _G.server2.cmd })
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
- ]])
+ return client_id2
+ end)
- exec_lua([[ vim.lsp.stop_client(client2) ]])
+ exec_lua(function()
+ vim.lsp.stop_client(client_id2)
+ end)
screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
end)
@@ -123,61 +131,85 @@ describe('vim.lsp.inlay_hint', function()
it('validation', function()
t.matches(
'enable: expected boolean, got table',
- t.pcall_err(exec_lua, [[vim.lsp.inlay_hint.enable({}, { bufnr = bufnr })]])
+ t.pcall_err(exec_lua, function()
+ --- @diagnostic disable-next-line:param-type-mismatch
+ vim.lsp.inlay_hint.enable({}, { bufnr = bufnr })
+ end)
)
t.matches(
'enable: expected boolean, got number',
- t.pcall_err(exec_lua, [[vim.lsp.inlay_hint.enable(42)]])
+ t.pcall_err(exec_lua, function()
+ --- @diagnostic disable-next-line:param-type-mismatch
+ vim.lsp.inlay_hint.enable(42)
+ end)
)
t.matches(
'filter: expected table, got number',
- t.pcall_err(exec_lua, [[vim.lsp.inlay_hint.enable(true, 42)]])
+ t.pcall_err(exec_lua, function()
+ --- @diagnostic disable-next-line:param-type-mismatch
+ vim.lsp.inlay_hint.enable(true, 42)
+ end)
)
end)
describe('clears/applies inlay hints when passed false/true/nil', function()
+ local bufnr2 --- @type integer
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)
- ]])
+ bufnr2 = exec_lua(function()
+ local bufnr2_0 = vim.api.nvim_create_buf(true, false)
+ vim.lsp.buf_attach_client(bufnr2_0, client_id)
+ vim.api.nvim_win_set_buf(0, bufnr2_0)
+ return bufnr2_0
+ end)
insert(text)
- exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr2 })]])
- exec_lua([[vim.api.nvim_win_set_buf(0, bufnr)]])
+ exec_lua(function()
+ vim.lsp.inlay_hint.enable(true, { bufnr = bufnr2 })
+ end)
+ n.api.nvim_win_set_buf(0, bufnr)
screen:expect({ grid = grid_with_inlay_hints })
end)
it('for one single buffer', function()
- exec_lua([[
+ exec_lua(function()
vim.lsp.inlay_hint.enable(false, { bufnr = bufnr })
vim.api.nvim_win_set_buf(0, bufnr2)
- ]])
+ end)
screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
- exec_lua([[vim.api.nvim_win_set_buf(0, bufnr)]])
+ n.api.nvim_win_set_buf(0, bufnr)
screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
- exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]])
+ exec_lua(function()
+ vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
+ end)
screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
- exec_lua(
- [[vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr })]]
- )
+ exec_lua(function()
+ vim.lsp.inlay_hint.enable(
+ not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }),
+ { bufnr = bufnr }
+ )
+ end)
screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
- exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]])
+ exec_lua(function()
+ vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
+ end)
screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
end)
it('for all buffers', function()
- exec_lua([[vim.lsp.inlay_hint.enable(false)]])
+ exec_lua(function()
+ vim.lsp.inlay_hint.enable(false)
+ end)
screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
- exec_lua([[vim.api.nvim_win_set_buf(0, bufnr2)]])
+ n.api.nvim_win_set_buf(0, bufnr2)
screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
- exec_lua([[vim.lsp.inlay_hint.enable(true)]])
+ exec_lua(function()
+ vim.lsp.inlay_hint.enable(true)
+ end)
screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
- exec_lua([[vim.api.nvim_win_set_buf(0, bufnr)]])
+ n.api.nvim_win_set_buf(0, bufnr)
screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
end)
end)
@@ -198,10 +230,8 @@ describe('vim.lsp.inlay_hint', function()
paddingRight = false,
}
- exec_lua(
- [[
- local expected2 = ...
- server2 = _create_server({
+ exec_lua(function()
+ _G.server2 = _G._create_server({
capabilities = {
inlayHintProvider = true,
},
@@ -209,52 +239,139 @@ describe('vim.lsp.inlay_hint', function()
['textDocument/inlayHint'] = function(_, _, callback)
callback(nil, { expected2 })
end,
- }
+ },
})
- client2 = vim.lsp.start({ name = 'dummy2', cmd = server2.cmd })
+ _G.client2 = vim.lsp.start({ name = 'dummy2', cmd = _G.server2.cmd })
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
- ]],
- expected2
- )
+ end)
--- @type vim.lsp.inlay_hint.get.ret
- local res = exec_lua([[return vim.lsp.inlay_hint.get()]])
- 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)
+ 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 },
+ },
+ exec_lua(function()
+ return vim.lsp.inlay_hint.get()
+ end)
+ )
- --- @type vim.lsp.inlay_hint.get.ret
- res = exec_lua([[return vim.lsp.inlay_hint.get({
- range = {
- start = { line = 2, character = 10 },
- ["end"] = { line = 2, character = 10 },
+ eq(
+ {
+ { bufnr = 1, client_id = 2, inlay_hint = expected2 },
},
- })]])
- eq({
- { bufnr = 1, client_id = 2, inlay_hint = expected2 },
- }, res)
+ exec_lua(function()
+ return vim.lsp.inlay_hint.get({
+ range = {
+ start = { line = 2, character = 10 },
+ ['end'] = { line = 2, character = 10 },
+ },
+ })
+ end)
+ )
- --- @type vim.lsp.inlay_hint.get.ret
- res = exec_lua([[return vim.lsp.inlay_hint.get({
- bufnr = vim.api.nvim_get_current_buf(),
- range = {
- start = { line = 4, character = 18 },
- ["end"] = { line = 5, character = 17 },
+ eq(
+ {
+ { bufnr = 1, client_id = 1, inlay_hint = expected[2] },
+ { bufnr = 1, client_id = 1, inlay_hint = expected[3] },
},
- })]])
- eq({
- { bufnr = 1, client_id = 1, inlay_hint = expected[2] },
- { bufnr = 1, client_id = 1, inlay_hint = expected[3] },
- }, res)
+ exec_lua(function()
+ return vim.lsp.inlay_hint.get({
+ bufnr = vim.api.nvim_get_current_buf(),
+ range = {
+ start = { line = 4, character = 18 },
+ ['end'] = { line = 5, character = 17 },
+ },
+ })
+ end)
+ )
- --- @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(
+ {},
+ exec_lua(function()
+ return vim.lsp.inlay_hint.get({
+ bufnr = vim.api.nvim_get_current_buf() + 1,
+ })
+ end)
+ )
+ end)
+ end)
+end)
+
+describe('Inlay hints handler', function()
+ local text = dedent([[
+test text
+ ]])
+
+ local response = [==[
+ [
+ { "position": { "line": 0, "character": 0 }, "label": "0" },
+ { "position": { "line": 0, "character": 0 }, "label": "1" },
+ { "position": { "line": 0, "character": 0 }, "label": "2" },
+ { "position": { "line": 0, "character": 0 }, "label": "3" },
+ { "position": { "line": 0, "character": 0 }, "label": "4" }
+ ]
+ ]==]
+
+ local grid_without_inlay_hints = [[
+ test text |
+ ^ |
+ |
+]]
+
+ local grid_with_inlay_hints = [[
+ {1:01234}test text |
+ ^ |
+ |
+]]
+
+ --- @type test.functional.ui.screen
+ local screen
+
+ --- @type integer
+ local client_id
+
+ --- @type integer
+ local bufnr
+
+ before_each(function()
+ clear_notrace()
+ screen = Screen.new(50, 3)
+ screen:attach()
+
+ exec_lua(create_server_definition)
+ bufnr = n.api.nvim_get_current_buf()
+ client_id = exec_lua(function()
+ _G.server = _G._create_server({
+ capabilities = {
+ inlayHintProvider = true,
+ },
+ handlers = {
+ ['textDocument/inlayHint'] = function(_, _, callback)
+ callback(nil, vim.json.decode(response))
+ end,
+ },
+ })
+
+ vim.api.nvim_win_set_buf(0, bufnr)
+
+ return vim.lsp.start({ name = 'dummy', cmd = _G.server.cmd })
+ end)
+ insert(text)
+ end)
+
+ it('renders hints with same position in received order', function()
+ exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]])
+ screen:expect({ grid = grid_with_inlay_hints })
+ exec_lua(function()
+ vim.lsp.stop_client(client_id)
end)
+ screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
+ end)
+
+ after_each(function()
+ api.nvim_exec_autocmds('VimLeavePre', { modeline = false })
end)
end)