From: Vincenzo Pupillo Date: Mon, 3 Feb 2025 21:14:44 +0000 (+0100) Subject: Correctly handled the local parser for jsdoc (bug#75456) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=fa874d2783c9e9f7ad9ff468a0f643368da2ac06;p=emacs.git Correctly handled the local parser for jsdoc (bug#75456) 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. (cherry picked from commit 4396f6414c2fb82cb8cee68420b658e376bb4e01) --- diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 4e2e32132ef..81cf02664c6 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -3490,7 +3490,10 @@ Check if a node type is available, then return the right 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 @@ Return nil if there is no name or if NODE is not a defun node." ("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 @@ -3922,6 +3941,7 @@ See `treesit-thing-settings' for more information.") ;; 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)