aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2025-04-22 21:01:28 +0300
committerJuri Linkov2025-04-22 21:01:28 +0300
commitadd8bf000aee39e40feacff7e0df7248fa4ef9c5 (patch)
tree5e5feff0a8eb34eb06a02b4902dfbb852071f001
parent573a2c09b991df5442ab3b9984c2885011153333 (diff)
downloademacs-add8bf000aee39e40feacff7e0df7248fa4ef9c5.tar.gz
emacs-add8bf000aee39e40feacff7e0df7248fa4ef9c5.zip
Replace some 'treesit-query-compile' with 'treesit-query-valid-p'.
* admin/tree-sitter/treesit-admin.el (treesit-admin--verify-major-mode-queries) (treesit-admin--validate-mode-lang): * lisp/progmodes/csharp-mode.el (csharp-ts-mode--test-this-expression) (csharp-ts-mode--test-interpolated-string-text) (csharp-ts-mode--test-string-content) (csharp-ts-mode--test-type-constraint) (csharp-ts-mode--test-type-of-expression) (csharp-ts-mode--test-typeof-expression) (csharp-ts-mode--test-name-equals) (csharp-ts-mode--test-if-directive) (csharp-ts-mode--test-method-declaration-type-field): * lisp/progmodes/php-ts-mode.el (php-ts-mode--test-namespace-name-as-prefix-p) (php-ts-mode--test-namespace-aliasing-clause-p) (php-ts-mode--test-namespace-use-group-clause-p) (php-ts-mode--test-visibility-modifier-operation-clause-p) (php-ts-mode--test-property-hook-clause-p): * lisp/progmodes/typescript-ts-mode.el (tsx-ts-mode--font-lock-compatibility-bb1f97b): Use the newer equivalent 'treesit-query-valid-p' instead of 'treesit-query-compile' with 'ignore-errors'.
-rw-r--r--admin/tree-sitter/treesit-admin.el8
-rw-r--r--lisp/progmodes/c-ts-mode.el4
-rw-r--r--lisp/progmodes/csharp-mode.el36
-rw-r--r--lisp/progmodes/php-ts-mode.el15
-rw-r--r--lisp/progmodes/typescript-ts-mode.el10
5 files changed, 21 insertions, 52 deletions
diff --git a/admin/tree-sitter/treesit-admin.el b/admin/tree-sitter/treesit-admin.el
index ef6d256a538..f41c4592039 100644
--- a/admin/tree-sitter/treesit-admin.el
+++ b/admin/tree-sitter/treesit-admin.el
@@ -156,9 +156,7 @@ queries that has problems with latest grammar."
156 (unless (memq language (alist-get mode mode-language-alist)) 156 (unless (memq language (alist-get mode mode-language-alist))
157 (push language (alist-get mode mode-language-alist))) 157 (push language (alist-get mode mode-language-alist)))
158 ;; Validate query. 158 ;; Validate query.
159 (when (not (ignore-errors 159 (unless (treesit-query-valid-p language query)
160 (treesit-query-compile language query t)
161 t))
162 (push (list mode language feature) invalid-feature-list) 160 (push (list mode language feature) invalid-feature-list)
163 (setq all-queries-valid nil)))) 161 (setq all-queries-valid nil))))
164 (when all-queries-valid 162 (when all-queries-valid
@@ -261,9 +259,7 @@ Return non-nil if all queries are valid, nil otherwise."
261 (language (treesit-query-language query))) 259 (language (treesit-query-language query)))
262 ;; Validate query. 260 ;; Validate query.
263 (when (and (eq lang language) 261 (when (and (eq lang language)
264 (not (ignore-errors 262 (not (treesit-query-valid-p language query)))
265 (treesit-query-compile language query t)
266 t)))
267 (setq all-queries-valid nil)))) 263 (setq all-queries-valid nil))))
268 all-queries-valid)) 264 all-queries-valid))
269 265
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 8d4b6f587d5..070984f4aac 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -674,9 +674,7 @@ MODE should be either `c' or `cpp'."
674 (mapcan 674 (mapcan
675 (lambda (entry) 675 (lambda (entry)
676 (let ((keywords (cdr entry))) 676 (let ((keywords (cdr entry)))
677 (if (ignore-errors 677 (if (treesit-query-valid-p 'c `([,@keywords] @cap))
678 (treesit-query-compile 'c `([,@keywords] @cap) t)
679 t)
680 (copy-sequence keywords) 678 (copy-sequence keywords)
681 nil))) 679 nil)))
682 c-ts-mode--optional-c-keywords) 680 c-ts-mode--optional-c-keywords)
diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
index fe2fbb0d1e5..a421d616d9b 100644
--- a/lisp/progmodes/csharp-mode.el
+++ b/lisp/progmodes/csharp-mode.el
@@ -733,57 +733,39 @@ compilation and evaluation time conflicts."
733 733
734(defun csharp-ts-mode--test-this-expression () 734(defun csharp-ts-mode--test-this-expression ()
735 "Return non-nil if (this_expression) is named in csharp grammar." 735 "Return non-nil if (this_expression) is named in csharp grammar."
736 (ignore-errors 736 (treesit-query-valid-p 'c-sharp "(this_expression)"))
737 (treesit-query-compile 'c-sharp "(this_expression)" t)
738 t))
739 737
740(defun csharp-ts-mode--test-interpolated-string-text () 738(defun csharp-ts-mode--test-interpolated-string-text ()
741 "Return non-nil if (interpolated_string_text) is in the grammar." 739 "Return non-nil if (interpolated_string_text) is in the grammar."
742 (ignore-errors 740 (treesit-query-valid-p 'c-sharp "(interpolated_string_text)"))
743 (treesit-query-compile 'c-sharp "(interpolated_string_text)" t)
744 t))
745 741
746(defun csharp-ts-mode--test-string-content () 742(defun csharp-ts-mode--test-string-content ()
747 "Return non-nil if (interpolated_string_text) is in the grammar." 743 "Return non-nil if (interpolated_string_text) is in the grammar."
748 (ignore-errors 744 (treesit-query-valid-p 'c-sharp "(string_content)"))
749 (treesit-query-compile 'c-sharp "(string_content)" t)
750 t))
751 745
752(defun csharp-ts-mode--test-type-constraint () 746(defun csharp-ts-mode--test-type-constraint ()
753 "Return non-nil if (type_constraint) is in the grammar." 747 "Return non-nil if (type_constraint) is in the grammar."
754 (ignore-errors 748 (treesit-query-valid-p 'c-sharp "(type_constraint)"))
755 (treesit-query-compile 'c-sharp "(type_constraint)" t)
756 t))
757 749
758(defun csharp-ts-mode--test-type-of-expression () 750(defun csharp-ts-mode--test-type-of-expression ()
759 "Return non-nil if (type_of_expression) is in the grammar." 751 "Return non-nil if (type_of_expression) is in the grammar."
760 (ignore-errors 752 (treesit-query-valid-p 'c-sharp "(type_of_expression)"))
761 (treesit-query-compile 'c-sharp "(type_of_expression)" t)
762 t))
763 753
764(defun csharp-ts-mode--test-typeof-expression () 754(defun csharp-ts-mode--test-typeof-expression ()
765 "Return non-nil if (type_of_expression) is in the grammar." 755 "Return non-nil if (type_of_expression) is in the grammar."
766 (ignore-errors 756 (treesit-query-valid-p 'c-sharp "(typeof_expression)"))
767 (treesit-query-compile 'c-sharp "(typeof_expression)" t)
768 t))
769 757
770(defun csharp-ts-mode--test-name-equals () 758(defun csharp-ts-mode--test-name-equals ()
771 "Return non-nil if (name_equals) is in the grammar." 759 "Return non-nil if (name_equals) is in the grammar."
772 (ignore-errors 760 (treesit-query-valid-p 'c-sharp "(name_equals)"))
773 (treesit-query-compile 'c-sharp "(name_equals)" t)
774 t))
775 761
776(defun csharp-ts-mode--test-if-directive () 762(defun csharp-ts-mode--test-if-directive ()
777 "Return non-nil if (if_directive) is in the grammar." 763 "Return non-nil if (if_directive) is in the grammar."
778 (ignore-errors 764 (treesit-query-valid-p 'c-sharp "(if_directive)"))
779 (treesit-query-compile 'c-sharp "(if_directive)" t)
780 t))
781 765
782(defun csharp-ts-mode--test-method-declaration-type-field () 766(defun csharp-ts-mode--test-method-declaration-type-field ()
783 "Return non-nil if (method_declaration) has a type field." 767 "Return non-nil if (method_declaration) has a type field."
784 (ignore-errors 768 (treesit-query-valid-p 'c-sharp "(method_declaration type: (_))"))
785 (treesit-query-compile 'c-sharp "(method_declaration type: (_))" t)
786 t))
787 769
788(defvar csharp-ts-mode--type-field 770(defvar csharp-ts-mode--type-field
789 (if (csharp-ts-mode--test-method-declaration-type-field) 771 (if (csharp-ts-mode--test-method-declaration-type-field)
diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el
index b3e9ad51eaa..5e3f30d94c9 100644
--- a/lisp/progmodes/php-ts-mode.el
+++ b/lisp/progmodes/php-ts-mode.el
@@ -840,28 +840,23 @@ characters of the current line."
840 840
841(defun php-ts-mode--test-namespace-name-as-prefix-p () 841(defun php-ts-mode--test-namespace-name-as-prefix-p ()
842 "Return t if namespace_name_as_prefix is a named node, nil otherwise." 842 "Return t if namespace_name_as_prefix is a named node, nil otherwise."
843 (ignore-errors 843 (treesit-query-valid-p 'php "(namespace_name_as_prefix)"))
844 (progn (treesit-query-compile 'php "(namespace_name_as_prefix)" t) t)))
845 844
846(defun php-ts-mode--test-namespace-aliasing-clause-p () 845(defun php-ts-mode--test-namespace-aliasing-clause-p ()
847 "Return t if namespace_aliasing_clause is a named node, nil otherwise." 846 "Return t if namespace_aliasing_clause is a named node, nil otherwise."
848 (ignore-errors 847 (treesit-query-valid-p 'php "(namespace_aliasing_clause)"))
849 (progn (treesit-query-compile 'php "(namespace_aliasing_clause)" t) t)))
850 848
851(defun php-ts-mode--test-namespace-use-group-clause-p () 849(defun php-ts-mode--test-namespace-use-group-clause-p ()
852 "Return t if namespace_use_group_clause is a named node, nil otherwise." 850 "Return t if namespace_use_group_clause is a named node, nil otherwise."
853 (ignore-errors 851 (treesit-query-valid-p 'php "(namespace_use_group_clause)"))
854 (progn (treesit-query-compile 'php "(namespace_use_group_clause)" t) t)))
855 852
856(defun php-ts-mode--test-visibility-modifier-operation-clause-p () 853(defun php-ts-mode--test-visibility-modifier-operation-clause-p ()
857 "Return t if (visibility_modifier (operation)) is defined, nil otherwise." 854 "Return t if (visibility_modifier (operation)) is defined, nil otherwise."
858 (ignore-errors 855 (treesit-query-valid-p 'php "(visibility_modifier (operation))"))
859 (progn (treesit-query-compile 'php "(visibility_modifier (operation))" t) t)))
860 856
861(defun php-ts-mode--test-property-hook-clause-p () 857(defun php-ts-mode--test-property-hook-clause-p ()
862 "Return t if property_hook is a named node, nil otherwise." 858 "Return t if property_hook is a named node, nil otherwise."
863 (ignore-errors 859 (treesit-query-valid-p 'php "(property_hook)"))
864 (progn (treesit-query-compile 'php "(property_hook)" t) t)))
865 860
866(defun php-ts-mode--font-lock-settings () 861(defun php-ts-mode--font-lock-settings ()
867 "Tree-sitter font-lock settings." 862 "Tree-sitter font-lock settings."
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 1b971fa80fd..50ebefa7871 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -246,12 +246,10 @@ Argument LANGUAGE is either `typescript' or `tsx'."
246 246
247 (jsx_attribute (property_identifier) 247 (jsx_attribute (property_identifier)
248 @typescript-ts-jsx-attribute-face)))) 248 @typescript-ts-jsx-attribute-face))))
249 (or (ignore-errors 249 (or (and (treesit-query-valid-p language queries-a)
250 (treesit-query-compile language queries-a t) 250 queries-a)
251 queries-a) 251 (and (treesit-query-valid-p language queries-b)
252 (ignore-errors 252 queries-b)
253 (treesit-query-compile language queries-b t)
254 queries-b)
255 ;; Return a dummy query that doesn't do anything, if neither 253 ;; Return a dummy query that doesn't do anything, if neither
256 ;; query works. 254 ;; query works.
257 '("," @_ignore)))) 255 '("," @_ignore))))