aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src
diff options
context:
space:
mode:
authorLuciano Bestia <[email protected]>2021-02-05 13:32:03 +0000
committerLuciano Bestia <[email protected]>2021-02-05 13:32:03 +0000
commit084b21bc36cd624e8db708eb1e12dd6db99a0602 (patch)
treeea3500a01b5412ffb6391bff3d9d81a46c08d476 /crates/ide/src
parent9f1d341ee9bf399fa8fa2a5d2fb5f91e1b319702 (diff)
simple comparison instead of regex
Diffstat (limited to 'crates/ide/src')
-rw-r--r--crates/ide/src/folding_ranges.rs28
1 files changed, 7 insertions, 21 deletions
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::{
9 SyntaxNode, TextRange, TextSize, 9 SyntaxNode, TextRange, TextSize,
10}; 10};
11 11
12use lazy_static::lazy_static;
13
14#[derive(Debug, PartialEq, Eq)] 12#[derive(Debug, PartialEq, Eq)]
15pub enum FoldKind { 13pub enum FoldKind {
16 Comment, 14 Comment,
@@ -53,17 +51,10 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
53 // Fold groups of comments 51 // Fold groups of comments
54 if let Some(comment) = ast::Comment::cast(token) { 52 if let Some(comment) = ast::Comment::cast(token) {
55 if !visited_comments.contains(&comment) { 53 if !visited_comments.contains(&comment) {
56 // regions are not really comments 54 // regions are not real comments
57 use regex::Regex; 55 if comment.text().trim().starts_with("// region:") {
58 lazy_static! {
59 static ref RE_START: Regex =
60 Regex::new(r"^\s*//\s*#?region\b").unwrap();
61 static ref RE_END: Regex =
62 Regex::new(r"^\s*//\s*#?endregion\b").unwrap();
63 }
64 if RE_START.is_match(comment.text()) {
65 regions_starts.push(comment.syntax().text_range().start()); 56 regions_starts.push(comment.syntax().text_range().start());
66 } else if RE_END.is_match(comment.text()) { 57 } else if comment.text().trim().starts_with("// endregion") {
67 if !regions_starts.is_empty() { 58 if !regions_starts.is_empty() {
68 res.push(Fold { 59 res.push(Fold {
69 range: TextRange::new( 60 range: TextRange::new(
@@ -202,15 +193,10 @@ fn contiguous_range_for_comment(
202 } 193 }
203 if let Some(c) = ast::Comment::cast(token) { 194 if let Some(c) = ast::Comment::cast(token) {
204 if c.kind() == group_kind { 195 if c.kind() == group_kind {
205 // regions are not really comments 196 // regions are not real comments
206 use regex::Regex; 197 if c.text().trim().starts_with("// region:")
207 lazy_static! { 198 || c.text().trim().starts_with("// endregion")
208 static ref RE_START: Regex = 199 {
209 Regex::new(r"^\s*//\s*#?region\b").unwrap();
210 static ref RE_END: Regex =
211 Regex::new(r"^\s*//\s*#?endregion\b").unwrap();
212 }
213 if RE_START.is_match(c.text()) || RE_END.is_match(c.text()) {
214 break; 200 break;
215 } else { 201 } else {
216 visited.insert(c.clone()); 202 visited.insert(c.clone());