Function: treesit--set-embed-ranges
treesit--set-embed-ranges is a byte-compiled function defined in
treesit.el.gz.
Signature
(treesit--set-embed-ranges RANGES EMBED-PARSER HOST-PARSER)
Documentation
A helper for setting RANGES to EMBED-PARSER.
Take HOST-PARSER's ranges and intersect with RANGES, then set to
EMBED-PARSER. If the intersection is empty, give EMBED-PARSER a
0-length ranges.
RANGES is a list of (START . END) or just (START . END).
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit--set-embed-ranges (ranges embed-parser host-parser)
"A helper for setting RANGES to EMBED-PARSER.
Take HOST-PARSER's ranges and intersect with RANGES, then set to
EMBED-PARSER. If the intersection is empty, give EMBED-PARSER a
0-length ranges.
RANGES is a list of (START . END) or just (START . END)."
(let* ((new-ranges-1 (cond
((null ranges) nil)
((consp (car ranges)) ranges)
(t (list ranges))))
(host-ranges (treesit-parser-included-ranges host-parser))
(new-ranges (if (and host-ranges new-ranges-1)
(treesit--intersect-ranges
new-ranges-1 host-ranges)
new-ranges-1)))
(when (and (null new-ranges) treesit--range-verbose)
(message "Setting empty ranges to %s\nRanges for embedded parser :%s\nRanges for host parser: %s\nIntersection is empty"
new-ranges-1 embed-parser host-parser))
;; Due to some tree-sitter bug[1], we need to force a full reparse for
;; some languages to get a correct parse tree.
;; [1] https://github.com/tree-sitter/tree-sitter/issues/5636
(when (memq (treesit-parser-language embed-parser)
treesit--embed-languages-need-full-parse)
(treesit-parser-set-included-ranges
embed-parser `((,(point-min) . ,(point-min))))
(treesit-parser-root-node embed-parser))
;; When there's no range for the embedded language, set it's range
;; to a dummy (1 . 1), otherwise it would be set to the whole
;; buffer, which is not what we want.
(treesit-parser-set-included-ranges
embed-parser (or new-ranges `((,(point-min) . ,(point-min)))))))