diff options
Diffstat (limited to 'crates/ra_editor/src/folding_ranges.rs')
-rw-r--r-- | crates/ra_editor/src/folding_ranges.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs index da542ecf0..6f3106889 100644 --- a/crates/ra_editor/src/folding_ranges.rs +++ b/crates/ra_editor/src/folding_ranges.rs | |||
@@ -1,9 +1,8 @@ | |||
1 | use rustc_hash::FxHashSet; | 1 | use rustc_hash::FxHashSet; |
2 | 2 | ||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | ast, AstNode, Direction, SourceFileNode, | 4 | ast, AstNode, Direction, SourceFile, SyntaxNode, TextRange, |
5 | SyntaxKind::{self, *}, | 5 | SyntaxKind::{self, *}, |
6 | SyntaxNodeRef, TextRange, | ||
7 | }; | 6 | }; |
8 | 7 | ||
9 | #[derive(Debug, PartialEq, Eq)] | 8 | #[derive(Debug, PartialEq, Eq)] |
@@ -19,7 +18,7 @@ pub struct Fold { | |||
19 | pub kind: FoldKind, | 18 | pub kind: FoldKind, |
20 | } | 19 | } |
21 | 20 | ||
22 | pub fn folding_ranges(file: &SourceFileNode) -> Vec<Fold> { | 21 | pub fn folding_ranges(file: &SourceFile) -> Vec<Fold> { |
23 | let mut res = vec![]; | 22 | let mut res = vec![]; |
24 | let mut visited_comments = FxHashSet::default(); | 23 | let mut visited_comments = FxHashSet::default(); |
25 | let mut visited_imports = FxHashSet::default(); | 24 | let mut visited_imports = FxHashSet::default(); |
@@ -69,7 +68,7 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> { | |||
69 | } | 68 | } |
70 | } | 69 | } |
71 | 70 | ||
72 | fn has_newline(node: SyntaxNodeRef) -> bool { | 71 | fn has_newline(node: &SyntaxNode) -> bool { |
73 | for descendant in node.descendants() { | 72 | for descendant in node.descendants() { |
74 | if let Some(ws) = ast::Whitespace::cast(descendant) { | 73 | if let Some(ws) = ast::Whitespace::cast(descendant) { |
75 | if ws.has_newlines() { | 74 | if ws.has_newlines() { |
@@ -86,8 +85,8 @@ fn has_newline(node: SyntaxNodeRef) -> bool { | |||
86 | } | 85 | } |
87 | 86 | ||
88 | fn contiguous_range_for_group<'a>( | 87 | fn contiguous_range_for_group<'a>( |
89 | first: SyntaxNodeRef<'a>, | 88 | first: &'a SyntaxNode, |
90 | visited: &mut FxHashSet<SyntaxNodeRef<'a>>, | 89 | visited: &mut FxHashSet<&'a SyntaxNode>, |
91 | ) -> Option<TextRange> { | 90 | ) -> Option<TextRange> { |
92 | visited.insert(first); | 91 | visited.insert(first); |
93 | 92 | ||
@@ -124,8 +123,8 @@ fn contiguous_range_for_group<'a>( | |||
124 | } | 123 | } |
125 | 124 | ||
126 | fn contiguous_range_for_comment<'a>( | 125 | fn contiguous_range_for_comment<'a>( |
127 | first: SyntaxNodeRef<'a>, | 126 | first: &'a SyntaxNode, |
128 | visited: &mut FxHashSet<SyntaxNodeRef<'a>>, | 127 | visited: &mut FxHashSet<&'a SyntaxNode>, |
129 | ) -> Option<TextRange> { | 128 | ) -> Option<TextRange> { |
130 | visited.insert(first); | 129 | visited.insert(first); |
131 | 130 | ||
@@ -174,7 +173,7 @@ mod tests { | |||
174 | 173 | ||
175 | fn do_check(text: &str, fold_kinds: &[FoldKind]) { | 174 | fn do_check(text: &str, fold_kinds: &[FoldKind]) { |
176 | let (ranges, text) = extract_ranges(text, "fold"); | 175 | let (ranges, text) = extract_ranges(text, "fold"); |
177 | let file = SourceFileNode::parse(&text); | 176 | let file = SourceFile::parse(&text); |
178 | let folds = folding_ranges(&file); | 177 | let folds = folding_ranges(&file); |
179 | 178 | ||
180 | assert_eq!( | 179 | assert_eq!( |