diff --git a/langs b/langs index 599570cd..0b15f1e4 160000 --- a/langs +++ b/langs @@ -1 +1 @@ -Subproject commit 599570cd2a6d1b43a109634896b5c52121e155e3 +Subproject commit 0b15f1e45e8e4e0128a518feb3af2b42f95ac37e diff --git a/lisp/tree-sitter-cli.el b/lisp/tree-sitter-cli.el index e03e6456..82dc2935 100644 --- a/lisp/tree-sitter-cli.el +++ b/lisp/tree-sitter-cli.el @@ -16,10 +16,20 @@ (eval-when-compile (require 'subr-x)) -(defun tree-sitter-cli-directory () - "Return tree-sitter CLI's directory, including the ending separator. -This is the directory where the CLI tool keeps compiled lang definitions, among -other data." +(defvar tree-sitter-binary (executable-find "tree-sitter") + "Tree-sitter binary location.") + +(defun tree-sitter-version () + "Return tree-sitter CLI version." + (if tree-sitter-binary + (nth 1 (split-string + (shell-command-to-string + (concat tree-sitter-binary " -V")))) + "0")) + +(defun tree-sitter-cli-config-directory () + "Return tree-sitter CLI's config directory, including the ending separator. +This is the directory where the CLI stores the configuration file." (file-name-as-directory (expand-file-name ;; https://github.com/tree-sitter/tree-sitter/blob/1bad6dc/cli/src/config.rs#L20 @@ -27,10 +37,29 @@ other data." dir "~/.tree-sitter")))) -(defun tree-sitter-cli-bin-directory () +(defun tree-sitter-cli-cache-directory () + "Return tree-sitter CLI's cache directory, including the ending separator. +This is the directory where the CLI tool keeps compiled lang definitions." + (file-name-as-directory + ;; https://github.com/tree-sitter/tree-sitter/blob/master/cli/loader/src/lib.rs#L110-L115 + (expand-file-name "tree-sitter" + (cond + ((eq system-type 'gnu/linux) + (let ((env (getenv "XDG_CACHE_HOME"))) + (if (or (null env) (not (file-name-absolute-p env))) + (expand-file-name "~/.cache") + env))) + ((eq system-type 'darwin) + "~/Library/Caches") + ((memq system-type '(cygwin windows-nt ms-dos)) + "~/AppData/Local"))))) + +(defun tree-sitter-cli-lib-directory () "Return the directory used by tree-sitter CLI to store compiled grammars." (file-name-as-directory - (concat (tree-sitter-cli-directory) "bin"))) + (if (version<= "0.20" (tree-sitter-version)) + (expand-file-name "lib" (tree-sitter-cli-cache-directory)) + (expand-file-name "bin" (tree-sitter-cli-config-directory))))) (provide 'tree-sitter-cli) ;;; tree-sitter-cli.el ends here diff --git a/lisp/tree-sitter-load.el b/lisp/tree-sitter-load.el index 95114506..d1304ee7 100644 --- a/lisp/tree-sitter-load.el +++ b/lisp/tree-sitter-load.el @@ -25,7 +25,7 @@ "An alist of mappings from language name symbols to language objects. See `tree-sitter-require'.") -(defvar tree-sitter-load-path (list (tree-sitter-cli-bin-directory)) +(defvar tree-sitter-load-path (list (tree-sitter-cli-lib-directory)) "List of directories to search for shared libraries that define languages.") (defvar tree-sitter-load-suffixes