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.

View in manual

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."
  ;; 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))
          (beg (or beg (point-min)))
          (end (or end (point-max))))
      (if (functionp query) (funcall query beg end)
        (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))
               (set-ranges (treesit--clip-ranges
                            (treesit--merge-ranges
                             old-ranges new-ranges beg end)
                            (point-min) (point-max))))
          (dolist (parser (treesit-parser-list))
            (when (eq (treesit-parser-language parser)
                      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))))))))))))