]> git.eshelyaron.com Git - emacs.git/commitdiff
Replace some 'treesit-query-compile' with 'treesit-query-valid-p'.
authorJuri Linkov <juri@linkov.net>
Tue, 22 Apr 2025 18:01:28 +0000 (21:01 +0300)
committerEshel Yaron <me@eshelyaron.com>
Tue, 22 Apr 2025 18:48:23 +0000 (20:48 +0200)
* 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'.

(cherry picked from commit add8bf000aee39e40feacff7e0df7248fa4ef9c5)

admin/tree-sitter/treesit-admin.el
lisp/progmodes/c-ts-mode.el
lisp/progmodes/csharp-mode.el
lisp/progmodes/php-ts-mode.el
lisp/progmodes/typescript-ts-mode.el

index ef6d256a53857a1c24c1928c8116eb0fae1a5743..f41c45920390b06f105101b40252bfc21038f152 100644 (file)
@@ -156,9 +156,7 @@ queries that has problems with latest grammar."
             (unless (memq language (alist-get mode mode-language-alist))
               (push language (alist-get mode mode-language-alist)))
             ;; Validate query.
-            (when (not (ignore-errors
-                         (treesit-query-compile language query t)
-                         t))
+            (unless (treesit-query-valid-p language query)
               (push (list mode language feature) invalid-feature-list)
               (setq all-queries-valid nil))))
         (when all-queries-valid
@@ -261,9 +259,7 @@ Return non-nil if all queries are valid, nil otherwise."
              (language (treesit-query-language query)))
         ;; Validate query.
         (when (and (eq lang language)
-                   (not (ignore-errors
-                          (treesit-query-compile language query t)
-                          t)))
+                   (not (treesit-query-valid-p language query)))
           (setq all-queries-valid nil))))
     all-queries-valid))
 
index 8d4b6f587d51127fe724c9045606c739f1d3defd..070984f4aac9c08e089f982c62848d23f7728657 100644 (file)
@@ -674,9 +674,7 @@ MODE should be either `c' or `cpp'."
       (mapcan
        (lambda (entry)
          (let ((keywords (cdr entry)))
-           (if (ignore-errors
-                 (treesit-query-compile 'c `([,@keywords] @cap) t)
-                 t)
+           (if (treesit-query-valid-p 'c `([,@keywords] @cap))
                (copy-sequence keywords)
              nil)))
        c-ts-mode--optional-c-keywords)
index fe2fbb0d1e521395a76ed3c8d917a6bffad2ba87..a421d616d9b5c175e0bca7e56443a493f19f38fc 100644 (file)
@@ -733,57 +733,39 @@ compilation and evaluation time conflicts."
 
 (defun csharp-ts-mode--test-this-expression ()
   "Return non-nil if (this_expression) is named in csharp grammar."
-  (ignore-errors
-    (treesit-query-compile 'c-sharp "(this_expression)" t)
-    t))
+  (treesit-query-valid-p 'c-sharp "(this_expression)"))
 
 (defun csharp-ts-mode--test-interpolated-string-text ()
   "Return non-nil if (interpolated_string_text) is in the grammar."
-  (ignore-errors
-    (treesit-query-compile 'c-sharp "(interpolated_string_text)" t)
-    t))
+  (treesit-query-valid-p 'c-sharp "(interpolated_string_text)"))
 
 (defun csharp-ts-mode--test-string-content ()
   "Return non-nil if (interpolated_string_text) is in the grammar."
-  (ignore-errors
-    (treesit-query-compile 'c-sharp "(string_content)" t)
-    t))
+  (treesit-query-valid-p 'c-sharp "(string_content)"))
 
 (defun csharp-ts-mode--test-type-constraint ()
   "Return non-nil if (type_constraint) is in the grammar."
-  (ignore-errors
-    (treesit-query-compile 'c-sharp "(type_constraint)" t)
-    t))
+  (treesit-query-valid-p 'c-sharp "(type_constraint)"))
 
 (defun csharp-ts-mode--test-type-of-expression ()
   "Return non-nil if (type_of_expression) is in the grammar."
-  (ignore-errors
-    (treesit-query-compile 'c-sharp "(type_of_expression)" t)
-    t))
+  (treesit-query-valid-p 'c-sharp "(type_of_expression)"))
 
 (defun csharp-ts-mode--test-typeof-expression ()
   "Return non-nil if (type_of_expression) is in the grammar."
-  (ignore-errors
-    (treesit-query-compile 'c-sharp "(typeof_expression)" t)
-    t))
+  (treesit-query-valid-p 'c-sharp "(typeof_expression)"))
 
 (defun csharp-ts-mode--test-name-equals ()
   "Return non-nil if (name_equals) is in the grammar."
-  (ignore-errors
-    (treesit-query-compile 'c-sharp "(name_equals)" t)
-    t))
+  (treesit-query-valid-p 'c-sharp "(name_equals)"))
 
 (defun csharp-ts-mode--test-if-directive ()
   "Return non-nil if (if_directive) is in the grammar."
-  (ignore-errors
-    (treesit-query-compile 'c-sharp "(if_directive)" t)
-    t))
+  (treesit-query-valid-p 'c-sharp "(if_directive)"))
 
 (defun csharp-ts-mode--test-method-declaration-type-field ()
   "Return non-nil if (method_declaration) has a type field."
-  (ignore-errors
-    (treesit-query-compile 'c-sharp "(method_declaration type: (_))" t)
-    t))
+  (treesit-query-valid-p 'c-sharp "(method_declaration type: (_))"))
 
 (defvar csharp-ts-mode--type-field
   (if (csharp-ts-mode--test-method-declaration-type-field)
index 9b3fd32682e1ab5bbae5f0477d3658591f112fb7..8a739fc62c2d95120182cb81261f1f98cb8bde83 100644 (file)
@@ -839,28 +839,23 @@ characters of the current line."
 
 (defun php-ts-mode--test-namespace-name-as-prefix-p ()
   "Return t if namespace_name_as_prefix is a named node, nil otherwise."
-  (ignore-errors
-    (progn (treesit-query-compile 'php "(namespace_name_as_prefix)" t) t)))
+  (treesit-query-valid-p 'php "(namespace_name_as_prefix)"))
 
 (defun php-ts-mode--test-namespace-aliasing-clause-p ()
   "Return t if namespace_aliasing_clause is a named node, nil otherwise."
-  (ignore-errors
-    (progn (treesit-query-compile 'php "(namespace_aliasing_clause)" t) t)))
+  (treesit-query-valid-p 'php "(namespace_aliasing_clause)"))
 
 (defun php-ts-mode--test-namespace-use-group-clause-p ()
   "Return t if namespace_use_group_clause is a named node, nil otherwise."
-  (ignore-errors
-    (progn (treesit-query-compile 'php "(namespace_use_group_clause)" t) t)))
+  (treesit-query-valid-p 'php "(namespace_use_group_clause)"))
 
 (defun php-ts-mode--test-visibility-modifier-operation-clause-p ()
   "Return t if (visibility_modifier (operation)) is defined, nil otherwise."
-  (ignore-errors
-    (progn (treesit-query-compile 'php "(visibility_modifier (operation))" t) t)))
+  (treesit-query-valid-p 'php "(visibility_modifier (operation))"))
 
 (defun php-ts-mode--test-property-hook-clause-p ()
   "Return t if property_hook is a named node, nil otherwise."
-  (ignore-errors
-    (progn (treesit-query-compile 'php "(property_hook)" t) t)))
+  (treesit-query-valid-p 'php "(property_hook)"))
 
 (defun php-ts-mode--font-lock-settings ()
   "Tree-sitter font-lock settings."
index 254ed1cc345af1a4543911a742830dfeb7f7c3b3..9b5b7312e1c257e6d7f86bdcc5892360f07b9af8 100644 (file)
@@ -246,12 +246,10 @@ Argument LANGUAGE is either `typescript' or `tsx'."
 
                      (jsx_attribute (property_identifier)
                                     @typescript-ts-jsx-attribute-face))))
-    (or (ignore-errors
-          (treesit-query-compile language queries-a t)
-          queries-a)
-        (ignore-errors
-          (treesit-query-compile language queries-b t)
-          queries-b)
+    (or (and (treesit-query-valid-p language queries-a)
+             queries-a)
+        (and (treesit-query-valid-p language queries-b)
+             queries-b)
         ;; Return a dummy query that doesn't do anything, if neither
         ;; query works.
         '("," @_ignore))))