treesit-auto icon indicating copy to clipboard operation
treesit-auto copied to clipboard

How to *update* language libs?

Open garyo opened this issue 1 year ago • 2 comments

Treesit-auto-install-all will find any languages not yet installed, but I don't think it tracks versions so it can't update languages if their upstream code has been improved. It would be nice to be able to update.

garyo avatar Aug 18 '24 21:08 garyo

To be honest, I don't think automatic version update is a desired behavior for most people. Since the base Tree-Sitter API is not versioned, new types of nodes might be added and Emacs treesit will scream and self-destruct. ~~(cough typescript cough)~~

Maybe addressing #99 can partially solve this problem? When you need a new version, simply navigate to user-emacs-directory and delete the .so file you want to update, then new grammar definition should be one treesit-auto-install-all away.

RangHo avatar Aug 20 '24 06:08 RangHo

This helps when I want to update all grammars by treesit-auto:

(defun my/update-treesit-auto-grammars ()
  "Update tree sitter grammars defined by `treesit-auto'."
  (interactive)
  (let* ((files (directory-files (locate-user-emacs-file "tree-sitter") nil directory-files-no-dot-files-regexp))
         (langs (mapcar
                 (lambda (file)
                   (and (string-match
                         (format "libtree-sitter-\\(.+\\)%s" (car dynamic-library-suffixes))
                         file)
                        (intern (match-string 1 file))))
                 files))
         (treesit-language-source-alist (treesit-auto--build-treesit-source-alist)))
    (cl-loop for lang in langs do
             (if (assoc lang treesit-language-source-alist)
                 (progn
                   (message "Installing language grammar for: %s" lang)
                   (treesit-install-language-grammar lang))
               (message "Skipping grammar for %s" lang)))))

avishefi avatar Dec 10 '24 16:12 avishefi