diff options
| author | Yuan Fu | 2022-12-28 15:30:10 -0800 |
|---|---|---|
| committer | Yuan Fu | 2022-12-28 15:30:10 -0800 |
| commit | f509246ba12ac791291f586340622871cdfc18ed (patch) | |
| tree | 26cd817ae37e05de4d7200c77150563beff3e987 /src | |
| parent | ec6feeaa19117deb0d60e97ad814b87ecbb7fa99 (diff) | |
| download | emacs-f509246ba12ac791291f586340622871cdfc18ed.tar.gz emacs-f509246ba12ac791291f586340622871cdfc18ed.zip | |
Call tree-sitter parser notifier on the first parse
* src/treesit.c (treesit_call_after_change_functions): Handle NULL
old_tree.
(treesit_ensure_parsed): Remove check for NULL tree.
Diffstat (limited to 'src')
| -rw-r--r-- | src/treesit.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/treesit.c b/src/treesit.c index e226df263c1..6570ada1d92 100644 --- a/src/treesit.c +++ b/src/treesit.c | |||
| @@ -933,11 +933,24 @@ static void | |||
| 933 | treesit_call_after_change_functions (TSTree *old_tree, TSTree *new_tree, | 933 | treesit_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 | ||
| @@ -996,11 +1009,8 @@ treesit_ensure_parsed (Lisp_Object parser) | |||
| 996 | treesit_ensure_parsed again, it returns early and do not | 1009 | treesit_ensure_parsed again, it returns early and do not |
| 997 | recursively call the after change functions again. | 1010 | recursively call the after change functions again. |
| 998 | (ref:notifier-inside-ensure-parsed) */ | 1011 | (ref:notifier-inside-ensure-parsed) */ |
| 999 | if (tree != NULL) | 1012 | treesit_call_after_change_functions (tree, new_tree, parser); |
| 1000 | { | 1013 | ts_tree_delete (tree); |
| 1001 | treesit_call_after_change_functions (tree, new_tree, parser); | ||
| 1002 | ts_tree_delete (tree); | ||
| 1003 | } | ||
| 1004 | } | 1014 | } |
| 1005 | 1015 | ||
| 1006 | /* 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 |