]> git.lizzy.rs Git - rust.git/commitdiff
simple comparison instead of regex
authorLuciano Bestia <LucianoBestia@gmail.com>
Fri, 5 Feb 2021 13:32:03 +0000 (14:32 +0100)
committerLuciano Bestia <LucianoBestia@gmail.com>
Fri, 5 Feb 2021 13:32:03 +0000 (14:32 +0100)
Cargo.lock
crates/ide/Cargo.toml
crates/ide/src/folding_ranges.rs

index 674c75450b8d21108b194cdcfc02bd1872434814..30cef4cf81d8f746fad10ae6079a08f113d6a51c 100644 (file)
@@ -15,15 +15,6 @@ version = "0.2.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e"
 
-[[package]]
-name = "aho-corasick"
-version = "0.7.15"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
-dependencies = [
- "memchr",
-]
-
 [[package]]
 name = "ansi_term"
 version = "0.12.1"
@@ -649,13 +640,11 @@ dependencies = [
  "ide_db",
  "indexmap",
  "itertools 0.10.0",
- "lazy_static",
  "log",
  "oorandom",
  "profile",
  "pulldown-cmark",
  "pulldown-cmark-to-cmark",
- "regex",
  "rustc-hash",
  "ssr",
  "stdx",
@@ -1317,10 +1306,7 @@ version = "1.4.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a"
 dependencies = [
- "aho-corasick",
- "memchr",
  "regex-syntax",
- "thread_local",
 ]
 
 [[package]]
index 6ec1064267e308eab020dc90e0fc992cb7eeb3d2..15a48c0f37b4ecb60bcb1b50f3e80533b287ca60 100644 (file)
@@ -31,13 +31,10 @@ assists = { path = "../assists", version = "0.0.0" }
 ssr = { path = "../ssr", version = "0.0.0" }
 completion = { path = "../completion", version = "0.0.0" }
 
-lazy_static = "1.4.0"
-regex = "1.4.3"
-env_logger = { version = "0.8.1", default-features = false }
-
 # ide should depend only on the top-level `hir` package. if you need
 # something from some `hir_xxx` subpackage, reexport the API via `hir`.
 hir = { path = "../hir", version = "0.0.0" }
 
 [dev-dependencies]
 expect-test = "1.1"
+env_logger = { version = "0.8.1", default-features = false }
\ No newline at end of file
index 99f0c3c99af7397c691a75370a4f9312741ff9c0..7ba775a771c6144bfc83c6e589fa204e304c6d85 100644 (file)
@@ -9,8 +9,6 @@
     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> {
                 // 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());