Skip to content

Commit e67cd76

Browse files
bors[bot]Veykril
andauthored
Merge #9604
9604: fix: Don't fold consecutive modules with item lists r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents f0da190 + 658514d commit e67cd76

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

crates/ide/src/folding_ranges.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,18 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
9292
}
9393

9494
// Fold groups of mods
95-
if node.kind() == MODULE && !has_visibility(&node) && !visited_mods.contains(&node)
96-
{
97-
if let Some(range) =
98-
contiguous_range_for_group_unless(&node, has_visibility, &mut visited_mods)
95+
if let Some(module) = ast::Module::cast(node.clone()) {
96+
if !has_visibility(&node)
97+
&& !visited_mods.contains(&node)
98+
&& module.item_list().is_none()
9999
{
100-
res.push(Fold { range, kind: FoldKind::Mods })
100+
if let Some(range) = contiguous_range_for_group_unless(
101+
&node,
102+
has_visibility,
103+
&mut visited_mods,
104+
) {
105+
res.push(Fold { range, kind: FoldKind::Mods })
106+
}
101107
}
102108
}
103109

@@ -328,7 +334,8 @@ fn main() <fold block>{
328334
//! because it has another flavor</fold>
329335
<fold comment>/* As does this
330336
multiline comment */</fold>
331-
}</fold>"#,
337+
}</fold>
338+
"#,
332339
);
333340
}
334341

@@ -341,9 +348,7 @@ use std::<fold block>{
341348
vec,
342349
io as iop
343350
}</fold>;
344-
345-
fn main() <fold block>{
346-
}</fold>"#,
351+
"#,
347352
);
348353
}
349354

@@ -368,8 +373,13 @@ pub not_folding_single_next;
368373
mod with_attribute;
369374
mod with_attribute_next;</fold>
370375
371-
fn main() <fold block>{
372-
}</fold>"#,
376+
mod inline0 {}
377+
mod inline1 {}
378+
379+
mod inline2 <fold block>{
380+
381+
}</fold>
382+
"#,
373383
);
374384
}
375385

@@ -387,9 +397,7 @@ use std::f64;</fold>
387397
<fold imports>use std::collections::HashMap;
388398
// Some random comment
389399
use std::collections::VecDeque;</fold>
390-
391-
fn main() <fold block>{
392-
}</fold>"#,
400+
"#,
393401
);
394402
}
395403

@@ -409,9 +417,7 @@ use std::collections::<fold block>{
409417
VecDeque,
410418
}</fold>;
411419
// Some random comment
412-
413-
fn main() <fold block>{
414-
}</fold>"#,
420+
"#,
415421
);
416422
}
417423

@@ -531,7 +537,7 @@ calling_function(x,y);
531537
r#"
532538
<fold consts>const FIRST_CONST: &str = "first";
533539
const SECOND_CONST: &str = "second";</fold>
534-
"#,
540+
"#,
535541
)
536542
}
537543

@@ -541,7 +547,7 @@ const SECOND_CONST: &str = "second";</fold>
541547
r#"
542548
<fold statics>static FIRST_STATIC: &str = "first";
543549
static SECOND_STATIC: &str = "second";</fold>
544-
"#,
550+
"#,
545551
)
546552
}
547553

@@ -574,7 +580,7 @@ fn foo()<fold returntype>-> (
574580
)</fold> { (true, true) }
575581
576582
fn bar() -> (bool, bool) { (true, true) }
577-
"#,
583+
"#,
578584
)
579585
}
580586
}

0 commit comments

Comments
 (0)