Revert "Fix treesit-node-field-name and friends (bug#66674)"
This reverts commit 9874561f39
.
See bug#67990. Basically our original code is correct, the error is
in libtree-sitter, which only manifests in certain cases.
https://github.com/tree-sitter/tree-sitter/pull/2104
This commit is contained in:
parent
fa0bb88302
commit
5303152872
3 changed files with 7 additions and 7 deletions
|
@ -1015,8 +1015,8 @@ This function returns the field name of the @var{n}'th child of
|
||||||
@var{node}. It returns @code{nil} if there is no @var{n}'th child, or
|
@var{node}. It returns @code{nil} if there is no @var{n}'th child, or
|
||||||
the @var{n}'th child doesn't have a field name.
|
the @var{n}'th child doesn't have a field name.
|
||||||
|
|
||||||
Note that @var{n} counts named nodes only, and @var{n} can be
|
Note that @var{n} counts both named and anonymous children, and
|
||||||
negative, e.g., @minus{}1 represents the last child.
|
@var{n} can be negative, e.g., @minus{}1 represents the last child.
|
||||||
@end defun
|
@end defun
|
||||||
|
|
||||||
@defun treesit-node-child-count node &optional named
|
@defun treesit-node-child-count node &optional named
|
||||||
|
|
|
@ -360,7 +360,6 @@ If NAMED is non-nil, collect named child only."
|
||||||
"Return the index of NODE in its parent.
|
"Return the index of NODE in its parent.
|
||||||
If NAMED is non-nil, count named child only."
|
If NAMED is non-nil, count named child only."
|
||||||
(let ((count 0))
|
(let ((count 0))
|
||||||
;; TODO: Use next-sibling as it's more efficient.
|
|
||||||
(while (setq node (treesit-node-prev-sibling node named))
|
(while (setq node (treesit-node-prev-sibling node named))
|
||||||
(cl-incf count))
|
(cl-incf count))
|
||||||
count))
|
count))
|
||||||
|
@ -368,7 +367,7 @@ If NAMED is non-nil, count named child only."
|
||||||
(defun treesit-node-field-name (node)
|
(defun treesit-node-field-name (node)
|
||||||
"Return the field name of NODE as a child of its parent."
|
"Return the field name of NODE as a child of its parent."
|
||||||
(when-let ((parent (treesit-node-parent node))
|
(when-let ((parent (treesit-node-parent node))
|
||||||
(idx (treesit-node-index node t)))
|
(idx (treesit-node-index node)))
|
||||||
(treesit-node-field-name-for-child parent idx)))
|
(treesit-node-field-name-for-child parent idx)))
|
||||||
|
|
||||||
;;; Query API supplement
|
;;; Query API supplement
|
||||||
|
|
|
@ -2019,8 +2019,9 @@ DEFUN ("treesit-node-field-name-for-child",
|
||||||
Return nil if there's no Nth child, or if it has no field.
|
Return nil if there's no Nth child, or if it has no field.
|
||||||
If NODE is nil, return nil.
|
If NODE is nil, return nil.
|
||||||
|
|
||||||
Note that N counts named nodes only. Also, N could be negative, e.g.,
|
N counts all children, i.e., named ones and anonymous ones.
|
||||||
-1 represents the last child. */)
|
|
||||||
|
N could be negative, e.g., -1 represents the last child. */)
|
||||||
(Lisp_Object node, Lisp_Object n)
|
(Lisp_Object node, Lisp_Object n)
|
||||||
{
|
{
|
||||||
if (NILP (node))
|
if (NILP (node))
|
||||||
|
@ -2034,7 +2035,7 @@ Note that N counts named nodes only. Also, N could be negative, e.g.,
|
||||||
|
|
||||||
/* Process negative index. */
|
/* Process negative index. */
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
idx = ts_node_named_child_count (treesit_node) + idx;
|
idx = ts_node_child_count (treesit_node) + idx;
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
if (idx > UINT32_MAX)
|
if (idx > UINT32_MAX)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue