aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/lsp/semantic_tokens_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/plugin/lsp/semantic_tokens_spec.lua')
-rw-r--r--test/functional/plugin/lsp/semantic_tokens_spec.lua194
1 files changed, 149 insertions, 45 deletions
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,
}
})