Repository: neovim/neovim
File: runtime/lua/vim/lsp/semantic_tokens.lua (Lua)

Code before:
--- are saved to facilitate document synchronization in the response.
---
---@package
function STHighlighter:send_request()
  local version = util.buf_versions[self.bufnr]

  self:reset_timer()

  for client_id, state in pairs(self.client_state) do
    local client = vim.lsp.get_client_by_id(client_id)
    if client then
      local current_result = state.current_result
      local active_request = state.active_request

      if
        state.supports_range
        or (current_result.version ~= version and active_request.version ~= version)
      then
        -- cancel stale in-flight request
        if active_request.request_id then
          client:cancel_request(active_request.request_id)
          active_request = {}
          state.active_request = active_request
        end

        ---@class lsp.SemanticTokensParams
        local params = { textDocument = util.make_text_document_params(self.bufnr) }

        ---@type vim.lsp.protocol.Method.ClientToServer.Request
        local method = 'textDocument/semanticTokens/full'

        if state.supports_range then
          method = 'textDocument/semanticTokens/range'
          params.range = self:get_visible_range()
        elseif state.supports_delta and current_result.result_id then
          method = 'textDocument/semanticTokens/full/delta'
          params.previousResultId = current_result.result_id
        end

        ---@param response? lsp.SemanticTokens|lsp.SemanticTokensDelta
        local success, request_id = client:request(method, params, function(err, response, ctx)
          local bufnr = assert(ctx.bufnr)
          local highlighter = STHighlighter.active[bufnr]
          if not highlighter then
            return
          end

          if err or not response then
            highlighter.client_state[client.id].active_request = {}
            return
          end

Review comment (suggestion):
```suggestion
        ---@type lsp.SemanticTokensParams
```

Code after:
---
--- For the given clients (or all attached, if not provided), this sends a request
--- to ask for semantic tokens. If the server supports delta requests, that will
--- be prioritized if we have a previous requestId and token array.
---
--- This function will skip servers where there is an already an active request in
--- flight for the same version. If there is a stale request in flight, that is
--- cancelled prior to sending a new one.
---
--- Finally, if the request was successful, the requestId and document version
--- are saved to facilitate document synchronization in the response.
---
---@package
function STHighlighter:send_request()
  local version = util.buf_versions[self.bufnr]

  self:reset_timer()

  for client_id, state in pairs(self.client_state) do
    local client = vim.lsp.get_client_by_id(client_id)
    if client then
      local current_result = state.current_result
      local active_request = state.active_request

      if
        state.supports_range
        or (current_result.version ~= version and active_request.version ~= version)
      then
        -- cancel stale in-flight request
        if active_request.request_id then
          client:cancel_request(active_request.request_id)
          active_request = {}
          state.active_request = active_request
        end

        ---@type lsp.SemanticTokensParams|lsp.SemanticTokensRangeParams|lsp.SemanticTokensDeltaParams
        local params = { textDocument = util.make_text_document_params(self.bufnr) }

        ---@type vim.lsp.protocol.Method.ClientToServer.Request
        local method = 'textDocument/semanticTokens/full'

        if state.supports_range then
          method = 'textDocument/semanticTokens/range'
          params.range = self:get_visible_range()
        elseif state.supports_delta and current_result.result_id then
          method = 'textDocument/semanticTokens/full/delta'
          params.previousResultId = current_result.result_id
        end

        ---@param response? lsp.SemanticTokens|lsp.SemanticTokensDelta
        local success, request_id = client:request(method, params, function(err, response, ctx)