diff options
| author | Vincenzo Pupillo | 2025-02-03 22:14:44 +0100 |
|---|---|---|
| committer | Yuan Fu | 2025-02-04 23:54:47 -0800 |
| commit | 4396f6414c2fb82cb8cee68420b658e376bb4e01 (patch) | |
| tree | 9ee792dfd4c47d03c4caf4ea09295580f88d92be | |
| parent | 12a3145b3b9480e5e5993dac28df52a36cc7b95d (diff) | |
| download | emacs-4396f6414c2fb82cb8cee68420b658e376bb4e01.tar.gz emacs-4396f6414c2fb82cb8cee68420b658e376bb4e01.zip | |
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.
| -rw-r--r-- | lisp/progmodes/js.el | 22 |
1 files changed, 21 insertions, 1 deletions
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 @@ Check if a node type is available, then return the right indent rules." | |||
| 3490 | ((match "/" "jsx_self_closing_element") parent 0) | 3490 | ((match "/" "jsx_self_closing_element") parent 0) |
| 3491 | ((parent-is "jsx_self_closing_element") parent js-indent-level) | 3491 | ((parent-is "jsx_self_closing_element") parent js-indent-level) |
| 3492 | ;; FIXME(Theo): This no-node catch-all should be removed. When is it needed? | 3492 | ;; FIXME(Theo): This no-node catch-all should be removed. When is it needed? |
| 3493 | (no-node parent-bol 0))))) | 3493 | (no-node parent-bol 0)) |
| 3494 | (jsdoc | ||
| 3495 | ((and (parent-is "document") c-ts-common-looking-at-star) | ||
| 3496 | c-ts-common-comment-start-after-first-star -1))))) | ||
| 3494 | 3497 | ||
| 3495 | (defvar js--treesit-keywords | 3498 | (defvar js--treesit-keywords |
| 3496 | '("as" "async" "await" "break" "case" "catch" "class" "const" "continue" | 3499 | '("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." | |||
| 3718 | ("lexical_declaration" (treesit-node-top-level node)) | 3721 | ("lexical_declaration" (treesit-node-top-level node)) |
| 3719 | (_ t))) | 3722 | (_ t))) |
| 3720 | 3723 | ||
| 3724 | (defun js--treesit-language-at-point (point) | ||
| 3725 | "Return the language at POINT." | ||
| 3726 | (let* ((node (treesit-node-at point 'javascript)) | ||
| 3727 | (node-type (treesit-node-type node)) | ||
| 3728 | (node-start (treesit-node-start node)) | ||
| 3729 | (node-end (treesit-node-end node))) | ||
| 3730 | (if (not (treesit-ready-p 'jsdoc t)) | ||
| 3731 | 'javascript | ||
| 3732 | (if (equal node-type "comment") | ||
| 3733 | (save-excursion | ||
| 3734 | (goto-char node-start) | ||
| 3735 | (if (search-forward "/**" node-end t) | ||
| 3736 | 'jsdoc | ||
| 3737 | 'javascript)) | ||
| 3738 | 'javascript)))) | ||
| 3739 | |||
| 3721 | ;;; Main Function | 3740 | ;;; Main Function |
| 3722 | 3741 | ||
| 3723 | ;;;###autoload | 3742 | ;;;###autoload |
| @@ -3927,6 +3946,7 @@ See `treesit-thing-settings' for more information.") | |||
| 3927 | 3946 | ||
| 3928 | ;; Tree-sitter setup. | 3947 | ;; Tree-sitter setup. |
| 3929 | (setq-local treesit-primary-parser (treesit-parser-create 'javascript)) | 3948 | (setq-local treesit-primary-parser (treesit-parser-create 'javascript)) |
| 3949 | (setq-local treesit-language-at-point-function #'js--treesit-language-at-point) | ||
| 3930 | 3950 | ||
| 3931 | ;; Indent. | 3951 | ;; Indent. |
| 3932 | (setq-local treesit-simple-indent-rules js--treesit-indent-rules) | 3952 | (setq-local treesit-simple-indent-rules js--treesit-indent-rules) |