From ed8c55f2aad49325b1fcc9239687bd31a9254c2f Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Sat, 28 Dec 2024 14:54:17 -0800 Subject: [PATCH] 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. (cherry picked from commit 9e1e9fdff44f047489d45ba4a73776cb0298574f) --- admin/treesit-admin.el | 13 ++++++++----- lisp/treesit.el | 15 +++++---------- 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 @@ 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")) diff --git a/lisp/treesit.el b/lisp/treesit.el index f6749a16525..110d5d84067 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -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. -- 2.39.5