- if let Some(range) =
- contiguous_range_for_comment(comment, &mut visited_comments)
- {
- res.push(Fold { range, kind: FoldKind::Comment })
+ // regions are not really comments
+ use regex::Regex;
+ lazy_static! {
+ static ref RE_START: Regex =
+ Regex::new(r"^\s*//\s*#?region\b").unwrap();
+ static ref RE_END: Regex =
+ Regex::new(r"^\s*//\s*#?endregion\b").unwrap();
+ }
+ if RE_START.is_match(comment.text()) {
+ regions_starts.push(comment.syntax().text_range().start());
+ } else if RE_END.is_match(comment.text()) {
+ if !regions_starts.is_empty() {
+ res.push(Fold {
+ range: TextRange::new(
+ regions_starts.pop().unwrap(),
+ comment.syntax().text_range().end(),
+ ),
+ kind: FoldKind::Region,
+ })
+ }
+ } else {
+ if let Some(range) =
+ contiguous_range_for_comment(comment, &mut visited_comments)
+ {
+ res.push(Fold { range, kind: FoldKind::Comment })
+ }