:feature 'definition
`(,@(js--treesit-font-lock-compatibility-definition-feature)
+ (class
+ name: (identifier) @font-lock-type-face)
+
(class_declaration
name: (identifier) @font-lock-type-face)
(treesit-node-text
(treesit-node-child-by-field-name
(pcase (treesit-node-type node)
- ("lexical_declaration"
+ ((or "lexical_declaration" "variable_declaration")
(treesit-search-subtree node "variable_declarator" nil nil 1))
((or "function_declaration" "method_definition" "class_declaration")
node))
t))
(defun js--treesit-valid-imenu-entry (node)
- "Return nil if NODE is a non-top-level \"lexical_declaration\"."
+ "Return nil if NODE is a non-top-level lexical/variable declaration."
(pcase (treesit-node-type node)
- ("lexical_declaration" (treesit-node-top-level node))
+ ((or "lexical_declaration" "variable_declaration")
+ (not (treesit-node-top-level
+ node (rx bos (or "class_declaration"
+ "method_definition"
+ "function_declaration"
+ "function_expression")
+ eos))))
(_ t)))
(defun js--treesit-language-at-point (point)
"labeled_statement"
"variable_declaration"
"lexical_declaration"
- "jsx_element"
- "jsx_self_closing_element")
+ "jsx_attribute")
"Nodes that designate sentences in JavaScript.
See `treesit-thing-settings' for more information.")
"object_pattern"
"array"
"array_pattern"
+ "jsx_element"
"jsx_expression"
- "_jsx_string"
+ "jsx_self_closing_element"
"string"
"regex"
"arguments"
"Settings for `treesit-font-lock-feature-list'.")
(defvar js--treesit-simple-imenu-settings
- `(("Function" "\\`function_declaration\\'" nil nil)
- ("Variable" "\\`lexical_declaration\\'"
- js--treesit-valid-imenu-entry nil)
- ("Class" ,(rx bos (or "class_declaration"
- "method_definition")
- eos)
- nil nil))
+ `(("Class" "\\`class_declaration\\'" nil nil)
+ ("Method" "\\`method_definition\\'" nil nil)
+ ("Function" "\\`function_declaration\\'" nil nil)
+ ("Variable" ,(rx bos (or "lexical_declaration"
+ "variable_declaration")
+ eos)
+ ,#'js--treesit-valid-imenu-entry nil))
"Settings for `treesit-simple-imenu'.")
+(defvar js-ts-mode--outline-predicate
+ `(or (and "\\`class\\'" named)
+ ,(rx bos (or"class_declaration"
+ "method_definition"
+ "function_declaration"
+ "function_expression")
+ eos)))
+
(defvar js--treesit-defun-type-regexp
- (rx (or "class_declaration"
- "method_definition"
- "function_declaration"
- "lexical_declaration"))
+ (rx bos (or "class_declaration"
+ "method_definition"
+ "function_declaration"
+ "lexical_declaration"
+ "variable_declaration")
+ eos)
"Settings for `treesit-defun-type-regexp'.")
(defvar js--treesit-jsdoc-comment-regexp
- (rx (or "comment" "line_comment" "block_comment" "description"))
+ (rx bos (or "comment" "line_comment" "block_comment" "description") eos)
"Regexp for `c-ts-common--comment-regexp'.")
;;;###autoload
;; Imenu
(setq-local treesit-simple-imenu-settings js--treesit-simple-imenu-settings)
+ ;; Outline minor mode
+ (setq-local treesit-outline-predicate js-ts-mode--outline-predicate)
(treesit-major-mode-setup)
(defvar mhtml-ts-mode--prettify-symbols-alist js--prettify-symbols-alist
"Alist of symbol prettifications for various supported languages.")
-(defun mhtml-ts-mode--html-defun-name (node)
- "Return the defun name of NODE.
-Return nil if there is no name or if NODE is not a defun node."
- (when (string-match-p "element" (treesit-node-type node))
- (treesit-node-text
- node
- ;; (treesit-search-subtree node "\\`tag_name\\'" nil nil 2)
- t)))
-
;; In order to support `which-fuction-mode' we should define
;; a function that return the defun name.
;; In a multilingual treesit mode, this can be implemented simply by
(setq-local treesit-aggregated-outline-predicate
`((html . ,#'html-ts-mode--outline-predicate)
- ;; TODO: add a predicate like for html above
- (javascript . "\\`function_declaration\\'")
+ (javascript . ,js-ts-mode--outline-predicate)
(css . ,css-ts-mode--outline-predicate)))
(treesit-major-mode-setup)