renzmann / treesit-auto

Automatic installation, usage, and fallback for tree-sitter major modes in Emacs 29
GNU General Public License v3.0
353 stars 27 forks source link

custom recipes in treesit-auto-recipe-list do not seem to be installing #98

Open ispringle opened 3 months ago

ispringle commented 3 months ago

I have the following recipe:

    (setq astro-tsauto-config
          (make-treesit-auto-recipe
           :lang 'astro
           :ts-mode 'astro-ts-mode
           :url "https://github.com/virchau13/tree-sitter-astro"
           :revision "master"
           :source-dir "src"
           :ext "\\.astro\\'"))
    (add-to-list 'treesit-auto-recipe-list astro-tsauto-config)

This was working and then I ended up getting a new machine and noticed that when I started emacs I was getting the following warning:

⛔ Warning (treesit): Cannot activate tree-sitter, because language grammar for astro is unavailable (not-found): (libtree-sitter-astro.so libtree-sitter-astro.so.0 libtree-sitter-astro.so.0.0 libtree-sitter-astro.dylib libtree-sitter-astro.dylib.0 libtree-sitter-astro.dylib.0.0) No such file or directory

If I manually add the TS grammar and use the exact values in the recipe it works fine, but it seems from my perspective that TS expects the grammar to exist and treesit-auto is not installing it. When I M-x treesit-auto-install-all I'd expect to see astro listed, but I am not.

Dev380 commented 3 months ago

This happens for me too, and additionally when I tried to test it by removing the grammar for awk (which is predefined) I only get the prompt in the install-all command for awk once I restart emacs and I never get a prompt before entering the file to download the awk grammar and switch to the treesitter mode, despite treesit-auto-install being set to 'prompt. treesit-auto--maybe-install-grammar is returning nil in that awk file.

Dev380 commented 3 months ago

20240416_17h00m18s_grim 20240416_16h59m52s_grim

Dev380 commented 3 months ago

I'm not sure if this is related to the issue but I can't find anything in my config that sets treesit-auto-langs and it's showing that originally the custom modes I set were in treesit-auto-langs and now they have disappeared.

This is the function that I think might have caused it:

(defun treesit-auto--maybe-install-grammar ()
  "Try to install the grammar matching the current file extension.

If the tree-sitter grammar is missing for the current file type, this will
silently fail, automatically install the grammar, or prompt the user about
automatic installation, depending on the value of `treesit-auto-install'.  If
installation of the grammar is successful, activate the tree-sitter major mode."
  (when-let* ((recipe (treesit-auto--get-mode-recipe))
              (ts-mode (treesit-auto-recipe-ts-mode recipe))
              (not-ready (not (treesit-auto--ready-p ts-mode)))
              (ts-mode-exists (fboundp ts-mode))
              (lang (treesit-auto-recipe-lang recipe))
              (treesit-language-source-alist (treesit-auto--build-treesit-source-alist))
              (treesit-auto-langs (remove lang treesit-auto-langs)))
    (dolist (req-lang (ensure-list (treesit-auto-recipe-requires recipe)))
      (treesit-auto--prompt-to-install-package req-lang))
    (treesit-auto--prompt-to-install-package lang)
    (if (and (stringp buffer-file-name)
             (file-exists-p buffer-file-name))
        (revert-buffer nil t)
      (when (treesit-auto--ready-p lang)
        (funcall ts-mode)))))
alexispurslane commented 1 month ago

I'm running into this exact same problem, and it is very frustrating. I've created a custom tree sitter mode entry correctly, with a defined *-ts-mode, and added it to the recipe list, as well as adding the lang to the auto-langs list, but it doesn't seem to do anything at all. Here's my code:

(define-derived-mode elisp-ts-mode emacs-lisp-mode "ELisp[ts]"
    "Tree-sitter major mode for editing Emacs Lisp."
    :group 'rust
    (when (treesit-ready-p 'elisp)
        (treesit-parser-create 'elisp)
        (treesit-major-mode-setup)))

(use-package treesit-auto
    :custom
    (treesit-auto-install 'prompt)
    :config
    (setq elisp-tsauto-config
          (make-treesit-auto-recipe
           :lang 'elisp
           :ts-mode 'elisp-ts-mode
           :remap '(emacs-lisp-mode)
           :url "https://github.com/Wilfred/tree-sitter-elisp"
           :revision "main"
           :source-dir "src"
           :ext "\\.el\\'"))

    (add-to-list 'treesit-auto-recipe-list elisp-tsauto-config)
    (add-to-list 'treesit-auto-langs 'elisp)
    ;; The only lisp treesit-auto is missing out of the box is elisp, somehow!
    (treesit-auto-add-to-auto-mode-alist 'all)
    (global-treesit-auto-mode))
alexispurslane commented 1 month ago

If I manually run (treesit-auto--maybe-install-grammar) it works, but I don't know why I have to manually run that.