mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	fix(treesitter): remove more double recursion
Do not call `for_each_child` in functions that are already recursive.
This commit is contained in:
		
				
					committed by
					
						
						Lewis Russell
					
				
			
			
				
	
			
			
			
						parent
						
							1c4a93b591
						
					
				
				
					commit
					7a76fb8547
				
			@@ -101,17 +101,15 @@ function TSTreeView:new(bufnr, lang)
 | 
			
		||||
  -- the root in the child tree to the {injections} table.
 | 
			
		||||
  local root = parser:parse(true)[1]:root()
 | 
			
		||||
  local injections = {} ---@type table<integer,table>
 | 
			
		||||
  parser:for_each_child(function(child, lang_)
 | 
			
		||||
    child:for_each_tree(function(tree)
 | 
			
		||||
      local r = tree:root()
 | 
			
		||||
      local node = root:named_descendant_for_range(r:range())
 | 
			
		||||
      if node then
 | 
			
		||||
        injections[node:id()] = {
 | 
			
		||||
          lang = lang_,
 | 
			
		||||
          root = r,
 | 
			
		||||
        }
 | 
			
		||||
      end
 | 
			
		||||
    end)
 | 
			
		||||
  parser:for_each_tree(function(tree, ltree)
 | 
			
		||||
    local r = tree:root()
 | 
			
		||||
    local node = root:named_descendant_for_range(r:range())
 | 
			
		||||
    if node then
 | 
			
		||||
      injections[node:id()] = {
 | 
			
		||||
        lang = ltree:lang(),
 | 
			
		||||
        root = r,
 | 
			
		||||
      }
 | 
			
		||||
    end
 | 
			
		||||
  end)
 | 
			
		||||
 | 
			
		||||
  local nodes = traverse(root, 0, parser:lang(), injections, {})
 | 
			
		||||
 
 | 
			
		||||
@@ -897,6 +897,20 @@ function LanguageTree:_edit(
 | 
			
		||||
    end
 | 
			
		||||
    return true
 | 
			
		||||
  end)
 | 
			
		||||
 | 
			
		||||
  for _, child in pairs(self._children) do
 | 
			
		||||
    child:_edit(
 | 
			
		||||
      start_byte,
 | 
			
		||||
      end_byte_old,
 | 
			
		||||
      end_byte_new,
 | 
			
		||||
      start_row,
 | 
			
		||||
      start_col,
 | 
			
		||||
      end_row_old,
 | 
			
		||||
      end_col_old,
 | 
			
		||||
      end_row_new,
 | 
			
		||||
      end_col_new
 | 
			
		||||
    )
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
---@package
 | 
			
		||||
@@ -943,20 +957,17 @@ function LanguageTree:_on_bytes(
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
  -- Edit trees together BEFORE emitting a bytes callback.
 | 
			
		||||
  ---@private
 | 
			
		||||
  self:for_each_child(function(child)
 | 
			
		||||
    child:_edit(
 | 
			
		||||
      start_byte,
 | 
			
		||||
      start_byte + old_byte,
 | 
			
		||||
      start_byte + new_byte,
 | 
			
		||||
      start_row,
 | 
			
		||||
      start_col,
 | 
			
		||||
      start_row + old_row,
 | 
			
		||||
      old_end_col,
 | 
			
		||||
      start_row + new_row,
 | 
			
		||||
      new_end_col
 | 
			
		||||
    )
 | 
			
		||||
  end, true)
 | 
			
		||||
  self:_edit(
 | 
			
		||||
    start_byte,
 | 
			
		||||
    start_byte + old_byte,
 | 
			
		||||
    start_byte + new_byte,
 | 
			
		||||
    start_row,
 | 
			
		||||
    start_col,
 | 
			
		||||
    start_row + old_row,
 | 
			
		||||
    old_end_col,
 | 
			
		||||
    start_row + new_row,
 | 
			
		||||
    new_end_col
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
  self:_do_callback(
 | 
			
		||||
    'bytes',
 | 
			
		||||
@@ -1017,9 +1028,9 @@ function LanguageTree:register_cbs(cbs, recursive)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  if recursive then
 | 
			
		||||
    self:for_each_child(function(child)
 | 
			
		||||
    for _, child in pairs(self._children) do
 | 
			
		||||
      child:register_cbs(cbs, true)
 | 
			
		||||
    end)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user