@@ -470,7 +470,7 @@ if a third argument (the value) is provided.
470470 :* )
471471 (:match , clojure-ts--interface-def-symbol-regexp @_def_symbol))))
472472
473- (defconst clojure-ts--match-docstring-query-compiled
473+ (defconst clojure-ts--match-docstring-query
474474 (treesit-query-compile 'clojure (clojure-ts--docstring-query '@font-lock-doc-face ))
475475 " Precompiled query that matches a Clojure docstring." )
476476
@@ -839,9 +839,14 @@ Skip the optional metadata node at pos 0 if present."
839839 t )))
840840
841841(defun clojure-ts--first-value-child (node )
842- " Return the first value child of the NODE.
843-
844- This will skip metadata and comment nodes."
842+ " Returns the first value child of the given NODE.
843+
844+ In the syntax tree, there are a few types of possible child nodes:
845+ unnamed standalone nodes (e.g., comments), anonymous nodes (e.g.,
846+ opening or closing parentheses), and named nodes. Named nodes are
847+ standalone nodes that are labeled by a specific name. The most common
848+ names are meta and value. This function skips any unnamed, anonymous,
849+ and metadata nodes and returns the first value node."
845850 (treesit-node-child-by-field-name node " value" ))
846851
847852(defun clojure-ts--symbol-matches-p (symbol-regexp node )
@@ -1363,7 +1368,7 @@ according to the rule. If NODE is nil, use next node after BOL."
13631368 " Match PARENT when it is a docstring node."
13641369 (when-let* ((top-level-node (treesit-parent-until parent 'defun t ))
13651370 (result (treesit-query-capture top-level-node
1366- clojure-ts--match-docstring-query-compiled )))
1371+ clojure-ts--match-docstring-query)))
13671372 (seq-find (lambda (elt )
13681373 (and (eq (car elt) 'font-lock-doc-face )
13691374 (treesit-node-eq (cdr elt) parent)))
@@ -1529,6 +1534,9 @@ function literal."
15291534 `((clojure
15301535 (sexp ,(regexp-opt clojure-ts--sexp-nodes))
15311536 (list ,(regexp-opt clojure-ts--list-nodes))
1537+ ; ; `sexp-default' thing allows to fallback to the default implementation of
1538+ ; ; `forward-sexp' function where `treesit-forward-sexp' produces undesired
1539+ ; ; results.
15321540 (sexp-default
15331541 ; ; For `C-M-f' in "#|(a)" or "#|{1 2 3}"
15341542 (,(rx (or " (" " {" )) . ,#'clojure-ts--default-sexp-node-p ))
@@ -2470,8 +2478,13 @@ before DELIM-OPEN."
24702478 " v0.24.3" ))
24712479 " Intended to be used as the value for `treesit-language-source-alist' ." )
24722480
2473- (defun clojure-ts--grammar-outdated-p ()
2474- " Return TRUE if currently installed grammar is outdated."
2481+ (defun clojure-ts--clojure-grammar-outdated-p ()
2482+ " Return TRUE if currently installed grammar is outdated.
2483+
2484+ This function checks if `clojure-ts-mode' is compatible with the
2485+ currently installed grammar. The simplest way to do this is to validate
2486+ a query that is valid in a previous grammar version but invalid in the
2487+ required version."
24752488 (treesit-query-valid-p 'clojure '((sym_lit (meta_lit)))))
24762489
24772490(defun clojure-ts--ensure-grammars ()
@@ -2483,7 +2496,7 @@ before DELIM-OPEN."
24832496 ; ; If Clojure grammar is available, but outdated, re-install
24842497 ; ; it.
24852498 (and (equal grammar 'clojure )
2486- (clojure-ts--grammar-outdated-p)))
2499+ (clojure-ts--clojure- grammar-outdated-p)))
24872500 (message " Installing %s Tree-sitter grammar " grammar)
24882501 ; ; `treesit-language-source-alist' is dynamically scoped.
24892502 ; ; Binding it in this let expression allows
0 commit comments