vim.lsp.semantic_tokens
Methods8
function M.start(bufnr: integer, client_id: integer, opts: nil | table) -> nil
Deprecated
Start the semantic token highlighting engine for the given buffer with the given client. The client must already be attached to the buffer.
NOTE: This is currently called automatically by |vim.lsp.bufattachclient()|. To opt-out of semantic highlighting with a server that supports it, you can delete the semanticTokensProvider table from the {server_capabilities} of your client in your |LspAttach| callback or your configuration's on_attach callback:
client.server_capabilities.semanticTokensProvider = nil
bufnrintegerBuffer number, or
0for current bufferclient_idintegerThe ID of the |vim.lsp.Client|
optsnil | tableOptional keyword arguments
- debounce (integer, default: 200): Debounce token requests
to the server by the given number in milliseconds
- nil
function M.stop(bufnr: integer, client_id: integer) -> nil
Deprecated
Stop the semantic token highlighting engine for the given buffer with the given client.
bufnrintegerBuffer number, or
0for current bufferclient_idintegerThe ID of the |vim.lsp.Client|
- nil
function M.is_enabled(filter: vim.lsp.capability.enable.Filter | nil) -> any
Query whether semantic tokens is enabled in the {filter}ed scope
function M.enable(enable: nil | boolean, filter: vim.lsp.capability.enable.Filter | nil) -> nil
Enables or disables semantic tokens for the {filter}ed scope.
To "toggle", pass the inverse of is_enabled():
vim.lsp.semantic_tokens.enable(not vim.lsp.semantic_tokens.is_enabled())
enablenil | booleantrue/nil to enable, false to disable
filtervim.lsp.capability.enable.Filter | nil
- nil
function M.get_at_pos(bufnr: nil | integer, row: nil | integer, col: nil | integer) -> STTokenRangeInspect[] | nil
Return the semantic token(s) at the given position. If called without arguments, returns the token under the cursor.
bufnrnil | integerBuffer number (0 for current buffer, default)
rownil | integerPosition row (default cursor position)
colnil | integerPosition column (default cursor position)
- STTokenRangeInspect[] | nil
(table|nil) List of tokens at position. Each token has the following fields:
- line (integer) line number, 0-based
- start_col (integer) start column, 0-based
- end_line (integer) end line number, 0-based
- end_col (integer) end column, 0-based
- type (string) token type as string, e.g. "variable"
- modifiers (table) token modifiers as a set. E.g., { static = true, readonly = true }
- client_id (integer)
function M.force_refresh(bufnr: nil | integer) -> nil
Force a refresh of all semantic tokens
Only has an effect if the buffer is currently active for semantic token highlighting (|vim.lsp.semantic_tokens.enable()| has been called for it)
bufnrnil | integerfilter by buffer. All buffers if nil, current buffer if 0
- nil
function M.highlight_token(token: table, bufnr: integer, client_id: integer, hl_group: string, opts: vim.lsp.semantic_tokens.highlight_token.Opts | nil) -> nil
Highlight a semantic token.
Apply an extmark with a given highlight group for a semantic token. The mark will be deleted by the semantic token engine when appropriate; for example, when the LSP sends updated tokens. This function is intended for use inside |LspTokenUpdate| callbacks.
tokentableSemantic token, provided as
ev.data.tokenin |LspTokenUpdate|bufnrintegerBuffer to highlight, or
0for current buffer.client_idintegerID of the |vim.lsp.Client|
hl_groupstringHighlight group name
optsvim.lsp.semantic_tokens.highlight_token.Opts | nilOptional parameters:
- nil
function M._refresh(err, _, ctx: lsp.HandlerContext) -> vim.NIL
|lsp-handler| for the method workspace/semanticTokens/refresh
Refresh requests are sent by the server to indicate a project-wide change that requires all tokens to be re-requested by the client. This handler will invalidate the current results of all buffers and automatically kick off a new request for buffers that are displayed in a window. For those that aren't, the BufWinEnter event should take care of it next time it's displayed.