Folding range for consts

This commit is contained in:
Ayomide Bamidele 2021-03-29 12:17:19 +01:00
parent 23601454fe
commit 391be07298
2 changed files with 9 additions and 1 deletions

View File

@ -32,6 +32,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
let mut visited_comments = FxHashSet::default();
let mut visited_imports = FxHashSet::default();
let mut visited_mods = FxHashSet::default();
let mut visited_consts = FxHashSet::default();
// regions can be nested, here is a LIFO buffer
let mut regions_starts: Vec<TextSize> = vec![];
@ -93,6 +94,13 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
res.push(Fold { range, kind: FoldKind::Mods })
}
}
// Fold groups of consts
if node.kind() == CONST && !visited_consts.contains(&node) {
if let Some(range) = contiguous_range_for_group(&node, &mut visited_consts) {
res.push(Fold { range, kind: FoldKind::Consts })
}
}
}
}
}

View File

@ -492,7 +492,7 @@ pub(crate) fn folding_range(
FoldKind::Comment => Some(lsp_types::FoldingRangeKind::Comment),
FoldKind::Imports => Some(lsp_types::FoldingRangeKind::Imports),
FoldKind::Region => Some(lsp_types::FoldingRangeKind::Region),
FoldKind::Mods | FoldKind::Block | FoldKind::ArgList => None,
FoldKind::Mods | FoldKind::Block | FoldKind::ArgList | FoldKind::Consts | FoldKind::Statics => None,
};
let range = range(line_index, fold.range);