From 391be072987bfccf2985a9d09623bbb73d60e3ff Mon Sep 17 00:00:00 2001 From: Ayomide Bamidele Date: Mon, 29 Mar 2021 12:17:19 +0100 Subject: Folding range for consts --- crates/ide/src/folding_ranges.rs | 8 ++++++++ crates/rust-analyzer/src/to_proto.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ide/src/folding_ranges.rs b/crates/ide/src/folding_ranges.rs index 1dd37483f..8f3144de0 100644 --- a/crates/ide/src/folding_ranges.rs +++ b/crates/ide/src/folding_ranges.rs @@ -32,6 +32,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec { 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 = vec![]; @@ -93,6 +94,13 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec { 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 }) + } + } } } } diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 530c8a5a4..a3799880f 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -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); -- cgit v1.2.3