mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
simple comparison instead of regex
This commit is contained in:
parent
9f1d341ee9
commit
084b21bc36
3 changed files with 8 additions and 39 deletions
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"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e"
|
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]]
|
[[package]]
|
||||||
name = "ansi_term"
|
name = "ansi_term"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
|
@ -649,13 +640,11 @@ dependencies = [
|
||||||
"ide_db",
|
"ide_db",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"itertools 0.10.0",
|
"itertools 0.10.0",
|
||||||
"lazy_static",
|
|
||||||
"log",
|
"log",
|
||||||
"oorandom",
|
"oorandom",
|
||||||
"profile",
|
"profile",
|
||||||
"pulldown-cmark",
|
"pulldown-cmark",
|
||||||
"pulldown-cmark-to-cmark",
|
"pulldown-cmark-to-cmark",
|
||||||
"regex",
|
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"ssr",
|
"ssr",
|
||||||
"stdx",
|
"stdx",
|
||||||
|
@ -1317,10 +1306,7 @@ version = "1.4.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a"
|
checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick",
|
|
||||||
"memchr",
|
|
||||||
"regex-syntax",
|
"regex-syntax",
|
||||||
"thread_local",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -31,13 +31,10 @@ assists = { path = "../assists", version = "0.0.0" }
|
||||||
ssr = { path = "../ssr", version = "0.0.0" }
|
ssr = { path = "../ssr", version = "0.0.0" }
|
||||||
completion = { path = "../completion", 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
|
# ide should depend only on the top-level `hir` package. if you need
|
||||||
# something from some `hir_xxx` subpackage, reexport the API via `hir`.
|
# something from some `hir_xxx` subpackage, reexport the API via `hir`.
|
||||||
hir = { path = "../hir", version = "0.0.0" }
|
hir = { path = "../hir", version = "0.0.0" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
expect-test = "1.1"
|
expect-test = "1.1"
|
||||||
|
env_logger = { version = "0.8.1", default-features = false }
|
|
@ -9,8 +9,6 @@ use syntax::{
|
||||||
SyntaxNode, TextRange, TextSize,
|
SyntaxNode, TextRange, TextSize,
|
||||||
};
|
};
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum FoldKind {
|
pub enum FoldKind {
|
||||||
Comment,
|
Comment,
|
||||||
|
@ -53,17 +51,10 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
|
||||||
// Fold groups of comments
|
// Fold groups of comments
|
||||||
if let Some(comment) = ast::Comment::cast(token) {
|
if let Some(comment) = ast::Comment::cast(token) {
|
||||||
if !visited_comments.contains(&comment) {
|
if !visited_comments.contains(&comment) {
|
||||||
// regions are not really comments
|
// regions are not real comments
|
||||||
use regex::Regex;
|
if comment.text().trim().starts_with("// region:") {
|
||||||
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_starts.push(comment.syntax().text_range().start());
|
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() {
|
if !regions_starts.is_empty() {
|
||||||
res.push(Fold {
|
res.push(Fold {
|
||||||
range: TextRange::new(
|
range: TextRange::new(
|
||||||
|
@ -202,15 +193,10 @@ fn contiguous_range_for_comment(
|
||||||
}
|
}
|
||||||
if let Some(c) = ast::Comment::cast(token) {
|
if let Some(c) = ast::Comment::cast(token) {
|
||||||
if c.kind() == group_kind {
|
if c.kind() == group_kind {
|
||||||
// regions are not really comments
|
// regions are not real comments
|
||||||
use regex::Regex;
|
if c.text().trim().starts_with("// region:")
|
||||||
lazy_static! {
|
|| c.text().trim().starts_with("// endregion")
|
||||||
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()) {
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
visited.insert(c.clone());
|
visited.insert(c.clone());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue