Don't fold consecutive modules with item lists

This commit is contained in:
Lukas Wirth 2021-07-15 16:35:31 +02:00
parent 190f37afab
commit 658514d378

View file

@ -92,14 +92,20 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
}
// Fold groups of mods
if node.kind() == MODULE && !has_visibility(&node) && !visited_mods.contains(&node)
{
if let Some(range) =
contiguous_range_for_group_unless(&node, has_visibility, &mut visited_mods)
if let Some(module) = ast::Module::cast(node.clone()) {
if !has_visibility(&node)
&& !visited_mods.contains(&node)
&& module.item_list().is_none()
{
if let Some(range) = contiguous_range_for_group_unless(
&node,
has_visibility,
&mut visited_mods,
) {
res.push(Fold { range, kind: FoldKind::Mods })
}
}
}
// Fold groups of consts
if node.kind() == CONST && !visited_consts.contains(&node) {
@ -328,7 +334,8 @@ fn main() <fold block>{
//! because it has another flavor</fold>
<fold comment>/* As does this
multiline comment */</fold>
}</fold>"#,
}</fold>
"#,
);
}
@ -341,9 +348,7 @@ use std::<fold block>{
vec,
io as iop
}</fold>;
fn main() <fold block>{
}</fold>"#,
"#,
);
}
@ -368,8 +373,13 @@ pub not_folding_single_next;
mod with_attribute;
mod with_attribute_next;</fold>
fn main() <fold block>{
}</fold>"#,
mod inline0 {}
mod inline1 {}
mod inline2 <fold block>{
}</fold>
"#,
);
}
@ -387,9 +397,7 @@ use std::f64;</fold>
<fold imports>use std::collections::HashMap;
// Some random comment
use std::collections::VecDeque;</fold>
fn main() <fold block>{
}</fold>"#,
"#,
);
}
@ -409,9 +417,7 @@ use std::collections::<fold block>{
VecDeque,
}</fold>;
// Some random comment
fn main() <fold block>{
}</fold>"#,
"#,
);
}