Closed tiagovla closed 2 years ago
I have this stupid function which sends a range
request and prints the token type and modifiers using vim.notify.
local on_full = require('nvim-semantic-tokens.semantic_tokens').on_full
function vim.lsp.buf.semantic_tokens_range(start_pos, end_pos)
local params = vim.lsp.util.make_given_range_params(start_pos, end_pos)
vim.lsp.buf_request(
0,
"textDocument/semanticTokens/range",
params,
vim.lsp.with(on_full, {
on_token = function(ctx, token)
vim.notify(token.type .. "." .. table.concat(token.modifiers, "."))
end,
})
)
end
then you can do something like
nnoremap <silent> <leader>lM viw:lua vim.lsp.semantic_tokens_range()<cr>
command! LspInspectTokenCursor execute "norm viw\<esc>" | lua vim.lsp.buf.semantic_tokens_range()
"textDocument/semanticTokens/range"
I was trying something like that with the textDocument/semanticTokens/full
method instead. Somehow my on_token
was never called due to the tick check. I will try this out. Thanks!
then you can do something like
nnoremap <silent> <leader>lM viw:lua vim.lsp.semantic_tokens_range()<cr> command! LspInspectTokenCursor execute "norm viw\<esc>" | lua vim.lsp.buf.semantic_tokens_range()
When I try your code snippet, nothing happens. Is there supposed to be output in the command window?
Even if I manually viw
a word and run :lua vim.lsp.semantic_tokens_range()
, I get no output.
lsp.log
shows:
reply:textDocument/semanticTokens/range(4) 0 ms, error: -32601: method not found
I wanted a command like the one treesitter has to debug semantic tokens. So, I came up with this:
It would be better if I could reuse the
on_full
handler with a customon_token
, but it returns at https://github.com/theHamsta/nvim-semantic-tokens/blob/668ca37a73f1afa42e1675dd72c0630b81f69f81/lua/nvim-semantic-tokens/semantic_tokens.lua#L69. Is there any workaround for this?