Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b298d55

Browse files
committedFeb 27, 2022
fix tree-sitter-cli dynamic library directory
1 parent 3cfab8a commit b298d55

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed
 

‎lisp/tree-sitter-cli.el

+22-6
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,37 @@
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+
(defun tree-sitter-cli-config-directory ()
20+
"Return tree-sitter CLI's config directory, including the ending separator.
21+
This is the directory where the CLI stores the configuration file."
2322
(file-name-as-directory
2423
(expand-file-name
2524
;; https://github.com/tree-sitter/tree-sitter/blob/1bad6dc/cli/src/config.rs#L20
2625
(if-let ((dir (getenv "TREE_SITTER_DIR")))
2726
dir
2827
"~/.tree-sitter"))))
2928

30-
(defun tree-sitter-cli-bin-directory ()
29+
(defun tree-sitter-cli-cache-directory ()
30+
"Return tree-sitter CLI's cache directory, including the ending separator.
31+
This is the directory where the CLI tool keeps compiled lang definitions."
32+
(file-name-as-directory
33+
;; https://github.com/tree-sitter/tree-sitter/blob/master/cli/loader/src/lib.rs#L110-L115
34+
(expand-file-name "tree-sitter"
35+
(cond
36+
((eq system-type 'gnu/linux)
37+
(let ((env (getenv "XDG_CACHE_HOME")))
38+
(if (or (null env) (not (file-name-absolute-p env)))
39+
(expand-file-name "~/.cache")
40+
env)))
41+
((eq system-type 'darwin)
42+
"~/Library/Caches")
43+
((memq system-type '(cygwin windows-nt ms-dos))
44+
"~/AppData/Local")))))
45+
46+
(defun tree-sitter-cli-lib-directory ()
3147
"Return the directory used by tree-sitter CLI to store compiled grammars."
3248
(file-name-as-directory
33-
(concat (tree-sitter-cli-directory) "bin")))
49+
(expand-file-name "lib" (tree-sitter-cli-cache-directory))))
3450

3551
(provide 'tree-sitter-cli)
3652
;;; 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)
Please sign in to comment.