GithubHelp home page GithubHelp logo

Comments (15)

CSRaghunandan avatar CSRaghunandan commented on April 20, 2024 3

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)

from elisp-tree-sitter.

shackra avatar shackra commented on April 20, 2024 2

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

from elisp-tree-sitter.

ubolonton avatar ubolonton commented on April 20, 2024 1

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)

from elisp-tree-sitter.

ubolonton avatar ubolonton commented on April 20, 2024

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

from elisp-tree-sitter.

CSRaghunandan avatar CSRaghunandan commented on April 20, 2024

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?

from elisp-tree-sitter.

shackra avatar shackra commented on April 20, 2024

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

from elisp-tree-sitter.

CSRaghunandan avatar CSRaghunandan commented on April 20, 2024

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

from elisp-tree-sitter.

CSRaghunandan avatar CSRaghunandan commented on April 20, 2024

@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.

from elisp-tree-sitter.

ubolonton avatar ubolonton commented on April 20, 2024

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.

from elisp-tree-sitter.

CSRaghunandan avatar CSRaghunandan commented on April 20, 2024

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.

from elisp-tree-sitter.

shackra avatar shackra commented on April 20, 2024

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.

from elisp-tree-sitter.

shackra avatar shackra commented on April 20, 2024

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.

from elisp-tree-sitter.

CSRaghunandan avatar CSRaghunandan commented on April 20, 2024

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.

from elisp-tree-sitter.

ubolonton avatar ubolonton commented on April 20, 2024

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

from elisp-tree-sitter.

CSRaghunandan avatar CSRaghunandan commented on April 20, 2024

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

from elisp-tree-sitter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.