Skip to content

Commit 2a6c46a

Browse files
committed
fix tree-sitter-cli dynamic library directory
1 parent c3fe96a commit 2a6c46a

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

lisp/tree-sitter-cli.el

+35-6
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,50 @@
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+
(defun tree-sitter-version ()
23+
"Return tree-sitter CLI version."
24+
(if tree-sitter-binary
25+
(nth 1 (split-string
26+
(shell-command-to-string
27+
(concat tree-sitter-binary " -V"))))
28+
"0"))
29+
30+
(defun tree-sitter-cli-config-directory ()
31+
"Return tree-sitter CLI's config directory, including the ending separator.
32+
This is the directory where the CLI stores the configuration file."
2333
(file-name-as-directory
2434
(expand-file-name
2535
;; https://github.com/tree-sitter/tree-sitter/blob/1bad6dc/cli/src/config.rs#L20
2636
(if-let ((dir (getenv "TREE_SITTER_DIR")))
2737
dir
2838
"~/.tree-sitter"))))
2939

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

3564
(provide 'tree-sitter-cli)
3665
;;; tree-sitter-cli.el ends here

lisp/tree-sitter-load.el

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