From 4b555ab1d99a8f6cacf4987fe85e1c8b5dee7262 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 8 Apr 2021 00:05:08 +0200 Subject: [PATCH] Emit folding ranges for multiline array literals --- crates/ide/src/folding_ranges.rs | 17 +++++++++++++++++ crates/rust-analyzer/src/to_proto.rs | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/ide/src/folding_ranges.rs b/crates/ide/src/folding_ranges.rs index 153726ce8b1..2b9ed123c11 100644 --- a/crates/ide/src/folding_ranges.rs +++ b/crates/ide/src/folding_ranges.rs @@ -19,6 +19,7 @@ pub enum FoldKind { Region, Consts, Statics, + Array, } #[derive(Debug)] @@ -119,6 +120,7 @@ fn fold_kind(kind: SyntaxKind) -> Option { match kind { COMMENT => Some(FoldKind::Comment), ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList), + ARRAY_EXPR => Some(FoldKind::Array), ASSOC_ITEM_LIST | RECORD_FIELD_LIST | RECORD_PAT_FIELD_LIST @@ -269,6 +271,7 @@ mod tests { FoldKind::Region => "region", FoldKind::Consts => "consts", FoldKind::Statics => "statics", + FoldKind::Array => "array", }; assert_eq!(kind, &attr.unwrap()); } @@ -464,6 +467,20 @@ fn foo( ) } + #[test] + fn fold_multiline_array() { + check( + r#" +const FOO: [usize; 4] = [ + 1, + 2, + 3, + 4, +]; +"#, + ) + } + #[test] fn fold_region() { check( diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index c3820944bcb..2ac31d981b9 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -497,7 +497,8 @@ pub(crate) fn folding_range( | FoldKind::Block | FoldKind::ArgList | FoldKind::Consts - | FoldKind::Statics => None, + | FoldKind::Statics + | FoldKind::Array => None, }; let range = range(line_index, fold.range);