Repository: neovim/neovim
File: runtime/lua/vim/treesitter/highlighter.lua (Lua)

Code before:
  local self = TSHighlighter.active[buf]
  if not self or not self._conceal_line then
    return
  end

  api.nvim_buf_clear_namespace(buf, ns, 0, -1)
  self._conceal_checked = {}
end

---@private
---@param buf integer
---@param topline integer
---@param botline integer
function TSHighlighter._on_win(_, win, buf, topline, botline)
  local self = TSHighlighter.active[buf]
  if not self then
    return false
  end
  self.parsing = self.parsing
    or self.tree:parse({ topline, botline + 1 }, function(_, trees)
        if trees and self.parsing then
          self.parsing = false
          api.nvim__redraw({ win = win, valid = false, flush = false })
        end
      end)
      == nil
  if not self.parsing then
    self.redraw_count = self.redraw_count + 1
    self:prepare_highlight_states(topline, botline)
  else
    self:for_each_highlight_state(function(state)
      -- TODO(ribru17): Inefficient. Eventually all marks should be applied in on_buf, and all
      -- non-folded ranges of each open window should be merged, and iterators should only be
      -- created over those regions. This would also fix #31777.
      --
      -- Currently this is not possible because the parser discards previously parsed injection
      -- trees upon parsing a different region.
      --
      -- It would also be nice if rather than re-querying extmarks for old trees, we could tell the
      -- decoration provider to not clear previous ephemeral marks for this redraw cycle.
      state.iter = nil
      state.next_row = 0
    end)
  end
  return #self._highlight_states > 0
end

api.nvim_set_decoration_provider(ns, {
  on_win = TSHighlighter._on_win,
  on_line = TSHighlighter._on_line,
  on_buf = TSHighlighter._on_buf,

Review comment (suggestion):
this is a case where yoda wins
```suggestion
    or nil == self.tree:parse({ topline, botline + 1 }, function(_, trees)
        if trees and self.parsing then
          self.parsing = false
          api.nvim__redraw({ win = win, valid = false, flush = false })
        end
      end)
```

Code after:
  local self = TSHighlighter.active[buf]
  if not self or not self._conceal_line then
    return
  end

  api.nvim_buf_clear_namespace(buf, ns, 0, -1)
  self._conceal_checked = {}
end

---@private
---@param buf integer
---@param topline integer
---@param botline integer
function TSHighlighter._on_win(_, win, buf, topline, botline)
  local self = TSHighlighter.active[buf]
  if not self then
    return false
  end
  self.parsing = self.parsing
    or nil
      == self.tree:parse({ topline, botline + 1 }, function(_, trees)
        if trees and self.parsing then
          self.parsing = false
          api.nvim__redraw({ win = win, valid = false, flush = false })
        end
      end)
  if not self.parsing then
    self.redraw_count = self.redraw_count + 1
    self:prepare_highlight_states(topline, botline)
  else
    self:for_each_highlight_state(function(state)
      -- TODO(ribru17): Inefficient. Eventually all marks should be applied in on_buf, and all
      -- non-folded ranges of each open window should be merged, and iterators should only be
      -- created over those regions. This would also fix #31777.
      --
      -- Currently this is not possible because the parser discards previously parsed injection
      -- trees upon parsing a different region.
      --
      -- It would also be nice if rather than re-querying extmarks for old trees, we could tell the
      -- decoration provider to not clear previous ephemeral marks for this redraw cycle.
      state.iter = nil
      state.next_row = 0
    end)
  end
  return #self._highlight_states > 0
end

api.nvim_set_decoration_provider(ns, {
  on_win = TSHighlighter._on_win,
  on_line = TSHighlighter._on_line,
  on_buf = TSHighlighter._on_buf,