aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Fu2024-12-28 14:54:17 -0800
committerYuan Fu2024-12-30 00:20:54 -0800
commit9e1e9fdff44f047489d45ba4a73776cb0298574f (patch)
treefe61fbbdc3933de1c1e8f242984cfe37610fbfd7
parente2f791715299d97f401a38c75fa11bb51fdb8292 (diff)
downloademacs-9e1e9fdff44f047489d45ba4a73776cb0298574f.tar.gz
emacs-9e1e9fdff44f047489d45ba4a73776cb0298574f.zip
Refactor treesit-admin--verify-major-mode-queries
Make treesit-admin--verify-major-mode-queries use treesit--install-language-grammar-1, rathre than the interactive command treesit-install-language-grammar. * admin/treesit-admin.el: (treesit-admin--verify-major-mode-queries): Add parameter SOURCE-ALIST. Use treesit--install-language-grammar-1. (treesit-admin-verify-major-mode-queries): Pass treesit-admin--builtin-language-sources to treesit-admin--verify-major-mode-queries. * lisp/treesit.el (treesit-install-language-grammar): Don't return revision of the git repo.
-rw-r--r--admin/treesit-admin.el13
-rw-r--r--lisp/treesit.el15
2 files changed, 13 insertions, 15 deletions
diff --git a/admin/treesit-admin.el b/admin/treesit-admin.el
index 440056aff21..36b8cb620b5 100644
--- a/admin/treesit-admin.el
+++ b/admin/treesit-admin.el
@@ -82,19 +82,19 @@
82The source information are in the format of 82The source information are in the format of
83`treesit-language-source-alist'. This is for development only.") 83`treesit-language-source-alist'. This is for development only.")
84 84
85(defun treesit-admin--verify-major-mode-queries (modes langs grammar-dir) 85(defun treesit-admin--verify-major-mode-queries (modes langs source-alist grammar-dir)
86 "Verify font-lock queries in MODES. 86 "Verify font-lock queries in MODES.
87 87
88LANGS is a list of languages, it should cover all the languages used by 88LANGS is a list of languages, it should cover all the languages used by
89MODES. GRAMMAR-DIR is a temporary direction in which grammars are 89major modes in MODES. SOURCE-ALIST should have the same shape as
90installed. 90`treesit-language-source-alist'. GRAMMAR-DIR is a temporary direction
91in which grammars are installed.
91 92
92If the font-lock queries work fine with the latest grammar, insert some 93If the font-lock queries work fine with the latest grammar, insert some
93comments in the source file saying that the modes are known to work with 94comments in the source file saying that the modes are known to work with
94that version of grammar. At the end of the process, show a list of 95that version of grammar. At the end of the process, show a list of
95queries that has problems with latest grammar." 96queries that has problems with latest grammar."
96 (let ((treesit-extra-load-path (list grammar-dir)) 97 (let ((treesit-extra-load-path (list grammar-dir))
97 (treesit-language-source-alist treesit-admin--builtin-language-sources)
98 (treesit--install-language-grammar-full-clone t) 98 (treesit--install-language-grammar-full-clone t)
99 (treesit--install-language-grammar-blobless t) 99 (treesit--install-language-grammar-blobless t)
100 (version-alist nil) 100 (version-alist nil)
@@ -103,7 +103,9 @@ queries that has problems with latest grammar."
103 (mode-language-alist nil) 103 (mode-language-alist nil)
104 (file-modes-alist nil)) 104 (file-modes-alist nil))
105 (dolist (lang langs) 105 (dolist (lang langs)
106 (let ((ver (treesit-install-language-grammar lang grammar-dir))) 106 (let* ((recipe (assoc lang source-alist))
107 (ver (apply #'treesit--install-language-grammar-1
108 (cons grammar-dir recipe))))
107 (if ver 109 (if ver
108 (push (cons lang ver) version-alist) 110 (push (cons lang ver) version-alist)
109 (error "Cannot get version for %s" lang)))) 111 (error "Cannot get version for %s" lang))))
@@ -200,6 +202,7 @@ queries that has problems with latest grammar."
200 (treesit-admin--verify-major-mode-queries 202 (treesit-admin--verify-major-mode-queries
201 '(cmake-ts-mode dockerfile-ts-mode go-ts-mode ruby-ts-mode) 203 '(cmake-ts-mode dockerfile-ts-mode go-ts-mode ruby-ts-mode)
202 '(cmake dockerfile go ruby) 204 '(cmake dockerfile go ruby)
205 treesit-admin--builtin-language-sources
203 "/tmp/tree-sitter-grammars")) 206 "/tmp/tree-sitter-grammars"))
204 207
205 208
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 73e7e5446d4..5e153bc6f78 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -4171,10 +4171,7 @@ executable programs, such as the C/C++ compiler and linker.
4171Interactively, prompt for the directory in which to install the 4171Interactively, prompt for the directory in which to install the
4172compiled grammar files. Non-interactively, use OUT-DIR; if it's 4172compiled grammar files. Non-interactively, use OUT-DIR; if it's
4173nil, the grammar is installed to the standard location, the 4173nil, the grammar is installed to the standard location, the
4174\"tree-sitter\" directory under `user-emacs-directory'. 4174\"tree-sitter\" directory under `user-emacs-directory'."
4175
4176Return the git revision of the installed grammar, but it only works when
4177`treesit--install-language-grammar-full-clone' is t."
4178 (interactive (list (intern 4175 (interactive (list (intern
4179 (completing-read 4176 (completing-read
4180 "Language: " 4177 "Language: "
@@ -4199,13 +4196,12 @@ Return the git revision of the installed grammar, but it only works when
4199 default-out-dir) 4196 default-out-dir)
4200 ;; When called non-interactively, OUT-DIR should 4197 ;; When called non-interactively, OUT-DIR should
4201 ;; default to DEFAULT-OUT-DIR. 4198 ;; default to DEFAULT-OUT-DIR.
4202 (or out-dir default-out-dir))) 4199 (or out-dir default-out-dir))))
4203 version)
4204 (when recipe 4200 (when recipe
4205 (condition-case err 4201 (condition-case err
4206 (progn 4202 (progn
4207 (setq version (apply #'treesit--install-language-grammar-1 4203 (apply #'treesit--install-language-grammar-1
4208 (cons out-dir recipe))) 4204 (cons out-dir recipe))
4209 4205
4210 ;; Check that the installed language grammar is loadable. 4206 ;; Check that the installed language grammar is loadable.
4211 (pcase-let ((`(,available . ,err) 4207 (pcase-let ((`(,available . ,err)
@@ -4226,8 +4222,7 @@ Return the git revision of the installed grammar, but it only works when
4226 (display-warning 4222 (display-warning
4227 'treesit 4223 'treesit
4228 (format "Error encountered when installing language grammar: %s" 4224 (format "Error encountered when installing language grammar: %s"
4229 err))))) 4225 err)))))))
4230 version))
4231 4226
4232(defun treesit--language-git-revision (repo-dir) 4227(defun treesit--language-git-revision (repo-dir)
4233 "Return the Git revision of the repo in REPO-DIR. 4228 "Return the Git revision of the repo in REPO-DIR.