Skip to content

Commit 084b21b

Browse files
Luciano BestiaLuciano Bestia
authored andcommitted
simple comparison instead of regex
1 parent 9f1d341 commit 084b21b

File tree

3 files changed

+8
-39
lines changed

3 files changed

+8
-39
lines changed

Cargo.lock

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ide/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,10 @@ assists = { path = "../assists", version = "0.0.0" }
3131
ssr = { path = "../ssr", version = "0.0.0" }
3232
completion = { path = "../completion", version = "0.0.0" }
3333

34-
lazy_static = "1.4.0"
35-
regex = "1.4.3"
36-
env_logger = { version = "0.8.1", default-features = false }
37-
3834
# ide should depend only on the top-level `hir` package. if you need
3935
# something from some `hir_xxx` subpackage, reexport the API via `hir`.
4036
hir = { path = "../hir", version = "0.0.0" }
4137

4238
[dev-dependencies]
4339
expect-test = "1.1"
40+
env_logger = { version = "0.8.1", default-features = false }

crates/ide/src/folding_ranges.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use syntax::{
99
SyntaxNode, TextRange, TextSize,
1010
};
1111

12-
use lazy_static::lazy_static;
13-
1412
#[derive(Debug, PartialEq, Eq)]
1513
pub enum FoldKind {
1614
Comment,
@@ -53,17 +51,10 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
5351
// Fold groups of comments
5452
if let Some(comment) = ast::Comment::cast(token) {
5553
if !visited_comments.contains(&comment) {
56-
// regions are not really comments
57-
use regex::Regex;
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()) {
54+
// regions are not real comments
55+
if comment.text().trim().starts_with("// region:") {
6556
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") {
6758
if !regions_starts.is_empty() {
6859
res.push(Fold {
6960
range: TextRange::new(
@@ -202,15 +193,10 @@ fn contiguous_range_for_comment(
202193
}
203194
if let Some(c) = ast::Comment::cast(token) {
204195
if c.kind() == group_kind {
205-
// regions are not really comments
206-
use regex::Regex;
207-
lazy_static! {
208-
static ref RE_START: Regex =
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()) {
196+
// regions are not real comments
197+
if c.text().trim().starts_with("// region:")
198+
|| c.text().trim().starts_with("// endregion")
199+
{
214200
break;
215201
} else {
216202
visited.insert(c.clone());

0 commit comments

Comments
 (0)