Skip to content

Commit 391be07

Browse files
committed
Folding range for consts
1 parent 2360145 commit 391be07

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

crates/ide/src/folding_ranges.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
3232
let mut visited_comments = FxHashSet::default();
3333
let mut visited_imports = FxHashSet::default();
3434
let mut visited_mods = FxHashSet::default();
35+
let mut visited_consts = FxHashSet::default();
3536
// regions can be nested, here is a LIFO buffer
3637
let mut regions_starts: Vec<TextSize> = vec![];
3738

@@ -93,6 +94,13 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
9394
res.push(Fold { range, kind: FoldKind::Mods })
9495
}
9596
}
97+
98+
// Fold groups of consts
99+
if node.kind() == CONST && !visited_consts.contains(&node) {
100+
if let Some(range) = contiguous_range_for_group(&node, &mut visited_consts) {
101+
res.push(Fold { range, kind: FoldKind::Consts })
102+
}
103+
}
96104
}
97105
}
98106
}

crates/rust-analyzer/src/to_proto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ pub(crate) fn folding_range(
492492
FoldKind::Comment => Some(lsp_types::FoldingRangeKind::Comment),
493493
FoldKind::Imports => Some(lsp_types::FoldingRangeKind::Imports),
494494
FoldKind::Region => Some(lsp_types::FoldingRangeKind::Region),
495-
FoldKind::Mods | FoldKind::Block | FoldKind::ArgList => None,
495+
FoldKind::Mods | FoldKind::Block | FoldKind::ArgList | FoldKind::Consts | FoldKind::Statics => None,
496496
};
497497

498498
let range = range(line_index, fold.range);

0 commit comments

Comments
 (0)