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

Code before:
          token.marked = true

          api.nvim_exec_autocmds('LspTokenUpdate', {
            buffer = self.bufnr,
            modeline = false,
            data = {
              token = token,
              client_id = client_id,
            },
          })
        end
      end
    end
  end
end

--- Reset the buffer's highlighting state and clears the extmark highlights.
---
---@package
function STHighlighter:reset()
  for client_id, state in pairs(self.client_state) do
    api.nvim_buf_clear_namespace(self.bufnr, state.namespace, 0, -1)
    state.current_result = {}
    if state.active_request.request_id then
      local client = vim.lsp.get_client_by_id(client_id)
      assert(client)
      client:cancel_request(state.active_request.request_id)
      state.active_request = {}
    end
  end
end

--- Mark a client's results as dirty. This method will cancel any active
--- requests to the server and pause new highlights from being added
--- in the on_win callback. The rest of the current results are saved
--- in case the server supports delta requests.
---
---@package
---@param client_id integer
function STHighlighter:mark_dirty(client_id)
  local state = self.client_state[client_id]
  assert(state)

  -- if we clear the version from current_result, it'll cause the
  -- next request to be sent and will also pause new highlights
  -- from being added in on_win until a new result comes from
  -- the server
  if state.current_result then
    state.current_result.version = nil
  end


Review comment (suggestion):
Nit:
```suggestion
      local client = assert(vim.lsp.get_client_by_id(client_id))
```

Code after:
        local token = assert(highlights[i])

        is_folded, foldend = check_fold(token.line + 1, foldend)

        if not is_folded and not token.marked then
          set_mark0(token, string.format('@lsp.type.%s.%s', token.type, ft), 0)
          for modifier in pairs(token.modifiers) do
            set_mark0(token, string.format('@lsp.mod.%s.%s', modifier, ft), 1)
            set_mark0(token, string.format('@lsp.typemod.%s.%s.%s', token.type, modifier, ft), 2)
          end
          token.marked = true

          api.nvim_exec_autocmds('LspTokenUpdate', {
            buffer = self.bufnr,
            modeline = false,
            data = {
              token = token,
              client_id = client_id,
            },
          })
        end
      end
    end
  end
end

--- Reset the buffer's highlighting state and clears the extmark highlights.
---
---@package
function STHighlighter:reset()
  for client_id, state in pairs(self.client_state) do
    api.nvim_buf_clear_namespace(self.bufnr, state.namespace, 0, -1)
    state.current_result = {}
    self:cancel_active_request(client_id)
  end
end

--- Mark a client's results as dirty. This method will cancel any active
--- requests to the server and pause new highlights from being added
--- in the on_win callback. The rest of the current results are saved
--- in case the server supports delta requests.
---
---@package
---@param client_id integer
function STHighlighter:mark_dirty(client_id)
  local state = assert(self.client_state[client_id])

  -- if we clear the version from current_result, it'll cause the
  -- next request to be sent and will also pause new highlights
  -- from being added in on_win until a new result comes from
  -- the server