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

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

Open ispringle opened this issue 1 year ago • 8 comments

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.

ispringle avatar Apr 16 '24 20:04 ispringle

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 avatar Apr 16 '24 20:04 Dev380

20240416_17h00m18s_grim 20240416_16h59m52s_grim

Dev380 avatar Apr 16 '24 21:04 Dev380

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)))))

Dev380 avatar Apr 16 '24 21:04 Dev380

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 avatar Jun 06 '24 23:06 alexispurslane

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

alexispurslane avatar Jun 06 '24 23:06 alexispurslane

For anybody who made it here to look for solutions, here is what worked for me, this does have the additional weird behaviour where the first time the mode was opened, it tries to say the treesitter was not installed even though I was just prompted it was.

(use-package! astro-ts-mode
  :config
  (global-treesit-auto-mode)
  (let ((astro-recipe (make-treesit-auto-recipe
                       :lang 'astro
                       :ts-mode 'astro-ts-mode
                       :url "https://github.com/virchau13/tree-sitter-astro"
                       :revision "master"
                       :source-dir "src")))
    (add-to-list 'treesit-auto-recipe-list astro-recipe)
    (add-to-list 'treesit-auto-langs 'astro)
    ))

Trap101 avatar Aug 14 '24 10:08 Trap101

I did it like this and it's working without any issues.

(use-package treesit-auto
  :custom
  (treesit-auto-install nil)

  :config

  (let ((nix-recipe (make-treesit-auto-recipe
                   :lang 'nix
                   :ts-mode 'nix-ts-mode
                   :ext "\\.nix\\'")))
  (add-to-list 'treesit-auto-recipe-list nix-recipe)
  (add-to-list 'treesit-auto-langs 'nix))

  (treesit-auto-add-to-auto-mode-alist 'all)
  (global-treesit-auto-mode))

@alexispurslane I haven't looked at the source enough to be sure, but i'd guess the reason this is working but your example isn't is because i don't have a nix-mode already installed. maybe it's not running whatever remaps the existing major modes to the ts modes after you've added it to the list? you could try looking in major-mode-remap-alist and seeing if your remap ended up in there. you could probably just run (add-to-list 'major-mode-remap-alist '(emacs-lisp-mode . elisp-ts-mode)) if it's not putting it in there. although i haven't tested it.

beep-beep-beep-boop avatar Aug 26 '24 21:08 beep-beep-beep-boop

it looks like it might also be checking for treesit-ready-p when adding modes to the remap list, even if you set the auto-mode-alist to 'all. maybe it's thinking your mode isn't ready fsr? idk.

beep-beep-beep-boop avatar Aug 26 '24 22:08 beep-beep-beep-boop