aboutsummaryrefslogtreecommitdiffstats
path: root/src/treesit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/treesit.c')
-rw-r--r--src/treesit.c49
1 files changed, 4 insertions, 45 deletions
diff --git a/src/treesit.c b/src/treesit.c
index 52d158b1bf8..d86ab501187 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -1017,8 +1017,9 @@ treesit_check_buffer_size (struct buffer *buffer)
1017 1017
1018static Lisp_Object treesit_make_ranges (const TSRange *, uint32_t, struct buffer *); 1018static Lisp_Object treesit_make_ranges (const TSRange *, uint32_t, struct buffer *);
1019 1019
1020static Lisp_Object 1020static void
1021treesit_get_changed_ranges (TSTree *old_tree, TSTree *new_tree, Lisp_Object parser) 1021treesit_call_after_change_functions (TSTree *old_tree, TSTree *new_tree,
1022 Lisp_Object parser)
1022{ 1023{
1023 /* If the old_tree is NULL, meaning this is the first parse, the 1024 /* If the old_tree is NULL, meaning this is the first parse, the
1024 changed range is the whole buffer. */ 1025 changed range is the whole buffer. */
@@ -1038,13 +1039,7 @@ treesit_get_changed_ranges (TSTree *old_tree, TSTree *new_tree, Lisp_Object pars
1038 lisp_ranges = Fcons (Fcons (Fpoint_min (), Fpoint_max ()), Qnil); 1039 lisp_ranges = Fcons (Fcons (Fpoint_min (), Fpoint_max ()), Qnil);
1039 set_buffer_internal (oldbuf); 1040 set_buffer_internal (oldbuf);
1040 } 1041 }
1041 return lisp_ranges;
1042}
1043 1042
1044static void
1045treesit_call_after_change_functions (Lisp_Object lisp_ranges,
1046 Lisp_Object parser)
1047{
1048 specpdl_ref count = SPECPDL_INDEX (); 1043 specpdl_ref count = SPECPDL_INDEX ();
1049 1044
1050 /* let's trust the after change functions and not clone a new ranges 1045 /* let's trust the after change functions and not clone a new ranges
@@ -1096,17 +1091,13 @@ treesit_ensure_parsed (Lisp_Object parser)
1096 XTS_PARSER (parser)->tree = new_tree; 1091 XTS_PARSER (parser)->tree = new_tree;
1097 XTS_PARSER (parser)->need_reparse = false; 1092 XTS_PARSER (parser)->need_reparse = false;
1098 1093
1099 Lisp_Object changed_ranges;
1100 changed_ranges = treesit_get_changed_ranges (tree, new_tree, parser);
1101 XTS_PARSER (parser)->last_changed_ranges = changed_ranges;
1102
1103 /* After-change functions should run at the very end, most crucially 1094 /* After-change functions should run at the very end, most crucially
1104 after need_reparse is set to false, this way if the function 1095 after need_reparse is set to false, this way if the function
1105 calls some tree-sitter function which invokes 1096 calls some tree-sitter function which invokes
1106 treesit_ensure_parsed again, it returns early and do not 1097 treesit_ensure_parsed again, it returns early and do not
1107 recursively call the after change functions again. 1098 recursively call the after change functions again.
1108 (ref:notifier-inside-ensure-parsed) */ 1099 (ref:notifier-inside-ensure-parsed) */
1109 treesit_call_after_change_functions (changed_ranges, parser); 1100 treesit_call_after_change_functions (tree, new_tree, parser);
1110 ts_tree_delete (tree); 1101 ts_tree_delete (tree);
1111} 1102}
1112 1103
@@ -1180,7 +1171,6 @@ make_treesit_parser (Lisp_Object buffer, TSParser *parser,
1180 lisp_parser->after_change_functions = Qnil; 1171 lisp_parser->after_change_functions = Qnil;
1181 lisp_parser->tag = tag; 1172 lisp_parser->tag = tag;
1182 lisp_parser->last_set_ranges = Qnil; 1173 lisp_parser->last_set_ranges = Qnil;
1183 lisp_parser->last_changed_ranges = Qnil;
1184 lisp_parser->buffer = buffer; 1174 lisp_parser->buffer = buffer;
1185 lisp_parser->parser = parser; 1175 lisp_parser->parser = parser;
1186 lisp_parser->tree = tree; 1176 lisp_parser->tree = tree;
@@ -1828,32 +1818,6 @@ positions. PARSER is the parser issuing the notification. */)
1828 return Qnil; 1818 return Qnil;
1829} 1819}
1830 1820
1831DEFUN ("treesit-parser-changed-ranges", Ftreesit_parser_changed_ranges,
1832 Streesit_parser_changed_ranges,
1833 1, 2, 0,
1834 doc: /* Return the buffer regions affected by the last reparse of PARSER.
1835
1836Returns a list of cons cells (BEG . END), where each cons cell represents
1837a region in which changes in buffer contents affected the last reparse.
1838
1839This function should almost always be called immediately after
1840reparsing. If it's called when there are new buffer edits that hasn't
1841been reparsed, Emacs signals the `treesit-unparsed-edits' error, unless
1842optional argument QUIET is non-nil.
1843
1844Calling this function multiple times consecutively doesn't change its
1845return value; it always returns the ranges affected by the last
1846reparse. */)
1847 (Lisp_Object parser, Lisp_Object quiet)
1848{
1849 treesit_check_parser (parser);
1850
1851 if (XTS_PARSER (parser)->need_reparse && NILP (quiet))
1852 xsignal1 (Qtreesit_unparsed_edits, parser);
1853
1854 return XTS_PARSER (parser)->last_changed_ranges;
1855}
1856
1857 1821
1858/*** Node API */ 1822/*** Node API */
1859 1823
@@ -4046,7 +4010,6 @@ syms_of_treesit (void)
4046 DEFSYM (Qtreesit_query_error, "treesit-query-error"); 4010 DEFSYM (Qtreesit_query_error, "treesit-query-error");
4047 DEFSYM (Qtreesit_parse_error, "treesit-parse-error"); 4011 DEFSYM (Qtreesit_parse_error, "treesit-parse-error");
4048 DEFSYM (Qtreesit_range_invalid, "treesit-range-invalid"); 4012 DEFSYM (Qtreesit_range_invalid, "treesit-range-invalid");
4049 DEFSYM (Qtreesit_unparsed_edits, "treesit-unparsed_edits");
4050 DEFSYM (Qtreesit_buffer_too_large, 4013 DEFSYM (Qtreesit_buffer_too_large,
4051 "treesit-buffer-too-large"); 4014 "treesit-buffer-too-large");
4052 DEFSYM (Qtreesit_load_language_error, 4015 DEFSYM (Qtreesit_load_language_error,
@@ -4075,8 +4038,6 @@ syms_of_treesit (void)
4075 define_error (Qtreesit_range_invalid, 4038 define_error (Qtreesit_range_invalid,
4076 "RANGES are invalid: they have to be ordered and should not overlap", 4039 "RANGES are invalid: they have to be ordered and should not overlap",
4077 Qtreesit_error); 4040 Qtreesit_error);
4078 define_error (Qtreesit_unparsed_edits, "There are unparsed edits in the buffer",
4079 Qtreesit_error);
4080 define_error (Qtreesit_buffer_too_large, "Buffer too large (> 4GiB)", 4041 define_error (Qtreesit_buffer_too_large, "Buffer too large (> 4GiB)",
4081 Qtreesit_error); 4042 Qtreesit_error);
4082 define_error (Qtreesit_load_language_error, 4043 define_error (Qtreesit_load_language_error,
@@ -4217,8 +4178,6 @@ the symbol of that THING. For example, (or sexp sentence). */);
4217 defsubr (&Streesit_parser_add_notifier); 4178 defsubr (&Streesit_parser_add_notifier);
4218 defsubr (&Streesit_parser_remove_notifier); 4179 defsubr (&Streesit_parser_remove_notifier);
4219 4180
4220 defsubr (&Streesit_parser_changed_ranges);
4221
4222 defsubr (&Streesit_node_type); 4181 defsubr (&Streesit_node_type);
4223 defsubr (&Streesit_node_start); 4182 defsubr (&Streesit_node_start);
4224 defsubr (&Streesit_node_end); 4183 defsubr (&Streesit_node_end);