aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_editor')
-rw-r--r--crates/ra_editor/src/folding_ranges.rs38
1 files changed, 19 insertions, 19 deletions
diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs
index 3aabd54ae..1d89ac853 100644
--- a/crates/ra_editor/src/folding_ranges.rs
+++ b/crates/ra_editor/src/folding_ranges.rs
@@ -1,6 +1,8 @@
1use rustc_hash::FxHashSet; 1use rustc_hash::FxHashSet;
2 2
3use ra_syntax::{ 3use ra_syntax::{
4 ast,
5 AstNode,
4 File, TextRange, SyntaxNodeRef, 6 File, TextRange, SyntaxNodeRef,
5 SyntaxKind, 7 SyntaxKind,
6 Direction, 8 Direction,
@@ -27,27 +29,25 @@ pub fn folding_ranges(file: &File) -> Vec<Fold> {
27 continue; 29 continue;
28 } 30 }
29 31
30 let range_and_kind = match node.kind() { 32 if let Some(comment) = ast::Comment::cast(node) {
31 SyntaxKind::COMMENT => ( 33 // Multiline comments (`/* ... */`) can only be folded if they span multiple lines
32 contiguous_range_for(SyntaxKind::COMMENT, node, &mut visited), 34 let range = if let ast::CommentFlavor::Multiline = comment.flavor() {
33 Some(FoldKind::Comment), 35 if comment.text().contains('\n') {
34 ), 36 Some(comment.syntax().range())
35 SyntaxKind::USE_ITEM => ( 37 } else {
36 contiguous_range_for(SyntaxKind::USE_ITEM, node, &mut visited), 38 None
37 Some(FoldKind::Imports), 39 }
38 ), 40 } else {
39 _ => (None, None), 41 contiguous_range_for(SyntaxKind::COMMENT, node, &mut visited)
40 }; 42 };
41 43
42 match range_and_kind { 44 range.map(|range| res.push(Fold { range, kind: FoldKind::Comment }));
43 (Some(range), Some(kind)) => {
44 res.push(Fold {
45 range: range,
46 kind: kind
47 });
48 }
49 _ => {}
50 } 45 }
46
47 if let SyntaxKind::USE_ITEM = node.kind() {
48 contiguous_range_for(SyntaxKind::USE_ITEM, node, &mut visited)
49 .map(|range| res.push(Fold { range, kind: FoldKind::Imports}));
50 };
51 } 51 }
52 52
53 res 53 res