aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock14
-rw-r--r--crates/ide/Cargo.toml5
-rw-r--r--crates/ide/src/folding_ranges.rs28
3 files changed, 8 insertions, 39 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 674c75450..30cef4cf8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -16,15 +16,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
16checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" 16checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e"
17 17
18[[package]] 18[[package]]
19name = "aho-corasick"
20version = "0.7.15"
21source = "registry+https://github.com/rust-lang/crates.io-index"
22checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
23dependencies = [
24 "memchr",
25]
26
27[[package]]
28name = "ansi_term" 19name = "ansi_term"
29version = "0.12.1" 20version = "0.12.1"
30source = "registry+https://github.com/rust-lang/crates.io-index" 21source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -649,13 +640,11 @@ dependencies = [
649 "ide_db", 640 "ide_db",
650 "indexmap", 641 "indexmap",
651 "itertools 0.10.0", 642 "itertools 0.10.0",
652 "lazy_static",
653 "log", 643 "log",
654 "oorandom", 644 "oorandom",
655 "profile", 645 "profile",
656 "pulldown-cmark", 646 "pulldown-cmark",
657 "pulldown-cmark-to-cmark", 647 "pulldown-cmark-to-cmark",
658 "regex",
659 "rustc-hash", 648 "rustc-hash",
660 "ssr", 649 "ssr",
661 "stdx", 650 "stdx",
@@ -1317,10 +1306,7 @@ version = "1.4.3"
1317source = "registry+https://github.com/rust-lang/crates.io-index" 1306source = "registry+https://github.com/rust-lang/crates.io-index"
1318checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" 1307checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a"
1319dependencies = [ 1308dependencies = [
1320 "aho-corasick",
1321 "memchr",
1322 "regex-syntax", 1309 "regex-syntax",
1323 "thread_local",
1324] 1310]
1325 1311
1326[[package]] 1312[[package]]
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" }
31ssr = { path = "../ssr", version = "0.0.0" } 31ssr = { path = "../ssr", version = "0.0.0" }
32completion = { path = "../completion", version = "0.0.0" } 32completion = { path = "../completion", version = "0.0.0" }
33 33
34lazy_static = "1.4.0"
35regex = "1.4.3"
36env_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`.
40hir = { path = "../hir", version = "0.0.0" } 36hir = { path = "../hir", version = "0.0.0" }
41 37
42[dev-dependencies] 38[dev-dependencies]
43expect-test = "1.1" 39expect-test = "1.1"
40env_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
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());