From: Juri Linkov Date: Tue, 22 Apr 2025 18:01:28 +0000 (+0300) Subject: Replace some 'treesit-query-compile' with 'treesit-query-valid-p'. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e8712baf2280b030b25df19a449de13c90051675;p=emacs.git 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'. (cherry picked from commit add8bf000aee39e40feacff7e0df7248fa4ef9c5) --- 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." (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)) 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'." (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) 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." (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) diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el index 9b3fd32682e..8a739fc62c2 100644 --- a/lisp/progmodes/php-ts-mode.el +++ b/lisp/progmodes/php-ts-mode.el @@ -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." diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el index 254ed1cc345..9b5b7312e1c 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'." (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))))