nvim_runtime_lua

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
Parameters
bufnrinteger

Buffer number, or 0 for current buffer

client_idinteger

The ID of the |vim.lsp.Client|

optsnil | table

Optional keyword arguments

  • debounce (integer, default: 200): Debounce token requests
  • to the server by the given number in milliseconds

Returns
nil
Deprecated
function M.stop(bufnr: integer, client_id: integer) -> nil
Deprecated

Stop the semantic token highlighting engine for the given buffer with the given client.

Parameters
bufnrinteger

Buffer number, or 0 for current buffer

client_idinteger

The ID of the |vim.lsp.Client|

Returns
nil
Deprecated
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())
Parameters
enablenil | boolean

true/nil to enable, false to disable

Returns
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.

Parameters
bufnrnil | integer

Buffer number (0 for current buffer, default)

rownil | integer

Position row (default cursor position)

colnil | integer

Position column (default cursor position)

Returns
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)

Parameters
bufnrnil | integer

filter by buffer. All buffers if nil, current buffer if 0

Returns
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.

Parameters
tokentable

Semantic token, provided as ev.data.token in |LspTokenUpdate|

bufnrinteger

Buffer to highlight, or 0 for current buffer.

client_idinteger

ID of the |vim.lsp.Client|

hl_groupstring

Highlight group name

optsvim.lsp.semantic_tokens.highlight_token.Opts | nil

Optional parameters:

Returns
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.