diff options
author | Luciano Bestia <[email protected]> | 2021-02-05 13:32:03 +0000 |
---|---|---|
committer | Luciano Bestia <[email protected]> | 2021-02-05 13:32:03 +0000 |
commit | 084b21bc36cd624e8db708eb1e12dd6db99a0602 (patch) | |
tree | ea3500a01b5412ffb6391bff3d9d81a46c08d476 /crates/ide | |
parent | 9f1d341ee9bf399fa8fa2a5d2fb5f91e1b319702 (diff) |
simple comparison instead of regex
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/Cargo.toml | 5 | ||||
-rw-r--r-- | crates/ide/src/folding_ranges.rs | 28 |
2 files changed, 8 insertions, 25 deletions
diff --git a/crates/ide/Cargo.toml b/crates/ide/Cargo.toml index 6ec106426..15a48c0f3 100644 --- a/crates/ide/Cargo.toml +++ b/crates/ide/Cargo.toml | |||
@@ -31,13 +31,10 @@ assists = { path = "../assists", version = "0.0.0" } | |||
31 | ssr = { path = "../ssr", version = "0.0.0" } | 31 | ssr = { path = "../ssr", version = "0.0.0" } |
32 | completion = { path = "../completion", version = "0.0.0" } | 32 | completion = { path = "../completion", version = "0.0.0" } |
33 | 33 | ||
34 | lazy_static = "1.4.0" | ||
35 | regex = "1.4.3" | ||
36 | env_logger = { version = "0.8.1", default-features = false } | ||
37 | |||
38 | # ide should depend only on the top-level `hir` package. if you need | 34 | # ide should depend only on the top-level `hir` package. if you need |
39 | # something from some `hir_xxx` subpackage, reexport the API via `hir`. | 35 | # something from some `hir_xxx` subpackage, reexport the API via `hir`. |
40 | hir = { path = "../hir", version = "0.0.0" } | 36 | hir = { path = "../hir", version = "0.0.0" } |
41 | 37 | ||
42 | [dev-dependencies] | 38 | [dev-dependencies] |
43 | expect-test = "1.1" | 39 | expect-test = "1.1" |
40 | env_logger = { version = "0.8.1", default-features = false } \ No newline at end of file | ||
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 | ||
12 | use lazy_static::lazy_static; | ||
13 | |||
14 | #[derive(Debug, PartialEq, Eq)] | 12 | #[derive(Debug, PartialEq, Eq)] |
15 | pub enum FoldKind { | 13 | pub 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()); |