[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master c9624c21117 05/10: Add treesit-admin--last-compatible-grammar-for
From: |
Yuan Fu |
Subject: |
master c9624c21117 05/10: Add treesit-admin--last-compatible-grammar-for-modes |
Date: |
Mon, 30 Dec 2024 03:24:10 -0500 (EST) |
branch: master
commit c9624c21117f7bece4d5a8271888155de5d086a2
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Add treesit-admin--last-compatible-grammar-for-modes
This function computes the latest compatible grammar version for
each major mode.
* admin/treesit-admin.el (treesit-admin-file-name): Move.
(treesit-admin--compat-template-file-name): New variable.
(treesit-admin--mode-languages): New function.
(treesit-admin--find-latest-compatible-revision): Return a plist
instead.
(treesit-admin--last-compatible-grammar-for-modes): New function.
---
admin/treesit-admin.el | 69 +++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 62 insertions(+), 7 deletions(-)
diff --git a/admin/treesit-admin.el b/admin/treesit-admin.el
index 253307775e9..0787f6c9742 100644
--- a/admin/treesit-admin.el
+++ b/admin/treesit-admin.el
@@ -82,9 +82,6 @@
The source information are in the format of
`treesit-language-source-alist'. This is for development only.")
-(defvar treesit-admin-file-name (or load-file-name (buffer-file-name))
- "Filename of the source file treesit-admin.el.")
-
(defun treesit-admin--verify-major-mode-queries (modes langs source-alist
grammar-dir)
"Verify font-lock queries in MODES.
@@ -194,6 +191,17 @@ queries that has problems with latest grammar."
(nth 2 entry)))))
(special-mode))))
+;;; Compatibility report
+
+(defvar treesit-admin-file-name (or load-file-name (buffer-file-name))
+ "Filename of the source file treesit-admin.el.")
+
+(defvar treesit-admin--compat-template-file-name
+ (expand-file-name "compat-template.html"
+ (file-name-directory
+ (or load-file-name (buffer-file-name))))
+ "Filename of the HTML template for the compatibility report.")
+
(defun treesit-admin-verify-major-mode-queries ()
"Varify font-lock queries in builtin major modes.
@@ -230,12 +238,30 @@ Return non-nil if all queries are valid, nil otherwise."
(setq all-queries-valid nil))))
all-queries-valid))
+(defun treesit-admin--mode-languages (mode)
+ "Return languages used by MODE in a list."
+ (let ((settings
+ (with-temp-buffer
+ (ignore-errors
+ (funcall mode)
+ (font-lock-mode -1)
+ treesit-font-lock-settings)))
+ (all-queries-valid t))
+ (cl-remove-duplicates
+ (mapcar #'treesit-query-language
+ (mapcar #'treesit-font-lock-setting-query
+ settings)))))
+
(defun treesit-admin--find-latest-compatible-revision
(mode language source-alist grammar-dir)
"Find the latest revision for LANGUAGE that's compatible with MODE.
MODE, LANGUAGE, SOURCE-ALIST, GRAMMAR-DIR are the same as in
-`treesit-admin--verify-major-mode-queries'."
+`treesit-admin--verify-major-mode-queries'.
+
+Return a plist (:version VERSION :head-version HEAD-VERSION).
+HEAD-VERSION is the version of the HEAD, VERSION is the latest
+compatible version."
(let ((treesit-extra-load-path (list grammar-dir))
(treesit--install-language-grammar-full-clone t)
(treesit--install-language-grammar-blobless t)
@@ -243,14 +269,14 @@ MODE, LANGUAGE, SOURCE-ALIST, GRAMMAR-DIR are the same as
in
(workdir (make-temp-file "treesit-validate-workdir" t))
(emacs-executable
(expand-file-name invocation-name invocation-directory))
- version exit-code)
+ head-version version exit-code)
(pcase-let ((`(,url ,revision ,source-dir ,cc ,c++ ,commit)
recipe))
(with-temp-buffer
(treesit--git-clone-repo url revision workdir)
(when commit
(treesit--git-checkout-branch workdir commit))
-
+ (setq head-version (treesit--language-git-revision workdir))
(treesit--build-grammar
workdir grammar-dir language source-dir cc c++)
(while (not (eq exit-code 0))
@@ -272,7 +298,36 @@ MODE, LANGUAGE, SOURCE-ALIST, GRAMMAR-DIR are the same as
in
',mode ',language)
(kill-emacs 0)
(kill-emacs -1)))))))))
- version))
+ (list :version version :head-version head-version)))
+
+(defun treesit-admin--last-compatible-grammar-for-modes
+ (modes source-alist grammar-dir)
+ "Generate an HTML page listing latest compatible grammar versions.
+
+MODES, SOURCE-ALIST, GRAMMAR-DIR are the same as
+`treesit-admin--verify-major-mode-queries'.
+
+Return an alist of an alist of a plist:
+
+ ((MODE . ((LANG . (:version VERSION :head-VERSION HEAD-VERSION)) ...)) ...)
+
+VERSION and HEAD-VERSION in the plist are the same as in
+`treesit-admin--find-latest-compatible-revision'."
+ (mapcar
+ (lambda (mode)
+ (cons mode
+ (mapcar
+ (lambda (language)
+ (cons language
+ (treesit-admin--find-latest-compatible-revision
+ mode language source-alist grammar-dir)))
+ (treesit-admin--mode-languages mode))))
+ modes))
+
+(defun treesit-admin-generate-compatibility-report ()
+ "Generate a language compatibility report."
+ (interactive)
+ )
(provide 'treesit-admin)
- master updated (dc653bf0636 -> ec3f9434c7d), Yuan Fu, 2024/12/30
- master 9e1e9fdff44 03/10: Refactor treesit-admin--verify-major-mode-queries, Yuan Fu, 2024/12/30
- master c9624c21117 05/10: Add treesit-admin--last-compatible-grammar-for-modes,
Yuan Fu <=
- master d9cfe1fe92f 07/10: Add treesit-admin-generate-compatibility-report, Yuan Fu, 2024/12/30
- master a22730f4d78 01/10: Support COMMIT in treesit-language-source-alist, Yuan Fu, 2024/12/30
- master d5ad51f25fb 04/10: Add treesit-admin--find-latest-compatible-revision, Yuan Fu, 2024/12/30
- master e2f79171529 02/10: Refactor treesit--install-language-grammar-1, Yuan Fu, 2024/12/30
- master 0b1986ba524 08/10: Generate compatibility report for multiple Emacs versions, Yuan Fu, 2024/12/30
- master 732a1108b0b 09/10: Add verified grammar version comment for tree-sitter modes, Yuan Fu, 2024/12/30
- master ec3f9434c7d 10/10: Make typescript-ts-mode work with latest grammar, Yuan Fu, 2024/12/30
- master 5ec170985f4 06/10: ; Move treesit-admin into tree-sitter directory, Yuan Fu, 2024/12/30