diff options
author | Adolfo OchagavĂa <[email protected]> | 2018-10-12 07:59:12 +0100 |
---|---|---|
committer | Adolfo OchagavĂa <[email protected]> | 2018-10-12 07:59:12 +0100 |
commit | ee0a6bf0535a5a6c7e536d2cffa11959c3ee2ae3 (patch) | |
tree | 51ae5f73f3069769cf8d87f5d3d3e500408930fd /crates/ra_editor | |
parent | 2ba6f18586d02a6dbc32e0bea88f7b4236277ea1 (diff) |
Fold multiline comments
Diffstat (limited to 'crates/ra_editor')
-rw-r--r-- | crates/ra_editor/src/folding_ranges.rs | 38 |
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 @@ | |||
1 | use rustc_hash::FxHashSet; | 1 | use rustc_hash::FxHashSet; |
2 | 2 | ||
3 | use ra_syntax::{ | 3 | use 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 |