Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No support for rustic-mode #41

Closed
CSRaghunandan opened this issue Jun 7, 2020 · 15 comments
Closed

No support for rustic-mode #41

CSRaghunandan opened this issue Jun 7, 2020 · 15 comments

Comments

@CSRaghunandan
Copy link

I use rustic-mode instead of rust-mode as the major mode for Rust files in emacs and emacs-tree-sitter has no support for it :(

Can you please add support for rustic-mode

@ubolonton
Copy link
Collaborator

I'll add it in the next release.

You can also customize tree-sitter-major-mode-language-alist to make it work:

(add-to-list 'tree-sitter-major-mode-language-alist '(rustic-mode . rust))

@CSRaghunandan
Copy link
Author

Okay, I added that to my emacs config, but now when I open a rust file, I am getting the below error:

tree-sitter-load: Cannot find shared library for language: rust

what does this error mean?

@shackra
Copy link
Collaborator

shackra commented Jun 8, 2020

Okay, I added that to my emacs config, but now when I open a rust file, I am getting the below error:

tree-sitter-load: Cannot find shared library for language: rust

what does this error mean?

it means you need to install the rust grammar I think, but that is installed when you install this package, but I could be wrong

@shackra
Copy link
Collaborator

shackra commented Jun 8, 2020

Turns out I'm having this issue too:

File mode specification error: (error Cannot find shared library for language: go)

to fix this run tree-sitter-langs-install-grammars or hook (lambda () (tree-sitter-langs-install-grammars t)) to your after-init-hook

@CSRaghunandan
Copy link
Author

Turns out I'm having this issue too:

File mode specification error: (error Cannot find shared library for language: go)

to fix this run tree-sitter-langs-install-grammars or hook (lambda () (tree-sitter-langs-install-grammars t)) to your after-init-hook

We dont need to do this. I suppose we have to run this only once to install all the grammars.

I managed to get it work with use-package and straight.el
You can find my config here: https://github.com/CSRaghunandan/.emacs.d/blob/master/setup-files/setup-tree-sitter.el

@CSRaghunandan
Copy link
Author

@ubolonton Maybe it will be helpful if you could run tree-sitter-langs-install-grammars as a part of the build process for installing emacs-tree-sitter package? I'm really not sure how emacs package management works and whether or not this is possible.

You can document this in README section so that the users don't get confused.

@ubolonton
Copy link
Collaborator

Maybe it will be helpful if you could run tree-sitter-langs-install-grammars as a part of the build process for installing emacs-tree-sitter package?

tree-sitter-langs-install-grammars should already be run when tree-sitter-langs is installed, as part of the byte-compilation process. If that's not the case, please provide a reproduction.

to fix this run tree-sitter-langs-install-grammars or hook (lambda () (tree-sitter-langs-install-grammars t)) to your after-init-hook

Please don't do this. If it was not run automatically, that's a bug to be fixed.

@CSRaghunandan
Copy link
Author

Maybe it will be helpful if you could run tree-sitter-langs-install-grammars as a part of the build process for installing emacs-tree-sitter package?

tree-sitter-langs-install-grammars should already be run when tree-sitter-langs is installed, as part of the byte-compilation process. If that's not the case, please provide a reproduction.

to fix this run tree-sitter-langs-install-grammars or hook (lambda () (tree-sitter-langs-install-grammars t)) to your after-init-hook

Please don't do this. If it was not run automatically, that's a bug to be fixed.

Pleaes find below the steps to reproduce:

  1. Copy my emacs config here: https://github.com/CSRaghunandan/.emacs.d/blob/master/setup-files/setup-tree-sitter.el

    It uses straight + use-package to configure tree-sitter for emacs

  2. Evaluate the buffer. This should download and build tree-sitter using straight

  3. Open any rust file

  4. Run tree-sitter-hl-mode

And you should run into the error: tree-sitter-load: Cannot find shared library for language: rust. Maybe tree-sitter-langs-install-grammars is not being run when building the package using straight instead of MELPA.

@shackra
Copy link
Collaborator

shackra commented Jun 9, 2020

We dont need to do this. I suppose we have to run this only once to install all the grammars.

that's just a workaround

Please don't do this. If it was not run automatically, that's a bug to be fixed.

ibid.

@shackra
Copy link
Collaborator

shackra commented Jun 9, 2020

This is my conf. for emacs-tree-sitter:

(use-package tree-sitter
  :straight (tree-sitter :host github
                         :repo "ubolonton/emacs-tree-sitter"
                         :files ("lisp/*.el" "src" "Cargo.toml" "Cargo.lock"))
  :hook ((after-init . global-tree-sitter-mode)
         ((go-mode python-mode js-mode typescript-mode) . tree-sitter-hl-mode)))

(use-package tree-sitter-langs
  :straight (tree-sitter-langs :host github
                               :repo "ubolonton/emacs-tree-sitter"
                               :files ("langs/*.el" "langs/queries"))
  :hook (after-init . (lambda () (tree-sitter-langs-install-grammars t))))

I, too, use straight.el. Without the workaround this bug will show up.

@ubolonton
Copy link
Collaborator

Normally you'd use (require 'tree-sitter-langs) explicitly, as described in the doc.

use-package uses deferred loading, so you will need to add :after tree-sitter instead:

(use-package tree-sitter-langs
  :straight (tree-sitter-langs :type git
                               :host github
                               :repo "ubolonton/emacs-tree-sitter"
                               :files ("langs/*.el" "langs/queries"))
  :after tree-sitter)

@CSRaghunandan
Copy link
Author

Normally you'd use (require 'tree-sitter-langs) explicitly, as described in the doc.

use-package uses deferred loading, so you will need to add :after tree-sitter instead:

(use-package tree-sitter-langs
  :straight (tree-sitter-langs :type git
                               :host github
                               :repo "ubolonton/emacs-tree-sitter"
                               :files ("langs/*.el" "langs/queries"))
  :after tree-sitter)

I tried this, but ran into the same error. tree-sitter-load: Cannot find shared library for language: rust

I had to run (require 'tree-sitter-langs) in :init section of use-package for it work. Is there a better way to do this? I'd like to lazy tree-sitter until I actually open a file for which tree-sitter-mode is enabled.

@ubolonton
Copy link
Collaborator

I had to run (require 'tree-sitter-langs) in :init section of use-package for it work. Is there a better way to do this? I'd like to lazy tree-sitter until I actually open a file for which tree-sitter-mode is enabled.

:init (require 'tree-sitter-langs) is not the right way to do it. It effectively means calling (require 'tree-sitter-langs) twice. :after tree-sitter should be the correct way. Please consult use-package's documentation.

  1. Evaluate the buffer. This should download and build tree-sitter using straight

Please provide better reproduction steps, which are not dependent on a specific config (the result of evaluating that depends on the specific straight.el setup; and in my case, it worked). For example, this is a minimal init.el that works: https://gist.github.com/ubolonton/9e135c0ae12600e6ab0b5d0868a4def7#file-init-el

@CSRaghunandan
Copy link
Author

I had to run (require 'tree-sitter-langs) in :init section of use-package for it work. Is there a better way to do this? I'd like to lazy tree-sitter until I actually open a file for which tree-sitter-mode is enabled.

:init (require 'tree-sitter-langs) is not the right way to do it. It effectively means calling (require 'tree-sitter-langs) twice. :after tree-sitter should be the correct way. Please consult use-package's documentation.

  1. Evaluate the buffer. This should download and build tree-sitter using straight

Please provide better reproduction steps, which are not dependent on a specific config (the result of evaluating that depends on the specific straight.el setup; and in my case, it worked). For example, this is a minimal init.el that works: https://gist.github.com/ubolonton/9e135c0ae12600e6ab0b5d0868a4def7#file-init-el

I realized why tree-sitter-langs was not being loaded. Since I used :hook declaration in my config, it tree-sitter is being lazy loaded.

I put :demand t for tree-sitter-langs use-package config and now it is working. But hmm. I'm still not sure if this is the right way of doing things.

I will give you steps to reproduce a littler today after my day job completes.

Thank you for your prompt replies

@CSRaghunandan
Copy link
Author

Okay, I was able to fix the lazy loading issue by minor refactoring, I can confirm the below code works:

(use-package tree-sitter
  :if (executable-find "tree-sitter")
  :straight (tree-sitter :type git
                         :host github
                         :repo "ubolonton/emacs-tree-sitter"
                         :files ("lisp/*.el" "src" "Cargo.toml" "Cargo.lock"))
  :hook (((rustic-mode
           python-mode
           css-mode) . tree-sitter-mode)
         ((rustic-mode
           python-mode
           css-mode) . tree-sitter-hl-mode))
  :config
  (add-to-list 'tree-sitter-major-mode-language-alist
               '(rustic-mode . rust)))

(use-package tree-sitter-langs
  :if (executable-find "tree-sitter")
  :straight (tree-sitter-langs :type git
                               :host github
                               :repo "ubolonton/emacs-tree-sitter"
                               :files ("langs/*.el" "langs/queries"))
  :after tree-sitter)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants