emacs-tree-sitter / elisp-tree-sitter

Emacs Lisp bindings for tree-sitter
https://emacs-tree-sitter.github.io
MIT License
816 stars 73 forks source link

fix tree-sitter-cli dynamic library directory #212

Open tpeacock19 opened 2 years ago

tpeacock19 commented 2 years ago

This is to fix the incorrect path for where the tree-sitter cli stores dynamically-loadale libraries.

Rust Dirs

/// Returns the path to the user's cache directory.
///
/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`.
///
/// |Platform | Value                               | Example                      |
/// | ------- | ----------------------------------- | ---------------------------- |
/// | Linux   | `$XDG_CACHE_HOME` or `$HOME`/.cache | /home/alice/.cache           |
/// | macOS   | `$HOME`/Library/Caches              | /Users/Alice/Library/Caches  |
/// | Windows | `{FOLDERID_LocalAppData}`           | C:\Users\Alice\AppData\Local |
pub fn cache_dir() -> Option<PathBuf> {
    sys::cache_dir()
}

Tree-Sitter Cli Loader

Function load_language_from_sources()


  https://github.com/tree-sitter/tree-sitter/blob/master/cli/loader/src/lib.rs#L391-L399
tpeacock19 commented 2 years ago

I've added a check for the tree-sitter version that should cover pre and post 0.19 versions. This should resolve https://github.com/emacs-tree-sitter/tree-sitter-langs/issues/80

ethan-leba commented 2 years ago

I’ve added a check for the tree-sitter version that should cover pre and post 0.19 versions. This should resolve emacs-tree-sitter/tree-sitter-langs#80

I don’t think this would resolve that issue, tree-sitter-langs-build doesn’t reference these TS functions for finding the dylibs (it’s hardcoded to look in the repo’s bin/ directory)

tpeacock19 commented 2 years ago

I don’t think this would resolve that issue, tree-sitter-langs-build doesn’t reference these TS functions for finding the dylibs (it’s hardcoded to look in the repo’s bin/ directory)

I was able to compile the languages using that script and they do, in fact, show up in my standard tree-sitter build directory within $XDG_CACHE_HOME. If we are also make these changes to tree-sitter-load-path then it will load them from there.

The main issue i see with this would be that tree-sitter-langs seems to run tree-sitter generate and tree-sitter test as well as running custom build commands. I'm not sure if this is entirely necessary because tree-sitter builds libraries when necessary when running tree-sitter test. I think there should be an option like the ability to build tsc locally that would check if the dynamic libraries are present in tree-sitter-load-path.

ethan-leba commented 2 years ago

I don’t think this would resolve that issue, tree-sitter-langs-build doesn’t reference these TS functions for finding the dylibs (it’s hardcoded to look in the repo’s bin/ directory)

I was able to compile the languages using that script and they do, in fact, show up in my standard tree-sitter build directory within $XDG_CACHE_HOME. If we are also make these changes to tree-sitter-load-path then it will load them from there.

Ah, you’re right – theres this bit of logic I thought might be problematic but it looks like the loading logic looks for either name.

leotrs commented 1 year ago

Bump :)