diff options
author | Aleksey Kladov <[email protected]> | 2019-01-26 13:26:30 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-26 13:26:30 +0000 |
commit | bf7a0f43d0e5bd9875f56013edba2e9ce6c40e33 (patch) | |
tree | b3d15335978ae844bb6dbe3c858976824a0d9980 | |
parent | 3feaf2a008be289dc4091f25e0925d0f427d6b65 (diff) |
minor cleanups
-rw-r--r-- | crates/ra_ide_api_light/src/folding_ranges.rs | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/crates/ra_ide_api_light/src/folding_ranges.rs b/crates/ra_ide_api_light/src/folding_ranges.rs index 87feb9bd8..c73637323 100644 --- a/crates/ra_ide_api_light/src/folding_ranges.rs +++ b/crates/ra_ide_api_light/src/folding_ranges.rs | |||
@@ -1,8 +1,9 @@ | |||
1 | use rustc_hash::FxHashSet; | 1 | use rustc_hash::FxHashSet; |
2 | 2 | ||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | ast, AstNode, Direction, SourceFile, SyntaxNode, TextRange, | 4 | AstNode, Direction, SourceFile, SyntaxNode, TextRange, |
5 | SyntaxKind::{self, *}, | 5 | SyntaxKind::{self, *}, |
6 | ast::{self, VisibilityOwner}, | ||
6 | }; | 7 | }; |
7 | 8 | ||
8 | #[derive(Debug, PartialEq, Eq)] | 9 | #[derive(Debug, PartialEq, Eq)] |
@@ -28,7 +29,7 @@ pub fn folding_ranges(file: &SourceFile) -> Vec<Fold> { | |||
28 | for node in file.syntax().descendants() { | 29 | for node in file.syntax().descendants() { |
29 | // Fold items that span multiple lines | 30 | // Fold items that span multiple lines |
30 | if let Some(kind) = fold_kind(node.kind()) { | 31 | if let Some(kind) = fold_kind(node.kind()) { |
31 | if has_newline(node) { | 32 | if node.text().contains('\n') { |
32 | res.push(Fold { | 33 | res.push(Fold { |
33 | range: node.range(), | 34 | range: node.range(), |
34 | kind, | 35 | kind, |
@@ -83,27 +84,9 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> { | |||
83 | } | 84 | } |
84 | 85 | ||
85 | fn has_visibility(node: &SyntaxNode) -> bool { | 86 | fn has_visibility(node: &SyntaxNode) -> bool { |
86 | use ast::VisibilityOwner; | 87 | ast::Module::cast(node) |
87 | |||
88 | return ast::Module::cast(node) | ||
89 | .and_then(|m| m.visibility()) | 88 | .and_then(|m| m.visibility()) |
90 | .is_some(); | 89 | .is_some() |
91 | } | ||
92 | |||
93 | fn has_newline(node: &SyntaxNode) -> bool { | ||
94 | for descendant in node.descendants() { | ||
95 | if let Some(ws) = ast::Whitespace::cast(descendant) { | ||
96 | if ws.has_newlines() { | ||
97 | return true; | ||
98 | } | ||
99 | } else if let Some(comment) = ast::Comment::cast(descendant) { | ||
100 | if comment.has_newlines() { | ||
101 | return true; | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | |||
106 | false | ||
107 | } | 90 | } |
108 | 91 | ||
109 | fn contiguous_range_for_group<'a>( | 92 | fn contiguous_range_for_group<'a>( |