Home Explore Blog CI



neovim

10th chunk of `runtime/doc/lsp.txt`
cdb667572b04511185d321f5a892d5e84abe33813e541afc0000000100000fa6
 progress notification from the server. Notifications can
    be polled from a `progress` ring buffer of a |vim.lsp.Client| or use
    |vim.lsp.status()| to get an aggregate message.

    If the server sends a "work done progress", the `pattern` is set to `kind`
    (one of `begin`, `report` or `end`).

    The Lua handler |event-data| argument has `client_id` and `params`
    properties, where `params` is the request params sent by the server (see
    `lsp.ProgressParams`).

    Example: >vim
        autocmd LspProgress * redrawstatus
<

LspRequest                                                        *LspRequest*
    For each request sent to an LSP server, this event is triggered for
    every change to the request's status. The status can be one of
    `pending`, `complete`, or `cancel` and is sent as the {type} on the
    "data" table passed to the callback function.

    It triggers when the initial request is sent ({type} == `pending`) and
    when the LSP server responds ({type} == `complete`). If a cancellation
    is requested using `client.cancel_request(request_id)`, then this event
    will trigger with {type} == `cancel`.

    The Lua handler |event-data| argument has the client ID, request ID, and
    request (described at |vim.lsp.Client|, {requests} field). If the request
    type is `complete`, the request will be deleted from the client's pending
    requests table after processing the event handlers.

    Example: >lua
    vim.api.nvim_create_autocmd('LspRequest', {
      callback = function(args)
        local bufnr = args.buf
        local client_id = args.data.client_id
        local request_id = args.data.request_id
        local request = args.data.request
        if request.type == 'pending' then
          -- do something with pending requests
          track_pending(client_id, bufnr, request_id, request)
        elseif request.type == 'cancel' then
          -- do something with pending cancel requests
          track_canceling(client_id, bufnr, request_id, request)
        elseif request.type == 'complete' then
          -- do something with finished requests. this pending
          -- request entry is about to be removed since it is complete
          track_finish(client_id, bufnr, request_id, request)
        end
      end,
    })
<

LspTokenUpdate                                                *LspTokenUpdate*
    When a visible semantic token is sent or updated by the LSP server, or
    when an existing token becomes visible for the first time. The
    |autocmd-pattern| is the buffer name. The Lua handler |event-data|
    argument has the client ID and token (see
    |vim.lsp.semantic_tokens.get_at_pos()|).

    Example: >lua
    vim.api.nvim_create_autocmd('LspTokenUpdate', {
      callback = function(args)
        local token = args.data.token
        if token.type == 'variable' and not token.modifiers.readonly then
          vim.lsp.semantic_tokens.highlight_token(
            token, args.buf, args.data.client_id, 'MyMutableVariableHighlight'
          )
        end
      end,
    })
<
    Note: doing anything other than calling
    |vim.lsp.semantic_tokens.highlight_token()| is considered experimental.

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

*vim.lsp.Config*
    Extends: |vim.lsp.ClientConfig|


    Fields: ~
      • {cmd}?           (`string[]|fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient`)
                         See `cmd` in |vim.lsp.ClientConfig|.
      • {filetypes}?     (`string[]`) Filetypes the client will attach to, if
                         activated by `vim.lsp.enable()`. If not provided, the
                         client will attach to all filetypes.
      • {reuse_client}?  (`fun(client: vim.lsp.Client, config: vim.lsp.ClientConfig): boolean`)
                         Predicate which decides if a client should be
                     

Title: LSP Events: LspRequest and LspTokenUpdate
Summary
This section details the `LspRequest` and `LspTokenUpdate` LSP events. `LspRequest` triggers on every change to a request's status (pending, complete, cancel), providing access to the client ID, request ID, and request details. It allows tracking the lifecycle of LSP requests. `LspTokenUpdate` is triggered when a visible semantic token is sent/updated, or when an existing token becomes visible, exposing the token and client ID, primarily intended for highlighting tokens.