]> git.eshelyaron.com Git - emacs.git/commitdiff
Refactor treesit-admin--verify-major-mode-queries
authorYuan Fu <casouri@gmail.com>
Sat, 28 Dec 2024 22:54:17 +0000 (14:54 -0800)
committerEshel Yaron <me@eshelyaron.com>
Sat, 4 Jan 2025 20:25:38 +0000 (21:25 +0100)
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.

(cherry picked from commit 9e1e9fdff44f047489d45ba4a73776cb0298574f)

admin/treesit-admin.el
lisp/treesit.el

index 440056aff212bf29486060d21ca9d8c702bf61cd..36b8cb620b588117e348bfc5fa300eb4b1e833b6 100644 (file)
 The source information are in the format of
 `treesit-language-source-alist'.  This is for development only.")
 
-(defun treesit-admin--verify-major-mode-queries (modes langs grammar-dir)
+(defun treesit-admin--verify-major-mode-queries (modes langs source-alist grammar-dir)
   "Verify font-lock queries in MODES.
 
 LANGS is a list of languages, it should cover all the languages used by
-MODES.  GRAMMAR-DIR is a temporary direction in which grammars are
-installed.
+major modes in MODES.  SOURCE-ALIST should have the same shape as
+`treesit-language-source-alist'.  GRAMMAR-DIR is a temporary direction
+in which grammars are installed.
 
 If the font-lock queries work fine with the latest grammar, insert some
 comments in the source file saying that the modes are known to work with
 that version of grammar.  At the end of the process, show a list of
 queries that has problems with latest grammar."
   (let ((treesit-extra-load-path (list grammar-dir))
-        (treesit-language-source-alist treesit-admin--builtin-language-sources)
         (treesit--install-language-grammar-full-clone t)
         (treesit--install-language-grammar-blobless t)
         (version-alist nil)
@@ -103,7 +103,9 @@ queries that has problems with latest grammar."
         (mode-language-alist nil)
         (file-modes-alist nil))
     (dolist (lang langs)
-      (let ((ver (treesit-install-language-grammar lang grammar-dir)))
+      (let* ((recipe (assoc lang source-alist))
+             (ver (apply #'treesit--install-language-grammar-1
+                         (cons grammar-dir recipe))))
         (if ver
             (push (cons lang ver) version-alist)
           (error "Cannot get version for %s" lang))))
@@ -200,6 +202,7 @@ queries that has problems with latest grammar."
   (treesit-admin--verify-major-mode-queries
    '(cmake-ts-mode dockerfile-ts-mode go-ts-mode ruby-ts-mode)
    '(cmake dockerfile go ruby)
+   treesit-admin--builtin-language-sources
    "/tmp/tree-sitter-grammars"))
 
 
index f6749a16525f199270628d6eef57ba665504fcf8..110d5d840678d7ba3690edae8e50674d14e76d09 100644 (file)
@@ -4163,10 +4163,7 @@ executable programs, such as the C/C++ compiler and linker.
 Interactively, prompt for the directory in which to install the
 compiled grammar files.  Non-interactively, use OUT-DIR; if it's
 nil, the grammar is installed to the standard location, the
-\"tree-sitter\" directory under `user-emacs-directory'.
-
-Return the git revision of the installed grammar, but it only works when
-`treesit--install-language-grammar-full-clone' is t."
+\"tree-sitter\" directory under `user-emacs-directory'."
   (interactive (list (intern
                       (completing-read
                        "Language: "
@@ -4191,13 +4188,12 @@ Return the git revision of the installed grammar, but it only works when
                default-out-dir)
             ;; When called non-interactively, OUT-DIR should
             ;; default to DEFAULT-OUT-DIR.
-            (or out-dir default-out-dir)))
-         version)
+            (or out-dir default-out-dir))))
     (when recipe
       (condition-case err
           (progn
-            (setq version (apply #'treesit--install-language-grammar-1
-                                 (cons out-dir recipe)))
+            (apply #'treesit--install-language-grammar-1
+                   (cons out-dir recipe))
 
             ;; Check that the installed language grammar is loadable.
             (pcase-let ((`(,available . ,err)
@@ -4218,8 +4214,7 @@ Return the git revision of the installed grammar, but it only works when
          (display-warning
           'treesit
           (format "Error encountered when installing language grammar: %s"
-                  err)))))
-    version))
+                  err)))))))
 
 (defun treesit--language-git-revision (repo-dir)
   "Return the Git revision of the repo in REPO-DIR.