Subject: bug#75456: 31.0.50; Cannot find the definition of the predicate in `treesit-thing-settings'" sexp-list)

From: Vincenzo Pupillo <[email-masked]>
Date: Mon, 03 Feb 2025 22:32:07 +0100

Ciao Yuan, thank you!
The attached patch solves the problem. I will fix php-ts-mode and
mhtml-ts-mode in the next few days.

Vincenzo

In data martedì 28 gennaio 2025 02:58:00 Ora standard dell’Europa centrale, 
Yuan Fu ha scritto:
> > On Jan 27, 2025, at 5:37 PM, Yuan Fu <[email-masked]> wrote:
> >> On Jan 19, 2025, at 10:59 PM, Yuan Fu <[email-masked]> wrote:
> >>> On Jan 18, 2025, at 8:52 AM, Vincenzo Pupillo <[email-masked]>
> >>> wrote:
> >>> 
> >>> Ciao Yuan,
> >>> 
> >>> In data sabato 18 gennaio 2025 07:27:32 Ora standard dell’Europa
> >>> centrale,
> >>> 
> >>> Yuan Fu ha scritto:
> >>>> ....
> >>>> 
> >>>> I just pushed a fix, now you shouldn’t see jsdoc parsers anymore. Can
> >>>> you
> >>>> see if this fixes the problem you had?
> >>> 
> >>> I only tested js.el with
> >>> 0001-language-at-point-function-that-handles-local- parser.patch
> >>> I tested only js.el with the
> >>> 0001-language-at-point-function-that-handles-
> >>> local-parser.patch because it was less complex. The font-locking is ok
> >>> but the indentation of jsdoc type comments breaks because there are no
> >>> specific rules (for jsdoc) and also this message appears:
> >>> 
> >>> Error running timer 'show-paren-function': (treesit-no-parser jsdoc)
> >>> 
> >>> The comment:
> >>> ;; 2. In most cases, a function shouldn't implicitly create a parser.
> >>> ;; All parsers should be created explicitly by user.
> >>> 
> >>> Does this imply that we need to create local parsers as well?
> >> 
> >> No, that means treesit.el has a bug. I’ll fix it.
> >> 
> >> Yuan
> > 
> > Ok, so it’s two-fold. I fixed the problem that caused the
> > treesit-no-parser error on emacs-30 a few days ago, it should be on
> > master now.
> > 
> > As for jsdoc not having indentation rules, I think the right solution is
> > to add comment indentation rules for jsdoc too. You can just copy the
> > rules from js-ts-mode, js-ts-mode uses the canned rules from
> > c-ts-common.el anyway.
> Sorry, I lied, turns out I haven’t pushed the patch to emacs-30 yet. I did
> that just now. It should be on master in a few days.
> 
> Yuan

>From 5b4833da86afc85021cd32430e1969661865b460 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <[email-masked]>
Date: Mon, 3 Feb 2025 22:14:44 +0100
Subject: [PATCH] Correctly handled the local parser for jsdoc.

As a result of recent patches to treesitter, local parsers must now be
recognized by 'treesit-language-at-point' and have their own indentation
rules.

* lisp/progmodes/js.el
(js--treesit-indent-rules): New rule for jsdoc.
(js--treesit-language-at-point): New function.
(js-ts-mode): Use the new function.
---
 lisp/progmodes/js.el | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 8029a304757..3168395acf1 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3490,7 +3490,10 @@ js--treesit-indent-rules
        ((match "/" "jsx_self_closing_element") parent 0)
        ((parent-is "jsx_self_closing_element") parent js-indent-level)
        ;; FIXME(Theo): This no-node catch-all should be removed.  When is it needed?
-       (no-node parent-bol 0)))))
+       (no-node parent-bol 0))
+      (jsdoc
+       ((and (parent-is "document") c-ts-common-looking-at-star)
+        c-ts-common-comment-start-after-first-star -1)))))
 
 (defvar js--treesit-keywords
   '("as" "async" "await" "break" "case" "catch" "class" "const" "continue"
@@ -3718,6 +3721,22 @@ js--treesit-valid-imenu-entry
     ("lexical_declaration" (treesit-node-top-level node))
     (_ t)))
 
+(defun js--treesit-language-at-point (point)
+  "Return the language at POINT."
+  (let* ((node (treesit-node-at point 'javascript))
+         (node-type (treesit-node-type node))
+         (node-start (treesit-node-start node))
+         (node-end (treesit-node-end node)))
+    (if (not (treesit-ready-p 'jsdoc t))
+        'javascript
+      (if (equal node-type "comment")
+          (save-excursion
+            (goto-char node-start)
+            (if (search-forward "/**" node-end t)
+                'jsdoc
+              'javascript))
+        'javascript))))
+
 ;;; Main Function
 
 ;;;###autoload
@@ -3927,6 +3946,7 @@ js-ts-mode
 
     ;; Tree-sitter setup.
     (setq-local treesit-primary-parser (treesit-parser-create 'javascript))
+    (setq-local treesit-language-at-point-function #'js--treesit-language-at-point)
 
     ;; Indent.
     (setq-local treesit-simple-indent-rules js--treesit-indent-rules)
-- 
2.48.1