summaryrefslogtreecommitdiff
path: root/src/treesit.c
diff options
context:
space:
mode:
authorYuan Fu <casouri@gmail.com>2023-01-12 17:07:21 -0800
committerYuan Fu <casouri@gmail.com>2023-01-12 17:11:38 -0800
commit956889d8ff1c79db45ca9b1711f406961e71c272 (patch)
tree4d44cc819db4ff7433ac2a02bf61f693182de00f /src/treesit.c
parent8f446c2d39736d752829e37100eede3f484b827e (diff)
downloademacs-956889d8ff1c79db45ca9b1711f406961e71c272.tar.gz
Equal now recognizes tree-sitter nodes (bug#60659)
Now equal uses ts_node_eq to check equality between nodes. * doc/lispref/parsing.texi: (Accessing Node Information): Update manual. * src/fns.c (internal_equal): Handle tree-sitter nodes. * src/treesit.c (treesit_node_eq): New function. (Ftreesit_node_eq): Factor out. Update docstring. * src/treesit.h (treesit_node_eq): Declare new function.
Diffstat (limited to 'src/treesit.c')
-rw-r--r--src/treesit.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/treesit.c b/src/treesit.c
index 55463122d14..d2db91604ab 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -2154,11 +2154,22 @@ If NODE is nil, return nil. */)
return make_treesit_node (XTS_NODE (node)->parser, child);
}
+/* Return true if NODE1 and NODE2 are the same node. Assumes they are
+ TS_NODE type. */
+bool treesit_node_eq (Lisp_Object node1, Lisp_Object node2)
+{
+ treesit_initialize ();
+ TSNode treesit_node_1 = XTS_NODE (node1)->node;
+ TSNode treesit_node_2 = XTS_NODE (node2)->node;
+ return ts_node_eq (treesit_node_1, treesit_node_2);
+}
+
DEFUN ("treesit-node-eq",
Ftreesit_node_eq,
Streesit_node_eq, 2, 2, 0,
doc: /* Return non-nil if NODE1 and NODE2 are the same node.
-If any one of NODE1 and NODE2 is nil, return nil. */)
+If any one of NODE1 and NODE2 is nil, return nil.
+This function uses the same equivalence metric as `equal'. */)
(Lisp_Object node1, Lisp_Object node2)
{
if (NILP (node1) || NILP (node2))
@@ -2166,12 +2177,7 @@ If any one of NODE1 and NODE2 is nil, return nil. */)
CHECK_TS_NODE (node1);
CHECK_TS_NODE (node2);
- treesit_initialize ();
-
- TSNode treesit_node_1 = XTS_NODE (node1)->node;
- TSNode treesit_node_2 = XTS_NODE (node2)->node;
-
- bool same_node = ts_node_eq (treesit_node_1, treesit_node_2);
+ bool same_node = treesit_node_eq (node1, node2);
return same_node ? Qt : Qnil;
}