simple comparison instead of regex
This commit is contained in:
parent
9f1d341ee9
commit
084b21bc36
14
Cargo.lock
generated
14
Cargo.lock
generated
@ -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]]
|
||||
|
@ -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 }
|
@ -9,8 +9,6 @@ use syntax::{
|
||||
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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user