@@ -9,8 +9,6 @@ use syntax::{
9
9
SyntaxNode , TextRange , TextSize ,
10
10
} ;
11
11
12
- use lazy_static:: lazy_static;
13
-
14
12
#[ derive( Debug , PartialEq , Eq ) ]
15
13
pub enum FoldKind {
16
14
Comment ,
@@ -53,17 +51,10 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
53
51
// Fold groups of comments
54
52
if let Some ( comment) = ast:: Comment :: cast ( token) {
55
53
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:" ) {
65
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
58
if !regions_starts. is_empty ( ) {
68
59
res. push ( Fold {
69
60
range : TextRange :: new (
@@ -202,15 +193,10 @@ fn contiguous_range_for_comment(
202
193
}
203
194
if let Some ( c) = ast:: Comment :: cast ( token) {
204
195
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
+ {
214
200
break ;
215
201
} else {
216
202
visited. insert ( c. clone ( ) ) ;
0 commit comments