From 084b21bc36cd624e8db708eb1e12dd6db99a0602 Mon Sep 17 00:00:00 2001 From: Luciano Bestia Date: Fri, 5 Feb 2021 14:32:03 +0100 Subject: simple comparison instead of regex --- crates/ide/src/folding_ranges.rs | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'crates/ide/src') diff --git a/crates/ide/src/folding_ranges.rs b/crates/ide/src/folding_ranges.rs index 99f0c3c99..7ba775a77 100644 --- a/crates/ide/src/folding_ranges.rs +++ b/crates/ide/src/folding_ranges.rs @@ -9,8 +9,6 @@ use syntax::{ SyntaxNode, TextRange, TextSize, }; -use lazy_static::lazy_static; - #[derive(Debug, PartialEq, Eq)] pub enum FoldKind { Comment, @@ -53,17 +51,10 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec { // Fold groups of comments if let Some(comment) = ast::Comment::cast(token) { if !visited_comments.contains(&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 are not real comments + if comment.text().trim().starts_with("// region:") { regions_starts.push(comment.syntax().text_range().start()); - } else if RE_END.is_match(comment.text()) { + } else if comment.text().trim().starts_with("// endregion") { if !regions_starts.is_empty() { res.push(Fold { range: TextRange::new( @@ -202,15 +193,10 @@ fn contiguous_range_for_comment( } if let Some(c) = ast::Comment::cast(token) { if c.kind() == group_kind { - // 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(c.text()) || RE_END.is_match(c.text()) { + // regions are not real comments + if c.text().trim().starts_with("// region:") + || c.text().trim().starts_with("// endregion") + { break; } else { visited.insert(c.clone()); -- cgit v1.2.3