[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-30 f0daa2f2153: Conservative heuristic for tree-sitter parser rang
From: |
Yuan Fu |
Subject: |
emacs-30 f0daa2f2153: Conservative heuristic for tree-sitter parser ranges (bug#73324) |
Date: |
Wed, 18 Sep 2024 00:26:41 -0400 (EDT) |
branch: emacs-30
commit f0daa2f2153a9d250d32ac1261a6fffb30860e31
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
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.
---
src/treesit.c | 41 ++++++++++++++++++-----------------------
test/src/treesit-tests.el | 2 +-
2 files changed, 19 insertions(+), 24 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)
prev_cons = lisp_ranges;
}
+ /* We are in a weird situation here: none of the previous ranges
+ overlaps with the new visible region. We don't have any good
+ options, so just throw the towel: just give the parser a zero
+ range. (Perfect filling!!) */
+ if (NILP (new_ranges_head))
+ new_ranges_head = Fcons (Fcons (make_fixnum (visible_beg),
+ make_fixnum (visible_beg)),
+ Qnil);
+
XTS_PARSER (parser)->last_set_ranges = new_ranges_head;
- if (NILP (new_ranges_head))
- {
- /* We are in a weird situation here: none of the previous ranges
- overlaps with the new visible region. We don't have any good
- options, so just throw the towel: just remove ranges and hope
- lisp world will soon update with reasonable ranges or just
- delete this parser. */
- bool success;
- success = ts_parser_set_included_ranges (XTS_PARSER (parser)->parser,
- NULL, 0);
- eassert (success);
- }
- else
- {
- uint32_t len = 0;
- TSRange *ts_ranges = treesit_make_ts_ranges (new_ranges_head, parser,
- &len);
- bool success;
- success = ts_parser_set_included_ranges (XTS_PARSER (parser)->parser,
- ts_ranges, len);
- xfree (ts_ranges);
- eassert (success);
- }
+ uint32_t len = 0;
+ TSRange *ts_ranges = NULL;
+ ts_ranges = treesit_make_ts_ranges (new_ranges_head, parser,
+ &len);
+ bool success;
+ success = ts_parser_set_included_ranges (XTS_PARSER (parser)->parser,
+ ts_ranges, len);
+ xfree (ts_ranges);
+ eassert (success);
}
/* (ref:bytepos-range-pitfall) Suppose we have the following buffer
diff --git a/test/src/treesit-tests.el b/test/src/treesit-tests.el
index 6256b1d2fb9..24cd755fcf0 100644
--- a/test/src/treesit-tests.el
+++ b/test/src/treesit-tests.el
@@ -741,7 +741,7 @@ visible_end.)"
;; { } narrow
(narrow-to-region 1 10)
(should (equal (treesit-parser-included-ranges parser)
- nil)))))
+ '((1 . 1)))))))
;;; Multiple language
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- emacs-30 f0daa2f2153: Conservative heuristic for tree-sitter parser ranges (bug#73324),
Yuan Fu <=