Fix tree-sitter local parser overlay cleanup routine
authorYuan Fu <casouri@gmail.com>
Mon, 26 Aug 2024 00:59:51 +0000 (17:59 -0700)
committerYuan Fu <casouri@gmail.com>
Mon, 26 Aug 2024 01:15:06 +0000 (18:15 -0700)
commitb8c05d73a1105851bbe9871d6a64efc06ddc5b6e
tree4d5a28a8c59d1113b23a5dd691e10c6cbbb686b7
parentaa6ed7f67ec7ed08224e6ab2aab0a5b65f2bc314
Fix tree-sitter local parser overlay cleanup routine

Sorry for sneaking in a sizable commit so late.  But I just found out
about this bug and it has to be fixed.  Before this change, we weren't
properly cleaning up overlays that store local parsers.  And in the case
of doxygen local parser in C files, the doxygen local parser overlay
sometimes bleeds out of comments and into other code, and interferes
with font-lock and indentation.

This commit adds a cleanup function that'll cleanup any overlays that
aren't being used.  I tested with doxygen in C files and everything
works smoothly now, including tricky tests like removing the ending "*/"
of a doxygen comment and adding it back.

The idea is simple, at the end of each call to (treesit-update-ranges
BEG END), we remove any overlay within BEG and END that wasn't touched
by the range setting code.

* lisp/treesit.el (treesit--cleanup-local-range-overlays): New function.
(treesit--update-ranges-local): Remove code for cleaning up zero-length
overlays since we have the cleanup function now.
(treesit-update-ranges): Wrap the function body inside a let form, which
defines modified-tick; and add a call to
treesit--cleanup-local-range-overlays at the very end.
lisp/treesit.el