1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

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'.
This commit is contained in:
Juri Linkov 2025-04-22 21:01:28 +03:00
parent 573a2c09b9
commit add8bf000a
5 changed files with 21 additions and 52 deletions

View file

@ -156,9 +156,7 @@ queries that has problems with latest grammar."
(unless (memq language (alist-get mode mode-language-alist)) (unless (memq language (alist-get mode mode-language-alist))
(push language (alist-get mode mode-language-alist))) (push language (alist-get mode mode-language-alist)))
;; Validate query. ;; Validate query.
(when (not (ignore-errors (unless (treesit-query-valid-p language query)
(treesit-query-compile language query t)
t))
(push (list mode language feature) invalid-feature-list) (push (list mode language feature) invalid-feature-list)
(setq all-queries-valid nil)))) (setq all-queries-valid nil))))
(when all-queries-valid (when all-queries-valid
@ -261,9 +259,7 @@ Return non-nil if all queries are valid, nil otherwise."
(language (treesit-query-language query))) (language (treesit-query-language query)))
;; Validate query. ;; Validate query.
(when (and (eq lang language) (when (and (eq lang language)
(not (ignore-errors (not (treesit-query-valid-p language query)))
(treesit-query-compile language query t)
t)))
(setq all-queries-valid nil)))) (setq all-queries-valid nil))))
all-queries-valid)) all-queries-valid))

View file

@ -674,9 +674,7 @@ MODE should be either `c' or `cpp'."
(mapcan (mapcan
(lambda (entry) (lambda (entry)
(let ((keywords (cdr entry))) (let ((keywords (cdr entry)))
(if (ignore-errors (if (treesit-query-valid-p 'c `([,@keywords] @cap))
(treesit-query-compile 'c `([,@keywords] @cap) t)
t)
(copy-sequence keywords) (copy-sequence keywords)
nil))) nil)))
c-ts-mode--optional-c-keywords) c-ts-mode--optional-c-keywords)

View file

@ -733,57 +733,39 @@ compilation and evaluation time conflicts."
(defun csharp-ts-mode--test-this-expression () (defun csharp-ts-mode--test-this-expression ()
"Return non-nil if (this_expression) is named in csharp grammar." "Return non-nil if (this_expression) is named in csharp grammar."
(ignore-errors (treesit-query-valid-p 'c-sharp "(this_expression)"))
(treesit-query-compile 'c-sharp "(this_expression)" t)
t))
(defun csharp-ts-mode--test-interpolated-string-text () (defun csharp-ts-mode--test-interpolated-string-text ()
"Return non-nil if (interpolated_string_text) is in the grammar." "Return non-nil if (interpolated_string_text) is in the grammar."
(ignore-errors (treesit-query-valid-p 'c-sharp "(interpolated_string_text)"))
(treesit-query-compile 'c-sharp "(interpolated_string_text)" t)
t))
(defun csharp-ts-mode--test-string-content () (defun csharp-ts-mode--test-string-content ()
"Return non-nil if (interpolated_string_text) is in the grammar." "Return non-nil if (interpolated_string_text) is in the grammar."
(ignore-errors (treesit-query-valid-p 'c-sharp "(string_content)"))
(treesit-query-compile 'c-sharp "(string_content)" t)
t))
(defun csharp-ts-mode--test-type-constraint () (defun csharp-ts-mode--test-type-constraint ()
"Return non-nil if (type_constraint) is in the grammar." "Return non-nil if (type_constraint) is in the grammar."
(ignore-errors (treesit-query-valid-p 'c-sharp "(type_constraint)"))
(treesit-query-compile 'c-sharp "(type_constraint)" t)
t))
(defun csharp-ts-mode--test-type-of-expression () (defun csharp-ts-mode--test-type-of-expression ()
"Return non-nil if (type_of_expression) is in the grammar." "Return non-nil if (type_of_expression) is in the grammar."
(ignore-errors (treesit-query-valid-p 'c-sharp "(type_of_expression)"))
(treesit-query-compile 'c-sharp "(type_of_expression)" t)
t))
(defun csharp-ts-mode--test-typeof-expression () (defun csharp-ts-mode--test-typeof-expression ()
"Return non-nil if (type_of_expression) is in the grammar." "Return non-nil if (type_of_expression) is in the grammar."
(ignore-errors (treesit-query-valid-p 'c-sharp "(typeof_expression)"))
(treesit-query-compile 'c-sharp "(typeof_expression)" t)
t))
(defun csharp-ts-mode--test-name-equals () (defun csharp-ts-mode--test-name-equals ()
"Return non-nil if (name_equals) is in the grammar." "Return non-nil if (name_equals) is in the grammar."
(ignore-errors (treesit-query-valid-p 'c-sharp "(name_equals)"))
(treesit-query-compile 'c-sharp "(name_equals)" t)
t))
(defun csharp-ts-mode--test-if-directive () (defun csharp-ts-mode--test-if-directive ()
"Return non-nil if (if_directive) is in the grammar." "Return non-nil if (if_directive) is in the grammar."
(ignore-errors (treesit-query-valid-p 'c-sharp "(if_directive)"))
(treesit-query-compile 'c-sharp "(if_directive)" t)
t))
(defun csharp-ts-mode--test-method-declaration-type-field () (defun csharp-ts-mode--test-method-declaration-type-field ()
"Return non-nil if (method_declaration) has a type field." "Return non-nil if (method_declaration) has a type field."
(ignore-errors (treesit-query-valid-p 'c-sharp "(method_declaration type: (_))"))
(treesit-query-compile 'c-sharp "(method_declaration type: (_))" t)
t))
(defvar csharp-ts-mode--type-field (defvar csharp-ts-mode--type-field
(if (csharp-ts-mode--test-method-declaration-type-field) (if (csharp-ts-mode--test-method-declaration-type-field)

View file

@ -840,28 +840,23 @@ characters of the current line."
(defun php-ts-mode--test-namespace-name-as-prefix-p () (defun php-ts-mode--test-namespace-name-as-prefix-p ()
"Return t if namespace_name_as_prefix is a named node, nil otherwise." "Return t if namespace_name_as_prefix is a named node, nil otherwise."
(ignore-errors (treesit-query-valid-p 'php "(namespace_name_as_prefix)"))
(progn (treesit-query-compile 'php "(namespace_name_as_prefix)" t) t)))
(defun php-ts-mode--test-namespace-aliasing-clause-p () (defun php-ts-mode--test-namespace-aliasing-clause-p ()
"Return t if namespace_aliasing_clause is a named node, nil otherwise." "Return t if namespace_aliasing_clause is a named node, nil otherwise."
(ignore-errors (treesit-query-valid-p 'php "(namespace_aliasing_clause)"))
(progn (treesit-query-compile 'php "(namespace_aliasing_clause)" t) t)))
(defun php-ts-mode--test-namespace-use-group-clause-p () (defun php-ts-mode--test-namespace-use-group-clause-p ()
"Return t if namespace_use_group_clause is a named node, nil otherwise." "Return t if namespace_use_group_clause is a named node, nil otherwise."
(ignore-errors (treesit-query-valid-p 'php "(namespace_use_group_clause)"))
(progn (treesit-query-compile 'php "(namespace_use_group_clause)" t) t)))
(defun php-ts-mode--test-visibility-modifier-operation-clause-p () (defun php-ts-mode--test-visibility-modifier-operation-clause-p ()
"Return t if (visibility_modifier (operation)) is defined, nil otherwise." "Return t if (visibility_modifier (operation)) is defined, nil otherwise."
(ignore-errors (treesit-query-valid-p 'php "(visibility_modifier (operation))"))
(progn (treesit-query-compile 'php "(visibility_modifier (operation))" t) t)))
(defun php-ts-mode--test-property-hook-clause-p () (defun php-ts-mode--test-property-hook-clause-p ()
"Return t if property_hook is a named node, nil otherwise." "Return t if property_hook is a named node, nil otherwise."
(ignore-errors (treesit-query-valid-p 'php "(property_hook)"))
(progn (treesit-query-compile 'php "(property_hook)" t) t)))
(defun php-ts-mode--font-lock-settings () (defun php-ts-mode--font-lock-settings ()
"Tree-sitter font-lock settings." "Tree-sitter font-lock settings."

View file

@ -246,12 +246,10 @@ Argument LANGUAGE is either `typescript' or `tsx'."
(jsx_attribute (property_identifier) (jsx_attribute (property_identifier)
@typescript-ts-jsx-attribute-face)))) @typescript-ts-jsx-attribute-face))))
(or (ignore-errors (or (and (treesit-query-valid-p language queries-a)
(treesit-query-compile language queries-a t) queries-a)
queries-a) (and (treesit-query-valid-p language queries-b)
(ignore-errors queries-b)
(treesit-query-compile language queries-b t)
queries-b)
;; Return a dummy query that doesn't do anything, if neither ;; Return a dummy query that doesn't do anything, if neither
;; query works. ;; query works.
'("," @_ignore)))) '("," @_ignore))))