mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-11 06:30:51 +00:00
Add recursion limit to treesit--children-covering-range-recurse
* lisp/treesit.el (treesit--children-covering-range-recurse): Add limit.
This commit is contained in:
parent
b429e52428
commit
670daa8b62
1 changed files with 11 additions and 4 deletions
|
@ -833,21 +833,28 @@ The range is between START and END."
|
||||||
(nreverse result))
|
(nreverse result))
|
||||||
(list node)))
|
(list node)))
|
||||||
|
|
||||||
(defun treesit--children-covering-range-recurse (node start end threshold)
|
(defun treesit--children-covering-range-recurse
|
||||||
|
(node start end threshold &optional limit)
|
||||||
"Return a list of children of NODE covering a range.
|
"Return a list of children of NODE covering a range.
|
||||||
|
|
||||||
Recursively go down the parse tree and collect children, until
|
Recursively go down the parse tree and collect children, until
|
||||||
all nodes in the returned list are smaller than THRESHOLD. The
|
all nodes in the returned list are smaller than THRESHOLD. The
|
||||||
range is between START and END."
|
range is between START and END.
|
||||||
|
|
||||||
|
LIMIT is the recursion limit, which defaults to 100."
|
||||||
(let* ((child (treesit-node-first-child-for-pos node start))
|
(let* ((child (treesit-node-first-child-for-pos node start))
|
||||||
|
(limit (or limit 100))
|
||||||
result)
|
result)
|
||||||
(while (and child (<= (treesit-node-start child) end))
|
;; If LIMIT is exceeded, we are probably seeing the erroneously
|
||||||
|
;; tall tree, in that case, just give up.
|
||||||
|
(while (and (> limit 0) child (<= (treesit-node-start child) end))
|
||||||
;; If child still too large, recurse down. Otherwise collect
|
;; If child still too large, recurse down. Otherwise collect
|
||||||
;; child.
|
;; child.
|
||||||
(if (> (- (treesit-node-end child)
|
(if (> (- (treesit-node-end child)
|
||||||
(treesit-node-start child))
|
(treesit-node-start child))
|
||||||
threshold)
|
threshold)
|
||||||
(dolist (r (treesit--children-covering-range-recurse
|
(dolist (r (treesit--children-covering-range-recurse
|
||||||
child start end threshold))
|
child start end threshold (1- limit)))
|
||||||
(push r result))
|
(push r result))
|
||||||
(push child result))
|
(push child result))
|
||||||
(setq child (treesit-node-next-sibling child)))
|
(setq child (treesit-node-next-sibling child)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue