Home Explore Blog CI



neovim

33th chunk of `runtime/doc/lsp.txt`
bbc7dbd4d0c2c9155295f0fdcc84ca5b568d09e39a4b08e50000000100000fd0
 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: ~
      • {token}      (`table`) A semantic token, found as `args.data.token` in
                     |LspTokenUpdate|
      • {bufnr}      (`integer`) The buffer to highlight, or `0` for current
                     buffer
      • {client_id}  (`integer`) The ID of the |vim.lsp.Client|
      • {hl_group}   (`string`) Highlight group name
      • {opts}       (`table?`) Optional parameters:
                     • {priority}? (`integer`, default:
                       `vim.hl.priorities.semantic_tokens + 3`) Priority for
                       the applied extmark.

start({bufnr}, {client_id}, {opts})          *vim.lsp.semantic_tokens.start()*
    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.buf_attach_client()|. 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: >lua
        client.server_capabilities.semanticTokensProvider = nil
<

    Parameters: ~
      • {bufnr}      (`integer`) Buffer number, or `0` for current buffer
      • {client_id}  (`integer`) The ID of the |vim.lsp.Client|
      • {opts}       (`table?`) Optional keyword arguments
                     • debounce (integer, default: 200): Debounce token
                       requests to the server by the given number in
                       milliseconds

stop({bufnr}, {client_id})                    *vim.lsp.semantic_tokens.stop()*
    Stop the semantic token highlighting engine for the given buffer with the
    given client.

    NOTE: This is automatically called by a |LspDetach| autocmd that is set up
    as part of `start()`, so you should only need this function to manually
    disengage the semantic token engine without fully detaching the LSP client
    from the buffer.

    Parameters: ~
      • {bufnr}      (`integer`) Buffer number, or `0` for current buffer
      • {client_id}  (`integer`) The ID of the |vim.lsp.Client|


==============================================================================
Lua module: vim.lsp.document_color                        *lsp-document_color*

enable({enable}, {bufnr}, {opts})            *vim.lsp.document_color.enable()*
    Enables document highlighting from the given language client in the given
    buffer.

    You can enable document highlighting when a client attaches to a buffer as
    follows: >lua
        vim.api.nvim_create_autocmd('LspAttach', {
          callback = function(args)
            vim.lsp.document_color.enable(true, args.buf)
          end
        })
<

    To "toggle", pass the inverse of `is_enabled()`: >lua
        vim.lsp.document_color.enable(not vim.lsp.document_color.is_enabled())
<

    Parameters: ~
      • {enable}  (`boolean?`) True to enable, false to disable. (default:
                  `true`)
      • {bufnr}   (`integer?`) Buffer handle, or 0 for current. (default: 0)
      • {opts}    (`table?`) A table with the following fields:
                  • {style}?
                    (`'background'|'foreground'|'virtual'|string|fun(bufnr: integer, range: Range4, hex_code: string)`)
                    Highlight style. It can be one of the pre-defined styles,
                    a string to be used as virtual text, or a function that
                    receives the buffer handle, the range (start line, start
                    col, end line, end col) and the resolved hex color.
                    (default: `'background'`)

is_enabled({bufnr})

Title: vim.lsp.semantic_tokens Functions (continued) and Introduction to vim.lsp.document_color
Summary
This section continues detailing the `vim.lsp.semantic_tokens` module with the `start` function, which starts the semantic token highlighting engine for a given buffer and client, and the `stop` function, which stops the semantic token highlighting engine. The section then introduces the `vim.lsp.document_color` module, starting with the `enable` function, which enables document highlighting from a given language client in a specified buffer. It provides examples of how to enable document highlighting when a client attaches to a buffer and how to toggle it. The parameters for `enable` include a boolean to enable/disable, a buffer handle, and optional settings like the highlight style.