can be that the node itself has an error, or one of its descendants
has an error.
+@cindex tree-sitter live node
+@cindex live node, tree-sitter
+A node is ``live'' if its parser is not deleted, and the buffer it
+belongs to is live.
+
@defun treesit-node-check node property
This function checks if @var{node} has the specified @var{property}.
@var{property} can be @code{named}, @code{missing}, @code{extra},
-@code{outdated}, or @code{has-error}.
+@code{outdated}, @code{has-error}, or @code{live}.
@end defun
@defun treesit-node-type node
return XTS_PARSER (parser)->language_symbol;
}
+/* Return true if PARSER is not deleted and its buffer is live. */
+static bool
+treesit_parser_live_p (Lisp_Object parser)
+{
+ CHECK_TS_PARSER (parser);
+ return ((!XTS_PARSER (parser)->deleted) &&
+ (!NILP (Fbuffer_live_p (XTS_PARSER (parser)->buffer))));
+}
+
/*** Parser API */
DEFUN ("treesit-parser-root-node",
Ftreesit_node_check, Streesit_node_check, 2, 2, 0,
doc: /* Return non-nil if NODE has PROPERTY, nil otherwise.
-PROPERTY could be `named', `missing', `extra', `outdated', or `has-error'.
+PROPERTY could be `named', `missing', `extra', `outdated',
+`has-error', or `live'.
Named nodes correspond to named rules in the language definition,
whereas "anonymous" nodes correspond to string literals in the
the node was created.
A node "has error" if itself is a syntax error or contains any syntax
-errors. */)
+errors.
+
+A node is "live" if its parser is not deleted and its buffer is
+live. */)
(Lisp_Object node, Lisp_Object property)
{
if (NILP (node)) return Qnil;
result = ts_node_is_extra (treesit_node);
else if (EQ (property, Qhas_error))
result = ts_node_has_error (treesit_node);
+ else if (EQ (property, Qlive))
+ result = treesit_parser_live_p (XTS_NODE (node)->parser);
else
signal_error ("Expecting `named', `missing', `extra', "
- "`outdated', or `has-error', but got",
+ "`outdated', `has-error', or `live', but got",
property);
return result ? Qt : Qnil;
}
DEFSYM (Qextra, "extra");
DEFSYM (Qoutdated, "outdated");
DEFSYM (Qhas_error, "has-error");
+ DEFSYM (Qlive, "live");
DEFSYM (QCanchor, ":anchor");
DEFSYM (QCequal, ":equal");
(should (eq nil (treesit-node-check root-node 'missing)))
(should (eq nil (treesit-node-check root-node 'extra)))
(should (eq nil (treesit-node-check root-node 'has-error)))
+ (should (eq t (treesit-node-check root-node 'live)))
;; `treesit-node-child'.
(setq doc-node (treesit-node-child root-node 0))
(should (equal "array" (treesit-node-type doc-node)))
:type 'args-out-of-range)
;; `treesit-node-eq'.
(should (treesit-node-eq root-node root-node))
- (should (not (treesit-node-eq root-node doc-node))))))
+ (should (not (treesit-node-eq root-node doc-node)))
+
+ ;; Further test for `treesit-node-check'.
+ (treesit-parser-delete parser)
+ (should (equal nil (treesit-node-check root-node 'live)))
+ ;; Recreate parser.
+ (setq parser (treesit-parser-create 'json))
+ (setq root-node (treesit-parser-root-node
+ parser))
+ (should (equal t (treesit-node-check root-node 'live)))
+ (kill-buffer)
+ (should (equal nil (treesit-node-check root-node 'live))))))
;;; Indirect buffer