aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/lsp/semantic_tokens_spec.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-01-03 02:09:18 +0100
committerJustin M. Keyes <justinkz@gmail.com>2024-01-03 02:09:29 +0100
commit04f2f864e270e772c6326cefdf24947f0130e492 (patch)
tree46f83f909b888a66c741032ab955afc6eab84292 /test/functional/plugin/lsp/semantic_tokens_spec.lua
parent59d117ec99b6037cb9fad5bbfb6d0b18f5012927 (diff)
downloadrneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.gz
rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.bz2
rneovim-04f2f864e270e772c6326cefdf24947f0130e492.zip
refactor: format test/*
Diffstat (limited to 'test/functional/plugin/lsp/semantic_tokens_spec.lua')
-rw-r--r--test/functional/plugin/lsp/semantic_tokens_spec.lua251
1 files changed, 162 insertions, 89 deletions
diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua
index b95d435c2b..77e39c81c8 100644
--- a/test/functional/plugin/lsp/semantic_tokens_spec.lua
+++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua
@@ -23,21 +23,20 @@ after_each(function()
end)
describe('semantic token highlighting', function()
-
local screen
before_each(function()
screen = Screen.new(40, 16)
screen:attach()
screen:set_default_attr_ids {
- [1] = { bold = true, foreground = Screen.colors.Blue1 };
- [2] = { foreground = Screen.colors.DarkCyan };
- [3] = { foreground = Screen.colors.SlateBlue };
- [4] = { bold = true, foreground = Screen.colors.SeaGreen };
- [5] = { foreground = tonumber('0x6a0dad') };
- [6] = { foreground = Screen.colors.Blue1 };
- [7] = { bold = true, foreground = Screen.colors.DarkCyan };
- [8] = { bold = true, foreground = Screen.colors.SlateBlue };
- [9] = { bold = true, foreground = tonumber('0x6a0dad') };
+ [1] = { bold = true, foreground = Screen.colors.Blue1 },
+ [2] = { foreground = Screen.colors.DarkCyan },
+ [3] = { foreground = Screen.colors.SlateBlue },
+ [4] = { bold = true, foreground = Screen.colors.SeaGreen },
+ [5] = { foreground = tonumber('0x6a0dad') },
+ [6] = { foreground = Screen.colors.Blue1 },
+ [7] = { bold = true, foreground = Screen.colors.DarkCyan },
+ [8] = { bold = true, foreground = Screen.colors.SlateBlue },
+ [9] = { bold = true, foreground = tonumber('0x6a0dad') },
}
command([[ hi link @lsp.type.namespace Type ]])
command([[ hi link @lsp.type.function Special ]])
@@ -81,7 +80,8 @@ describe('semantic token highlighting', function()
before_each(function()
exec_lua(create_server_definition)
- exec_lua([[
+ exec_lua(
+ [[
local legend, response, edit_response = ...
server = _create_server({
capabilities = {
@@ -99,7 +99,11 @@ describe('semantic token highlighting', function()
end,
}
})
- ]], legend, response, edit_response)
+ ]],
+ legend,
+ response,
+ edit_response
+ )
end)
it('buffer is highlighted when attached', function()
@@ -112,7 +116,8 @@ describe('semantic token highlighting', function()
insert(text)
- screen:expect { grid = [[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int {8:main}() |
@@ -127,7 +132,8 @@ describe('semantic token highlighting', function()
^} |
{1:~ }|*3
|
- ]] }
+ ]],
+ }
end)
it('use LspTokenUpdate and highlight_token', function()
@@ -149,7 +155,8 @@ describe('semantic token highlighting', function()
insert(text)
- screen:expect { grid = [[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int {9:main}() |
@@ -164,8 +171,8 @@ describe('semantic token highlighting', function()
^} |
{1:~ }|*3
|
- ]] }
-
+ ]],
+ }
end)
it('buffer is unhighlighted when client is detached', function()
@@ -182,7 +189,8 @@ describe('semantic token highlighting', function()
vim.lsp.buf_detach_client(bufnr, client_id)
]])
- screen:expect { grid = [[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int main() |
@@ -197,25 +205,28 @@ describe('semantic token highlighting', function()
^} |
{1:~ }|*3
|
- ]] }
+ ]],
+ }
end)
- it('buffer is highlighted and unhighlighted when semantic token highlighting is started and stopped'
- , function()
- exec_lua([[
+ it(
+ 'buffer is highlighted and unhighlighted when semantic token highlighting is started and stopped',
+ 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)
+ insert(text)
- exec_lua([[
+ exec_lua([[
vim.notify = function() end
vim.lsp.semantic_tokens.stop(bufnr, client_id)
]])
- screen:expect { grid = [[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int main() |
@@ -230,13 +241,15 @@ describe('semantic token highlighting', function()
^} |
{1:~ }|*3
|
- ]] }
+ ]],
+ }
- exec_lua([[
+ exec_lua([[
vim.lsp.semantic_tokens.start(bufnr, client_id)
]])
- screen:expect { grid = [[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int {8:main}() |
@@ -251,8 +264,10 @@ describe('semantic token highlighting', function()
^} |
{1:~ }|*3
|
- ]] }
- end)
+ ]],
+ }
+ end
+ )
it('buffer is re-highlighted when force refreshed', function()
exec_lua([[
@@ -263,7 +278,8 @@ describe('semantic token highlighting', function()
insert(text)
- screen:expect { grid = [[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int {8:main}() |
@@ -278,13 +294,15 @@ describe('semantic token highlighting', function()
^} |
{1:~ }|*3
|
- ]] }
+ ]],
+ }
exec_lua([[
vim.lsp.semantic_tokens.force_refresh(bufnr)
]])
- screen:expect { grid = [[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int {8:main}() |
@@ -299,7 +317,9 @@ describe('semantic token highlighting', function()
^} |
{1:~ }|*3
|
- ]], unchanged = true }
+ ]],
+ unchanged = true,
+ }
local messages = exec_lua('return server.messages')
local token_request_count = 0
@@ -338,7 +358,8 @@ describe('semantic token highlighting', function()
]])
insert(text)
- screen:expect { grid = [[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int {8:main}() |
@@ -353,10 +374,12 @@ describe('semantic token highlighting', function()
^} |
{1:~ }|*3
|
- ]] }
+ ]],
+ }
feed_command('%s/int x/int x()/')
feed_command('noh')
- screen:expect { grid = [[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int {8:main}() |
@@ -370,7 +393,8 @@ describe('semantic token highlighting', function()
} |*2
{1:~ }|*3
:noh |
- ]] }
+ ]],
+ }
end)
it('prevents starting semantic token highlighting with invalid conditions', function()
@@ -381,7 +405,7 @@ describe('semantic token highlighting', function()
notifications = {}
vim.notify = function(...) table.insert(notifications, 1, {...}) end
]])
- eq(false, exec_lua("return vim.lsp.buf_is_attached(bufnr, client_id)"))
+ eq(false, exec_lua('return vim.lsp.buf_is_attached(bufnr, client_id)'))
insert(text)
@@ -398,7 +422,8 @@ describe('semantic token highlighting', function()
matches('%[LSP%] No client with id %d', notifications[1][1])
end)
- it('opt-out: does not activate semantic token highlighting if disabled in client attach',
+ it(
+ 'opt-out: does not activate semantic token highlighting if disabled in client attach',
function()
exec_lua([[
bufnr = vim.api.nvim_get_current_buf()
@@ -411,11 +436,12 @@ describe('semantic token highlighting', function()
end),
})
]])
- eq(true, exec_lua("return vim.lsp.buf_is_attached(bufnr, client_id)"))
+ eq(true, exec_lua('return vim.lsp.buf_is_attached(bufnr, client_id)'))
insert(text)
- screen:expect { grid = [[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int main() |
@@ -430,7 +456,8 @@ describe('semantic token highlighting', function()
^} |
{1:~ }|*3
|
- ]] }
+ ]],
+ }
local notifications = exec_lua([[
local notifications = {}
@@ -440,7 +467,8 @@ describe('semantic token highlighting', function()
]])
eq('[LSP] Server does not support semantic tokens', notifications[1][1])
- screen:expect { grid = [[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int main() |
@@ -455,10 +483,13 @@ describe('semantic token highlighting', function()
^} |
{1:~ }|*3
|
- ]], unchanged = true }
- end)
+ ]],
+ unchanged = true,
+ }
+ end
+ )
- it('ignores null responses from the server', function()
+ it('ignores null responses from the server', function()
exec_lua([[
local legend, response, edit_response = ...
server2 = _create_server({
@@ -480,11 +511,12 @@ describe('semantic token highlighting', function()
vim.api.nvim_win_set_buf(0, bufnr)
client_id = vim.lsp.start({ name = 'dummy', cmd = server2.cmd })
]])
- eq(true, exec_lua("return vim.lsp.buf_is_attached(bufnr, client_id)"))
+ eq(true, exec_lua('return vim.lsp.buf_is_attached(bufnr, client_id)'))
insert(text)
- screen:expect { grid = [[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int main() |
@@ -499,11 +531,13 @@ describe('semantic token highlighting', function()
^} |
{1:~ }|*3
|
- ]] }
+ ]],
+ }
end)
it('does not send delta requests if not supported by server', function()
- exec_lua([[
+ exec_lua(
+ [[
local legend, response, edit_response = ...
server2 = _create_server({
capabilities = {
@@ -524,10 +558,15 @@ describe('semantic token highlighting', function()
bufnr = vim.api.nvim_get_current_buf()
vim.api.nvim_win_set_buf(0, bufnr)
client_id = vim.lsp.start({ name = 'dummy', cmd = server2.cmd })
- ]], legend, response, edit_response)
+ ]],
+ legend,
+ response,
+ edit_response
+ )
insert(text)
- screen:expect { grid = [[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int {8:main}() |
@@ -542,14 +581,16 @@ describe('semantic token highlighting', function()
^} |
{1:~ }|*3
|
- ]] }
+ ]],
+ }
feed_command('%s/int x/int x()/')
feed_command('noh')
-- the highlights don't change because our fake server sent the exact
-- same result for the same method (the full request). "x" would have
-- changed to highlight index 3 had we sent a delta request
- screen:expect { grid = [[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int {8:main}() |
@@ -563,7 +604,8 @@ describe('semantic token highlighting', function()
} |*2
{1:~ }|*3
:noh |
- ]] }
+ ]],
+ }
local messages = exec_lua('return server2.messages')
local token_request_count = 0
for _, message in ipairs(messages) do
@@ -601,11 +643,13 @@ describe('semantic token highlighting', function()
},
},
expected_screen = function()
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
char* {7:foo} = "\n"^; |
{1:~ }|*14
|
- ]]}
+ ]],
+ }
end,
},
{
@@ -720,7 +764,8 @@ int main()
},
},
expected_screen = function()
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
#include <iostream> |
int {8:main}() |
{ |
@@ -733,7 +778,8 @@ int main()
^} |
{1:~ }|*5
|
- ]]}
+ ]],
+ }
end,
},
{
@@ -777,13 +823,15 @@ b = "as"]],
},
},
expected_screen = function()
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
{6:-- comment} |
local {7:a} = 1 |
{2:b} = "as^" |
{1:~ }|*12
|
- ]]}
+ ]],
+ }
end,
},
{
@@ -896,7 +944,8 @@ b = "as"]],
},
},
expected_screen = function()
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
pub fn {8:main}() { |
break rust; |
//{6:/ what?} |
@@ -904,13 +953,15 @@ b = "as"]],
^ |
{1:~ }|*10
|
- ]]}
+ ]],
+ }
end,
},
}) do
it(test.it, function()
exec_lua(create_server_definition)
- exec_lua([[
+ exec_lua(
+ [[
local legend, resp = ...
server = _create_server({
capabilities = {
@@ -928,7 +979,10 @@ b = "as"]],
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 })
- ]], test.legend, test.response)
+ ]],
+ test.legend,
+ test.response
+ )
insert(test.text)
@@ -970,7 +1024,7 @@ b = "as"]],
end_col = 9,
type = 'variable',
marked = true,
- }
+ },
},
expected2 = {
{
@@ -983,22 +1037,26 @@ b = "as"]],
end_col = 9,
type = 'variable',
marked = true,
- }
+ },
},
expected_screen1 = function()
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
char* {7:foo} = "\n"^; |
{1:~ }|*14
|
- ]]}
+ ]],
+ }
end,
expected_screen2 = function()
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
^ |
char* {7:foo} = "\n"; |
{1:~ }|*13
|
- ]]}
+ ]],
+ }
end,
},
{
@@ -1115,7 +1173,7 @@ int main()
modifiers = {},
type = 'comment',
marked = true,
- }
+ },
},
expected2 = {
{
@@ -1197,10 +1255,11 @@ int main()
modifiers = {},
type = 'comment',
marked = true,
- }
+ },
},
expected_screen1 = function()
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int {8:main}() |
@@ -1214,10 +1273,12 @@ int main()
^} |
{1:~ }|*4
|
- ]]}
+ ]],
+ }
end,
expected_screen2 = function()
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
#include <iostream> |
|
int {8:main}() |
@@ -1232,7 +1293,8 @@ int main()
} |
{1:~ }|*3
|
- ]]}
+ ]],
+ }
end,
},
{
@@ -1259,29 +1321,33 @@ int main()
end_col = 6,
type = 'variable',
marked = true,
- }
- },
- expected2 = {
+ },
},
+ expected2 = {},
expected_screen1 = function()
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
{7:string} = "test^" |
{1:~ }|*14
|
- ]]}
+ ]],
+ }
end,
expected_screen2 = function()
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
^ |
{1:~ }|*14
|
- ]]}
+ ]],
+ }
end,
},
}) do
it(test.it, function()
exec_lua(create_server_definition)
- exec_lua([[
+ exec_lua(
+ [[
local legend, resp1, resp2 = ...
server = _create_server({
capabilities = {
@@ -1309,7 +1375,11 @@ int main()
semantic_tokens.stop(bufnr, client_id)
semantic_tokens.start(bufnr, client_id, { debounce = 10 })
end)
- ]], test.legend, test.response1, test.response2)
+ ]],
+ test.legend,
+ test.response1,
+ test.response2
+ )
insert(test.text1)
@@ -1324,11 +1394,14 @@ int main()
if test.edit then
feed(test.edit)
else
- exec_lua([[
+ exec_lua(
+ [[
local text = ...
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, vim.fn.split(text, "\n"))
vim.wait(15) -- wait for debounce
- ]], test.text2)
+ ]],
+ test.text2
+ )
end
test.expected_screen2()