aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/treesit.c50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/treesit.c b/src/treesit.c
index 9926806612a..8b485ca4ece 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -1642,6 +1642,17 @@ treesit_check_node (Lisp_Object obj)
1642 xsignal1 (Qtreesit_node_outdated, obj); 1642 xsignal1 (Qtreesit_node_outdated, obj);
1643} 1643}
1644 1644
1645/* Checks that OBJ is a positive integer and it is within the visible
1646 portion of BUF. */
1647static void
1648treesit_check_position (Lisp_Object obj, struct buffer *buf)
1649{
1650 treesit_check_positive_integer (obj);
1651 ptrdiff_t pos = XFIXNUM (obj);
1652 if (pos < BUF_BEGV (buf) || pos > BUF_ZV (buf))
1653 xsignal1 (Qargs_out_of_range, obj);
1654}
1655
1645bool 1656bool
1646treesit_node_uptodate_p (Lisp_Object obj) 1657treesit_node_uptodate_p (Lisp_Object obj)
1647{ 1658{
@@ -1990,14 +2001,12 @@ Note that this function returns an immediate child, not the smallest
1990 if (NILP (node)) 2001 if (NILP (node))
1991 return Qnil; 2002 return Qnil;
1992 treesit_check_node (node); 2003 treesit_check_node (node);
1993 treesit_check_positive_integer (pos);
1994 2004
1995 struct buffer *buf = XBUFFER (XTS_PARSER (XTS_NODE (node)->parser)->buffer); 2005 struct buffer *buf = XBUFFER (XTS_PARSER (XTS_NODE (node)->parser)->buffer);
1996 ptrdiff_t visible_beg = XTS_PARSER (XTS_NODE (node)->parser)->visible_beg; 2006 ptrdiff_t visible_beg = XTS_PARSER (XTS_NODE (node)->parser)->visible_beg;
1997 ptrdiff_t byte_pos = buf_charpos_to_bytepos (buf, XFIXNUM (pos)); 2007 ptrdiff_t byte_pos = buf_charpos_to_bytepos (buf, XFIXNUM (pos));
1998 2008
1999 if (byte_pos < BUF_BEGV_BYTE (buf) || byte_pos > BUF_ZV_BYTE (buf)) 2009 treesit_check_position (pos, buf);
2000 xsignal1 (Qargs_out_of_range, pos);
2001 2010
2002 treesit_initialize (); 2011 treesit_initialize ();
2003 2012
@@ -2028,19 +2037,14 @@ If NODE is nil, return nil. */)
2028{ 2037{
2029 if (NILP (node)) return Qnil; 2038 if (NILP (node)) return Qnil;
2030 treesit_check_node (node); 2039 treesit_check_node (node);
2031 CHECK_INTEGER (beg);
2032 CHECK_INTEGER (end);
2033 2040
2034 struct buffer *buf = XBUFFER (XTS_PARSER (XTS_NODE (node)->parser)->buffer); 2041 struct buffer *buf = XBUFFER (XTS_PARSER (XTS_NODE (node)->parser)->buffer);
2035 ptrdiff_t visible_beg = XTS_PARSER (XTS_NODE (node)->parser)->visible_beg; 2042 ptrdiff_t visible_beg = XTS_PARSER (XTS_NODE (node)->parser)->visible_beg;
2036 ptrdiff_t byte_beg = buf_charpos_to_bytepos (buf, XFIXNUM (beg)); 2043 ptrdiff_t byte_beg = buf_charpos_to_bytepos (buf, XFIXNUM (beg));
2037 ptrdiff_t byte_end = buf_charpos_to_bytepos (buf, XFIXNUM (end)); 2044 ptrdiff_t byte_end = buf_charpos_to_bytepos (buf, XFIXNUM (end));
2038 2045
2039 /* Checks for BUFFER_BEG <= BEG <= END <= BUFFER_END. */ 2046 treesit_check_position (beg, buf);
2040 if (!(BUF_BEGV_BYTE (buf) <= byte_beg 2047 treesit_check_position (end, buf);
2041 && byte_beg <= byte_end
2042 && byte_end <= BUF_ZV_BYTE (buf)))
2043 xsignal2 (Qargs_out_of_range, beg, end);
2044 2048
2045 treesit_initialize (); 2049 treesit_initialize ();
2046 2050
@@ -2426,21 +2430,24 @@ the query. */)
2426 (Lisp_Object node, Lisp_Object query, 2430 (Lisp_Object node, Lisp_Object query,
2427 Lisp_Object beg, Lisp_Object end, Lisp_Object node_only) 2431 Lisp_Object beg, Lisp_Object end, Lisp_Object node_only)
2428{ 2432{
2429 if (!NILP (beg))
2430 CHECK_INTEGER (beg);
2431 if (!NILP (end))
2432 CHECK_INTEGER (end);
2433
2434 if (!(TS_COMPILED_QUERY_P (query) 2433 if (!(TS_COMPILED_QUERY_P (query)
2435 || CONSP (query) || STRINGP (query))) 2434 || CONSP (query) || STRINGP (query)))
2436 wrong_type_argument (Qtreesit_query_p, query); 2435 wrong_type_argument (Qtreesit_query_p, query);
2437 2436
2437 treesit_initialize ();
2438
2438 /* Resolve NODE into an actual node. */ 2439 /* Resolve NODE into an actual node. */
2439 Lisp_Object lisp_node; 2440 Lisp_Object lisp_node;
2440 if (TS_NODEP (node)) 2441 if (TS_NODEP (node))
2441 lisp_node = node; 2442 {
2443 treesit_check_node (node); /* Check if up-to-date. */
2444 lisp_node = node;
2445 }
2442 else if (TS_PARSERP (node)) 2446 else if (TS_PARSERP (node))
2443 lisp_node = Ftreesit_parser_root_node (node); 2447 {
2448 treesit_check_parser (node); /* Check if deleted. */
2449 lisp_node = Ftreesit_parser_root_node (node);
2450 }
2444 else if (SYMBOLP (node)) 2451 else if (SYMBOLP (node))
2445 { 2452 {
2446 Lisp_Object parser 2453 Lisp_Object parser
@@ -2452,8 +2459,6 @@ the query. */)
2452 list4 (Qor, Qtreesit_node_p, Qtreesit_parser_p, Qsymbolp), 2459 list4 (Qor, Qtreesit_node_p, Qtreesit_parser_p, Qsymbolp),
2453 node); 2460 node);
2454 2461
2455 treesit_initialize ();
2456
2457 /* Extract C values from Lisp objects. */ 2462 /* Extract C values from Lisp objects. */
2458 TSNode treesit_node 2463 TSNode treesit_node
2459 = XTS_NODE (lisp_node)->node; 2464 = XTS_NODE (lisp_node)->node;
@@ -2464,6 +2469,13 @@ the query. */)
2464 const TSLanguage *lang 2469 const TSLanguage *lang
2465 = ts_parser_language (XTS_PARSER (lisp_parser)->parser); 2470 = ts_parser_language (XTS_PARSER (lisp_parser)->parser);
2466 2471
2472 /* Check BEG and END. */
2473 struct buffer *buf = XBUFFER (XTS_PARSER (lisp_parser)->buffer);
2474 if (!NILP (beg))
2475 treesit_check_position (beg, buf);
2476 if (!NILP (end))
2477 treesit_check_position (end, buf);
2478
2467 /* Initialize query objects. At the end of this block, we should 2479 /* Initialize query objects. At the end of this block, we should
2468 have a working TSQuery and a TSQueryCursor. */ 2480 have a working TSQuery and a TSQueryCursor. */
2469 TSQuery *treesit_query; 2481 TSQuery *treesit_query;