aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Kangas2022-12-29 06:30:09 +0100
committerStefan Kangas2022-12-29 06:30:09 +0100
commitd9d90666f545dc25be63c1b16c030ce1aa96510e (patch)
tree21b45187f7167d781d5b0562234826b5508d1dce /src
parentdce6791e9934d029ffae45793a5d05096346be0c (diff)
parent909091d7578b7225601b202fb9257dedae879e9a (diff)
downloademacs-d9d90666f545dc25be63c1b16c030ce1aa96510e.tar.gz
emacs-d9d90666f545dc25be63c1b16c030ce1aa96510e.zip
Merge from origin/emacs-29
909091d7578 ; Minor cleanup for tree-sitter font-lock rules in js-ts-... e78e69b3318 Clean up font-lock rules in js-ts-mode 0a61e4e2b71 ; * doc/lispref/parsing.texi (Using Parser): Minor improv... 398ed75c276 ; * lisp/progmodes/c-ts-mode.el (c-ts-mode--fill-paragrap... 19b8733aa27 Fix syntax for < and > in c++-ts-mode (bug#60351) f509246ba12 Call tree-sitter parser notifier on the first parse ec6feeaa191 Fix tree-sitter parser notifier recursion
Diffstat (limited to 'src')
-rw-r--r--src/treesit.c43
1 files changed, 31 insertions, 12 deletions
diff --git a/src/treesit.c b/src/treesit.c
index 813d4222f98..6570ada1d92 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -933,11 +933,24 @@ static void
933treesit_call_after_change_functions (TSTree *old_tree, TSTree *new_tree, 933treesit_call_after_change_functions (TSTree *old_tree, TSTree *new_tree,
934 Lisp_Object parser) 934 Lisp_Object parser)
935{ 935{
936 uint32_t len; 936 /* If the old_tree is NULL, meaning this is the first parse, the
937 TSRange *ranges = ts_tree_get_changed_ranges (old_tree, new_tree, &len); 937 changed range is the whole buffer. */
938 Lisp_Object lisp_ranges;
938 struct buffer *buf = XBUFFER (XTS_PARSER (parser)->buffer); 939 struct buffer *buf = XBUFFER (XTS_PARSER (parser)->buffer);
939 Lisp_Object lisp_ranges = treesit_make_ranges (ranges, len, buf); 940 if (old_tree)
940 xfree (ranges); 941 {
942 uint32_t len;
943 TSRange *ranges = ts_tree_get_changed_ranges (old_tree, new_tree, &len);
944 lisp_ranges = treesit_make_ranges (ranges, len, buf);
945 xfree (ranges);
946 }
947 else
948 {
949 struct buffer *oldbuf = current_buffer;
950 set_buffer_internal (buf);
951 lisp_ranges = Fcons (Fcons (Fpoint_min (), Fpoint_max ()), Qnil);
952 set_buffer_internal (oldbuf);
953 }
941 954
942 specpdl_ref count = SPECPDL_INDEX (); 955 specpdl_ref count = SPECPDL_INDEX ();
943 956
@@ -955,6 +968,11 @@ treesit_call_after_change_functions (TSTree *old_tree, TSTree *new_tree,
955static void 968static void
956treesit_ensure_parsed (Lisp_Object parser) 969treesit_ensure_parsed (Lisp_Object parser)
957{ 970{
971 /* Make sure this comes before everything else, see comment
972 (ref:notifier-inside-ensure-parsed) for more detail. */
973 if (!XTS_PARSER (parser)->need_reparse)
974 return;
975
958 struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer); 976 struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer);
959 977
960 /* Before we parse, catch up with the narrowing situation. */ 978 /* Before we parse, catch up with the narrowing situation. */
@@ -963,8 +981,6 @@ treesit_ensure_parsed (Lisp_Object parser)
963 because it might set the flag to true. */ 981 because it might set the flag to true. */
964 treesit_sync_visible_region (parser); 982 treesit_sync_visible_region (parser);
965 983
966 if (!XTS_PARSER (parser)->need_reparse)
967 return;
968 TSParser *treesit_parser = XTS_PARSER (parser)->parser; 984 TSParser *treesit_parser = XTS_PARSER (parser)->parser;
969 TSTree *tree = XTS_PARSER (parser)->tree; 985 TSTree *tree = XTS_PARSER (parser)->tree;
970 TSInput input = XTS_PARSER (parser)->input; 986 TSInput input = XTS_PARSER (parser)->input;
@@ -984,14 +1000,17 @@ treesit_ensure_parsed (Lisp_Object parser)
984 xsignal1 (Qtreesit_parse_error, buf); 1000 xsignal1 (Qtreesit_parse_error, buf);
985 } 1001 }
986 1002
987 if (tree != NULL)
988 {
989 treesit_call_after_change_functions (tree, new_tree, parser);
990 ts_tree_delete (tree);
991 }
992
993 XTS_PARSER (parser)->tree = new_tree; 1003 XTS_PARSER (parser)->tree = new_tree;
994 XTS_PARSER (parser)->need_reparse = false; 1004 XTS_PARSER (parser)->need_reparse = false;
1005
1006 /* After-change functions should run at the very end, most crucially
1007 after need_reparse is set to false, this way if the function
1008 calls some tree-sitter function which invokes
1009 treesit_ensure_parsed again, it returns early and do not
1010 recursively call the after change functions again.
1011 (ref:notifier-inside-ensure-parsed) */
1012 treesit_call_after_change_functions (tree, new_tree, parser);
1013 ts_tree_delete (tree);
995} 1014}
996 1015
997/* This is the read function provided to tree-sitter to read from a 1016/* This is the read function provided to tree-sitter to read from a