]> git.eshelyaron.com Git - emacs.git/commitdiff
Change treesit-check-query and mention it in documentation
authorYuan Fu <casouri@gmail.com>
Tue, 14 Jun 2022 21:30:39 +0000 (14:30 -0700)
committerYuan Fu <casouri@gmail.com>
Tue, 14 Jun 2022 21:30:39 +0000 (14:30 -0700)
* doc/lispref/parsing.texi (Pattern Matching): Mention it.
* lisp/treesit.el (treesit-check-query): Rename to
treesit-query-validate.
* src/treesit.c (Ftreesit_query_capture, Ftreesit_query_compile):
Mention it.

doc/lispref/parsing.texi
lisp/treesit.el
src/treesit.c

index 1c4a7805a31f752d495d4fc2e4043c5808bbb2e2..36c03364e3960acb54623eb84d6e4b7ac166faeb 100644 (file)
@@ -816,7 +816,7 @@ are both non-nil, it only pattern matches nodes in that range.
 @vindex treesit-query-error
 This function raise a @var{treesit-query-error} if @var{query} is
 malformed.  The signal data contains a description of the specific
-error.
+error.  You can use @code{treesit-query-validate} to debug the query.
 @end defun
 
 @defun treesit-query-in source query &optional beg end
@@ -1111,6 +1111,10 @@ a query is accepted.
 @defun treesit-query-compile language query
 This function compiles @var{query} for @var{language} into a compiled
 query object and returns it.
+
+This function raise a @var{treesit-query-error} if @var{query} is
+malformed.  The signal data contains a description of the specific
+error.  You can use @code{treesit-query-validate} to debug the query.
 @end defun
 
 @defun treesit-expand-query query
index 09f750f9d52004b87451585cfc5a7d26d8ae9049..ad90d9f9f01af6106e2c25725d6a51dbbc89c428 100644 (file)
@@ -1038,10 +1038,11 @@ uses the first parser in `treesit-parser-list'."
           (remove '(:eval treesit--inspect-name)
                   mode-line-misc-info))))
 
-(defun treesit-check-query (query language)
+(defun treesit-query-validate (language query)
   "Check if QUERY is valid for LANGUAGE.
 If QUERY is invalid, display the query in a popup buffer, jumps
 to the offending pattern and highlight the pattern."
+  (cl-assert (or (consp query) (stringp query)))
   (let ((buf (get-buffer-create "*tree-sitter check query*")))
     (with-temp-buffer
       (treesit-get-parser-create language)
index 5b344a2ea1c735a52c45b06dc2864e796da20352..df8c992bb5d7c1fc893cdb5513cec5f64bd520f8 100644 (file)
@@ -1522,8 +1522,9 @@ DEFUN ("treesit-query-compile",
 Querying a compiled query is much faster than an uncompiled one.
 LANGUAGE is the language this query is for.
 
-Signals treesit-query-error if QUERY is malformed or something
-else goes wrong.  */)
+Signals treesit-query-error if QUERY is malformed or something else
+goes wrong.  You can use `treesit-query-validate' to debug the
+query.  */)
   (Lisp_Object language, Lisp_Object query)
 {
   if (!Ftreesit_query_p (query))
@@ -1564,8 +1565,9 @@ compile your queries if it will be used over and over.
 BEG and END, if both non-nil, specifies the range in which the query
 is executed.
 
-Raise an treesit-query-error if QUERY is malformed, or something
-else goes wrong.  */)
+Signals treesit-query-error if QUERY is malformed or something else
+goes wrong.  You can use `treesit-query-validate' to debug the
+query.  */)
   (Lisp_Object node, Lisp_Object query,
    Lisp_Object beg, Lisp_Object end)
 {