From b323baa31f2c5243f993b1d2a754fe27288085b6 Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Fri, 1 Aug 2025 09:17:00 -0700 Subject: [PATCH] fix(treesitter): simpler root node calculation This eliminates the need to traverse up the tree to find its root, which can be costly for deep trees. --- lua/nvim-surround/treesitter.lua | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lua/nvim-surround/treesitter.lua b/lua/nvim-surround/treesitter.lua index 83299b7..861e15e 100644 --- a/lua/nvim-surround/treesitter.lua +++ b/lua/nvim-surround/treesitter.lua @@ -37,15 +37,7 @@ end ---@nodiscard M.get_root = function() local node = get_node() - if node == nil then - return nil - end - - while node:parent() ~= nil do - node = node:parent() - end - - return node + return node and node:tree():root() end -- Gets the current smallest node at the cursor.