Function: treesit-update-ranges
treesit-update-ranges is a byte-compiled function defined in
treesit.el.gz.
Signature
(treesit-update-ranges &optional BEG END)
Documentation
Update the ranges for each language in the current buffer.
If BEG and END are non-nil, only update parser ranges in that region.
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-update-ranges (&optional beg end)
"Update the ranges for each language in the current buffer.
If BEG and END are non-nil, only update parser ranges in that
region."
(let ((modified-tick (buffer-chars-modified-tick))
(beg (or beg (point-min)))
(end (or end (point-max))))
;; When updating ranges, we want to avoid querying the whole buffer
;; which could be slow in very large buffers. Instead, we only
;; query for nodes that intersect with the region between BEG and
;; END. Also, we only update the ranges intersecting BEG and END;
;; outside of that region we inherit old ranges.
(dolist (setting treesit-range-settings)
(let ((query (nth 0 setting))
(language (nth 1 setting))
(local (nth 2 setting))
(offset (nth 3 setting)))
(cond
((functionp query) (funcall query beg end))
(local
(treesit--update-ranges-local
query language modified-tick beg end offset))
(t
(let* ((host-lang (treesit-query-language query))
(parser (treesit-parser-create language))
(old-ranges (treesit-parser-included-ranges parser))
(new-ranges (treesit-query-range
host-lang query beg end offset))
(set-ranges (treesit--clip-ranges
(treesit--merge-ranges
old-ranges new-ranges beg end)
(point-min) (point-max))))
(dolist (parser (treesit-parser-list nil language))
(treesit-parser-set-included-ranges
parser (or set-ranges
;; 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.
`((,(point-min) . ,(point-min)))))))))))
(treesit--cleanup-local-range-overlays modified-tick beg end)))