Skip to content

Commit 28f4347

Browse files
committed
fix tree-sitter-cli dynamic library directory
1 parent 3cfab8a commit 28f4347

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

lisp/tree-sitter-cli.el

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,49 @@
1616
(eval-when-compile
1717
(require 'subr-x))
1818

19-
(defun tree-sitter-cli-directory ()
20-
"Return tree-sitter CLI's directory, including the ending separator.
21-
This is the directory where the CLI tool keeps compiled lang definitions, among
22-
other data."
19+
(defvar tree-sitter-binary (executable-find "tree-sitter")
20+
"Tree-sitter binary location.")
21+
22+
(defvar tree-sitter-version (if tree-sitter-binary
23+
(nth 1 (split-string
24+
(shell-command-to-string
25+
(concat tree-sitter-binary " -V"))))
26+
(error "tree-sitter binary not installed"))
27+
"Return tree-sitter CLI version.")
28+
29+
(defun tree-sitter-cli-config-directory ()
30+
"Return tree-sitter CLI's config directory, including the ending separator.
31+
This is the directory where the CLI stores the configuration file."
2332
(file-name-as-directory
2433
(expand-file-name
2534
;; https://github.com/tree-sitter/tree-sitter/blob/1bad6dc/cli/src/config.rs#L20
2635
(if-let ((dir (getenv "TREE_SITTER_DIR")))
2736
dir
2837
"~/.tree-sitter"))))
2938

30-
(defun tree-sitter-cli-bin-directory ()
39+
(defun tree-sitter-cli-cache-directory ()
40+
"Return tree-sitter CLI's cache directory, including the ending separator.
41+
This is the directory where the CLI tool keeps compiled lang definitions."
42+
(file-name-as-directory
43+
;; https://github.com/tree-sitter/tree-sitter/blob/master/cli/loader/src/lib.rs#L110-L115
44+
(expand-file-name "tree-sitter"
45+
(cond
46+
((eq system-type 'gnu/linux)
47+
(let ((env (getenv "XDG_CACHE_HOME")))
48+
(if (or (null env) (not (file-name-absolute-p env)))
49+
(expand-file-name "~/.cache")
50+
env)))
51+
((eq system-type 'darwin)
52+
"~/Library/Caches")
53+
((memq system-type '(cygwin windows-nt ms-dos))
54+
"~/AppData/Local")))))
55+
56+
(defun tree-sitter-cli-lib-directory ()
3157
"Return the directory used by tree-sitter CLI to store compiled grammars."
3258
(file-name-as-directory
33-
(concat (tree-sitter-cli-directory) "bin")))
59+
(if (version<= "0.20" tree-sitter-version)
60+
(expand-file-name "lib" (tree-sitter-cli-cache-directory))
61+
(expand-file-name "bin" (tree-sitter-cli-config-directory)))))
3462

3563
(provide 'tree-sitter-cli)
3664
;;; tree-sitter-cli.el ends here

lisp/tree-sitter-load.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"An alist of mappings from language name symbols to language objects.
2626
See `tree-sitter-require'.")
2727

28-
(defvar tree-sitter-load-path (list (tree-sitter-cli-bin-directory))
28+
(defvar tree-sitter-load-path (list (tree-sitter-cli-lib-directory))
2929
"List of directories to search for shared libraries that define languages.")
3030

3131
(defvar tree-sitter-load-suffixes

0 commit comments

Comments
 (0)