diff --git a/packages/language-html/grammars/tree-sitter-html/folds.scm b/packages/language-html/grammars/tree-sitter-html/folds.scm index 5c8919ff7..bc80d5ff6 100644 --- a/packages/language-html/grammars/tree-sitter-html/folds.scm +++ b/packages/language-html/grammars/tree-sitter-html/folds.scm @@ -1,6 +1,74 @@ +; When dealing with a self-closing element that spans multiple lines, this lets +; us fold the attribute list. +; +; This query captures elements that happen to be self-closing but don't end +; with an XHTML-style ` />`. Because `tree-sitter-html` doesn't distinguish +; these from elements that can have content, we have to check the tag name to +; know how to treat these. + +((element + (start_tag + (tag_name) @_IGNORE_) @fold) + (#match? @_IGNORE_ "^(area|base|br|col|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$") +) + +; This one captures the XHTML-style nodes. +(self_closing_tag) @fold + + +; TODO: Right now, the fold cache doesn't work properly when a given range +; satisfies more than one fold. We should employ `ScopeResolver` to fix this. + +; Fold up all of +; +;
+; +;
+; +; with the fold indicator appearing on whichever line has the `>` that closes +; the opening tag. +; +; Usually this'll be the same line on which the tag opened; but when it isn't, +; this allows for the attribute list of the opening element to be folded +; separately from the element's contents. +; + +(element + (start_tag + (tag_name) @_IGNORE_ + ">" @fold) + (#not-match? @_IGNORE_ "^(area|base|br|col|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$") + (#set! fold.endAt parent.parent.lastNamedChild.startPosition) + (#set! fold.adjustToEndOfPreviousRow true) +) + + +; When we have… +; +;
+; +;
+; +; …we can put a fold indicator on the line with `