Fix treesit_sync_visible_region's range fixup code (bug#73264)

new_ranges_head
      |
      v
( )->( )->( )->( )->( )
           ^    ^
           |    |
           |    lisp_ranges (loop head)
           |
           prev_cons -> set cdr to nil to cut of the rest

result:

     ( )->( )

* src/treesit.c (treesit_sync_visible_region): Cut off this cons and the
rest, not set the current range's end to nil.
* test/src/treesit-tests.el:
(treesit-range-fixup-after-edit): Add tests for all cases.
This commit is contained in:
Yuan Fu
2024-09-15 00:24:03 -07:00
parent 81347c1aaf
commit 460b9d705a
2 changed files with 43 additions and 3 deletions

View File

@@ -709,7 +709,37 @@ visible_end.)"
'((1 . 7) (10 . 15))))
(narrow-to-region 5 13)
(should (equal (treesit-parser-included-ranges parser)
'((5 . 7) (10 . 13)))))))
'((5 . 7) (10 . 13))))
;; Narrow in front.
(widen)
(treesit-parser-set-included-ranges parser '((4 . 17)))
;; 11111111111111111111
;; [ ]
;; { } narrow
(narrow-to-region 1 8)
(should (equal (treesit-parser-included-ranges parser)
'((4 . 8))))
;; Narrow in back.
(widen)
(treesit-parser-set-included-ranges parser '((4 . 17)))
;; 11111111111111111111
;; [ ]
;; { } narrow
(narrow-to-region 15 20)
(should (equal (treesit-parser-included-ranges parser)
'((15 . 17))))
;; No overlap
(widen)
(treesit-parser-set-included-ranges parser '((15 . 20)))
;; 11111111111111111111
;; [ ]
;; { } narrow
(narrow-to-region 1 10)
(should (equal (treesit-parser-included-ranges parser)
nil)))))
;;; Multiple language