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

Code before:
    self:send_request()
  end
end

---@private
function STHighlighter:reset_timer()
  local timer = self.timer
  if timer then
    self.timer = nil
    if not timer:is_closing() then
      timer:stop()
      timer:close()
    end
  end
end

---@param bufnr (integer) Buffer number, or `0` for current buffer
---@param client_id (integer) The ID of the |vim.lsp.Client|
---@param debounce? (integer) (default: 200): Debounce token requests
---        to the server by the given number in milliseconds
function M._start(bufnr, client_id, debounce)
  local highlighter = STHighlighter.active[bufnr]

  if not highlighter then
    highlighter = STHighlighter:new(bufnr)
    highlighter.debounce = debounce or 200
  else
    highlighter.debounce = debounce or 200
  end

  highlighter:on_attach(client_id)
  if M.is_enabled({ bufnr = bufnr }) then
    highlighter:send_request()
  end
end

--- 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
--- ```
---
---@deprecated
---@param bufnr (integer) Buffer number, or `0` for current buffer

Review comment (suggestion):
The original code used a `max(current_value, debounce or 200)` which was originally intended to make it so that later calls to `start()` that didn't have a debounce parameter passed wouldn't override the debounce value that was set previously.

What might be better is in the `else`, to do something like:

```lua
highlighter.debounce = debounce or higlighter.debounce or 200
```

Code after:

---@private
function STHighlighter:reset_timer()
  local timer = self.timer
  if timer then
    self.timer = nil
    if not timer:is_closing() then
      timer:stop()
      timer:close()
    end
  end
end

---@param bufnr (integer) Buffer number, or `0` for current buffer
---@param client_id (integer) The ID of the |vim.lsp.Client|
---@param debounce? (integer) (default: 200): Debounce token requests
---        to the server by the given number in milliseconds
function M._start(bufnr, client_id, debounce)
  local highlighter = STHighlighter.active[bufnr]

  if not highlighter then
    highlighter = STHighlighter:new(bufnr)
    highlighter.debounce = debounce or 200
  else
    highlighter.debounce = debounce or highlighter.debounce
  end

  highlighter:on_attach(client_id)
  if M.is_enabled({ bufnr = bufnr }) then
    highlighter:send_request()
  end
end

--- 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
--- ```
---
---@deprecated
---@param bufnr (integer) Buffer number, or `0` for current buffer
---@param client_id (integer) The ID of the |vim.lsp.Client|
---@param opts? (table) Optional keyword arguments
---  - debounce (integer, default: 200): Debounce token requests