aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api_light/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api_light/src')
-rw-r--r--crates/ra_ide_api_light/src/folding_ranges.rs27
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 @@
1use rustc_hash::FxHashSet; 1use rustc_hash::FxHashSet;
2 2
3use ra_syntax::{ 3use 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
85fn has_visibility(node: &SyntaxNode) -> bool { 86fn 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
93fn 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
109fn contiguous_range_for_group<'a>( 92fn contiguous_range_for_group<'a>(