diff options
| author | Yuan Fu | 2024-09-17 21:17:13 -0700 |
|---|---|---|
| committer | Yuan Fu | 2024-09-17 21:18:28 -0700 |
| commit | f0daa2f2153a9d250d32ac1261a6fffb30860e31 (patch) | |
| tree | be9e9161088e18acee1c0cb56cd22f1b134dd8ee /src | |
| parent | 035024b4e5a8eb759e30ce72ed3b83036f35525e (diff) | |
| download | emacs-f0daa2f2153a9d250d32ac1261a6fffb30860e31.tar.gz emacs-f0daa2f2153a9d250d32ac1261a6fffb30860e31.zip | |
Conservative heuristic for tree-sitter parser ranges (bug#73324)
* src/treesit.c (treesit_sync_visible_region): If the parser's original
ranges don't overlap with visible region, give it a zero range, rather
than don't set any range.
* test/src/treesit-tests.el (treesit-range-fixup-after-edit): Test new
behavior.
Diffstat (limited to 'src')
| -rw-r--r-- | src/treesit.c | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/src/treesit.c b/src/treesit.c index 8fc7385a3da..84d903b027c 100644 --- a/src/treesit.c +++ b/src/treesit.c | |||
| @@ -1098,31 +1098,26 @@ treesit_sync_visible_region (Lisp_Object parser) | |||
| 1098 | prev_cons = lisp_ranges; | 1098 | prev_cons = lisp_ranges; |
| 1099 | } | 1099 | } |
| 1100 | 1100 | ||
| 1101 | /* We are in a weird situation here: none of the previous ranges | ||
| 1102 | overlaps with the new visible region. We don't have any good | ||
| 1103 | options, so just throw the towel: just give the parser a zero | ||
| 1104 | range. (Perfect filling!!) */ | ||
| 1105 | if (NILP (new_ranges_head)) | ||
| 1106 | new_ranges_head = Fcons (Fcons (make_fixnum (visible_beg), | ||
| 1107 | make_fixnum (visible_beg)), | ||
| 1108 | Qnil); | ||
| 1109 | |||
| 1101 | XTS_PARSER (parser)->last_set_ranges = new_ranges_head; | 1110 | XTS_PARSER (parser)->last_set_ranges = new_ranges_head; |
| 1102 | 1111 | ||
| 1103 | if (NILP (new_ranges_head)) | 1112 | uint32_t len = 0; |
| 1104 | { | 1113 | TSRange *ts_ranges = NULL; |
| 1105 | /* We are in a weird situation here: none of the previous ranges | 1114 | ts_ranges = treesit_make_ts_ranges (new_ranges_head, parser, |
| 1106 | overlaps with the new visible region. We don't have any good | 1115 | &len); |
| 1107 | options, so just throw the towel: just remove ranges and hope | 1116 | bool success; |
| 1108 | lisp world will soon update with reasonable ranges or just | 1117 | success = ts_parser_set_included_ranges (XTS_PARSER (parser)->parser, |
| 1109 | delete this parser. */ | 1118 | ts_ranges, len); |
| 1110 | bool success; | 1119 | xfree (ts_ranges); |
| 1111 | success = ts_parser_set_included_ranges (XTS_PARSER (parser)->parser, | 1120 | eassert (success); |
| 1112 | NULL, 0); | ||
| 1113 | eassert (success); | ||
| 1114 | } | ||
| 1115 | else | ||
| 1116 | { | ||
| 1117 | uint32_t len = 0; | ||
| 1118 | TSRange *ts_ranges = treesit_make_ts_ranges (new_ranges_head, parser, | ||
| 1119 | &len); | ||
| 1120 | bool success; | ||
| 1121 | success = ts_parser_set_included_ranges (XTS_PARSER (parser)->parser, | ||
| 1122 | ts_ranges, len); | ||
| 1123 | xfree (ts_ranges); | ||
| 1124 | eassert (success); | ||
| 1125 | } | ||
| 1126 | } | 1121 | } |
| 1127 | 1122 | ||
| 1128 | /* (ref:bytepos-range-pitfall) Suppose we have the following buffer | 1123 | /* (ref:bytepos-range-pitfall) Suppose we have the following buffer |