From f6702dda9a9527437475e130a01340566ccaf28a Mon Sep 17 00:00:00 2001 From: Ayomide Bamidele Date: Mon, 29 Mar 2021 11:43:03 +0100 Subject: Test cases for folding consts and statics --- crates/ide/src/folding_ranges.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'crates/ide') diff --git a/crates/ide/src/folding_ranges.rs b/crates/ide/src/folding_ranges.rs index 4b1b24562..379ee5650 100644 --- a/crates/ide/src/folding_ranges.rs +++ b/crates/ide/src/folding_ranges.rs @@ -457,4 +457,24 @@ calling_function(x,y); "#, ) } + + #[test] + fn fold_consecutive_const() { + check( + r#" +const FIRST_CONST: &str = "first"; +const SECOND_CONST: &str = "second"; + "#, + ) + } + + #[test] + fn fold_consecutive_static() { + check( + r#" +static FIRST_STATIC: &str = "first"; +static SECOND_STATIC: &str = "second"; + "#, + ) + } } -- cgit v1.2.3 From 23601454fe3467eccdcc6393145bfd0858bd84cb Mon Sep 17 00:00:00 2001 From: Ayomide Bamidele Date: Mon, 29 Mar 2021 11:49:14 +0100 Subject: New FoldKinds - Consts, Statics --- crates/ide/src/folding_ranges.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'crates/ide') diff --git a/crates/ide/src/folding_ranges.rs b/crates/ide/src/folding_ranges.rs index 379ee5650..1dd37483f 100644 --- a/crates/ide/src/folding_ranges.rs +++ b/crates/ide/src/folding_ranges.rs @@ -17,6 +17,8 @@ pub enum FoldKind { Block, ArgList, Region, + Consts, + Statics, } #[derive(Debug)] @@ -250,6 +252,8 @@ mod tests { FoldKind::Block => "block", FoldKind::ArgList => "arglist", FoldKind::Region => "region", + FoldKind::Consts => "consts", + FoldKind::Statics => "statics" }; assert_eq!(kind, &attr.unwrap()); } @@ -472,7 +476,7 @@ const SECOND_CONST: &str = "second"; fn fold_consecutive_static() { check( r#" -static FIRST_STATIC: &str = "first"; +static FIRST_STATIC: &str = "first"; static SECOND_STATIC: &str = "second"; "#, ) -- cgit v1.2.3 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 ++++++++ 1 file changed, 8 insertions(+) (limited to 'crates/ide') 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 }) + } + } } } } -- cgit v1.2.3 From a813062ed206b4382a1694ea6aef019f18733bca Mon Sep 17 00:00:00 2001 From: Ayomide Bamidele Date: Mon, 29 Mar 2021 12:20:26 +0100 Subject: Folding range for statics --- crates/ide/src/folding_ranges.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'crates/ide') diff --git a/crates/ide/src/folding_ranges.rs b/crates/ide/src/folding_ranges.rs index 8f3144de0..8b8a2cc38 100644 --- a/crates/ide/src/folding_ranges.rs +++ b/crates/ide/src/folding_ranges.rs @@ -33,6 +33,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec { let mut visited_imports = FxHashSet::default(); let mut visited_mods = FxHashSet::default(); let mut visited_consts = FxHashSet::default(); + let mut visited_statics = FxHashSet::default(); // regions can be nested, here is a LIFO buffer let mut regions_starts: Vec = vec![]; @@ -101,6 +102,12 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec { res.push(Fold { range, kind: FoldKind::Consts }) } } + // Fold groups of consts + if node.kind() == STATIC && !visited_statics.contains(&node) { + if let Some(range) = contiguous_range_for_group(&node, &mut visited_statics) { + res.push(Fold { range, kind: FoldKind::Statics }) + } + } } } } -- cgit v1.2.3 From 8e11796dc5fcaaeba7b4cc2e0096ed459ec9b899 Mon Sep 17 00:00:00 2001 From: Ayomide Bamidele Date: Mon, 29 Mar 2021 12:56:02 +0100 Subject: formatting fix --- crates/ide/src/folding_ranges.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ide') diff --git a/crates/ide/src/folding_ranges.rs b/crates/ide/src/folding_ranges.rs index 8b8a2cc38..153726ce8 100644 --- a/crates/ide/src/folding_ranges.rs +++ b/crates/ide/src/folding_ranges.rs @@ -268,7 +268,7 @@ mod tests { FoldKind::ArgList => "arglist", FoldKind::Region => "region", FoldKind::Consts => "consts", - FoldKind::Statics => "statics" + FoldKind::Statics => "statics", }; assert_eq!(kind, &attr.unwrap()); } -- cgit v1.2.3