aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_editor/src')
-rw-r--r--crates/ra_editor/src/code_actions.rs5
-rw-r--r--crates/ra_editor/src/completion.rs13
-rw-r--r--crates/ra_editor/src/extend_selection.rs4
-rw-r--r--crates/ra_editor/src/folding_ranges.rs8
-rw-r--r--crates/ra_editor/src/lib.rs10
-rw-r--r--crates/ra_editor/src/scope/fn_scope.rs6
-rw-r--r--crates/ra_editor/src/symbols.rs4
-rw-r--r--crates/ra_editor/src/typing.rs3
8 files changed, 24 insertions, 29 deletions
diff --git a/crates/ra_editor/src/code_actions.rs b/crates/ra_editor/src/code_actions.rs
index 83f7956d2..b0f0d8f1d 100644
--- a/crates/ra_editor/src/code_actions.rs
+++ b/crates/ra_editor/src/code_actions.rs
@@ -9,7 +9,6 @@ use ra_syntax::{
9 Direction, siblings, 9 Direction, siblings,
10 find_leaf_at_offset, 10 find_leaf_at_offset,
11 find_covering_node, 11 find_covering_node,
12 ancestors,
13 }, 12 },
14}; 13};
15 14
@@ -101,8 +100,8 @@ pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() ->
101 100
102pub fn introduce_variable<'a>(file: &'a File, range: TextRange) -> Option<impl FnOnce() -> LocalEdit + 'a> { 101pub fn introduce_variable<'a>(file: &'a File, range: TextRange) -> Option<impl FnOnce() -> LocalEdit + 'a> {
103 let node = find_covering_node(file.syntax(), range); 102 let node = find_covering_node(file.syntax(), range);
104 let expr = ancestors(node).filter_map(ast::Expr::cast).next()?; 103 let expr = node.ancestors().filter_map(ast::Expr::cast).next()?;
105 let anchor_stmt = ancestors(expr.syntax()).filter_map(ast::Stmt::cast).next()?; 104 let anchor_stmt = expr.syntax().ancestors().filter_map(ast::Stmt::cast).next()?;
106 let indent = anchor_stmt.syntax().prev_sibling()?; 105 let indent = anchor_stmt.syntax().prev_sibling()?;
107 if indent.kind() != WHITESPACE { 106 if indent.kind() != WHITESPACE {
108 return None; 107 return None;
diff --git a/crates/ra_editor/src/completion.rs b/crates/ra_editor/src/completion.rs
index ff9de20d3..62a63fb04 100644
--- a/crates/ra_editor/src/completion.rs
+++ b/crates/ra_editor/src/completion.rs
@@ -4,7 +4,6 @@ use ra_syntax::{
4 File, TextUnit, AstNode, SyntaxNodeRef, SyntaxKind::*, 4 File, TextUnit, AstNode, SyntaxNodeRef, SyntaxKind::*,
5 ast::{self, LoopBodyOwner, ModuleItemOwner}, 5 ast::{self, LoopBodyOwner, ModuleItemOwner},
6 algo::{ 6 algo::{
7 ancestors,
8 visit::{visitor, Visitor, visitor_ctx, VisitorCtx}, 7 visit::{visitor, Visitor, visitor_ctx, VisitorCtx},
9 }, 8 },
10 text_utils::is_subrange, 9 text_utils::is_subrange,
@@ -59,7 +58,7 @@ fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec<Completi
59 return; 58 return;
60 } 59 }
61 let mut visited_fn = false; 60 let mut visited_fn = false;
62 for node in ancestors(name_ref.syntax()) { 61 for node in name_ref.syntax().ancestors() {
63 if let Some(items) = visitor() 62 if let Some(items) = visitor()
64 .visit::<ast::Root, _>(|it| Some(it.items())) 63 .visit::<ast::Root, _>(|it| Some(it.items()))
65 .visit::<ast::Module, _>(|it| Some(it.item_list()?.items())) 64 .visit::<ast::Module, _>(|it| Some(it.item_list()?.items()))
@@ -92,7 +91,7 @@ fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec<Completi
92 91
93fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) { 92fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) {
94 let mut params = HashMap::new(); 93 let mut params = HashMap::new();
95 for node in ancestors(ctx) { 94 for node in ctx.ancestors() {
96 let _ = visitor_ctx(&mut params) 95 let _ = visitor_ctx(&mut params)
97 .visit::<ast::Root, _>(process) 96 .visit::<ast::Root, _>(process)
98 .visit::<ast::ItemList, _>(process) 97 .visit::<ast::ItemList, _>(process)
@@ -123,7 +122,7 @@ fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) {
123} 122}
124 123
125fn is_node<'a, N: AstNode<'a>>(node: SyntaxNodeRef<'a>) -> bool { 124fn is_node<'a, N: AstNode<'a>>(node: SyntaxNodeRef<'a>) -> bool {
126 match ancestors(node).filter_map(N::cast).next() { 125 match node.ancestors().filter_map(N::cast).next() {
127 None => false, 126 None => false,
128 Some(n) => n.syntax().range() == node.range(), 127 Some(n) => n.syntax().range() == node.range(),
129 } 128 }
@@ -152,7 +151,7 @@ fn complete_expr_keywords(file: &File, fn_def: ast::FnDef, name_ref: ast::NameRe
152} 151}
153 152
154fn is_in_loop_body(name_ref: ast::NameRef) -> bool { 153fn is_in_loop_body(name_ref: ast::NameRef) -> bool {
155 for node in ancestors(name_ref.syntax()) { 154 for node in name_ref.syntax().ancestors() {
156 if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { 155 if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR {
157 break; 156 break;
158 } 157 }
@@ -171,7 +170,7 @@ fn is_in_loop_body(name_ref: ast::NameRef) -> bool {
171} 170}
172 171
173fn complete_return(fn_def: ast::FnDef, name_ref: ast::NameRef) -> Option<CompletionItem> { 172fn complete_return(fn_def: ast::FnDef, name_ref: ast::NameRef) -> Option<CompletionItem> {
174 // let is_last_in_block = ancestors(name_ref.syntax()).filter_map(ast::Expr::cast) 173 // let is_last_in_block = name_ref.syntax().ancestors().filter_map(ast::Expr::cast)
175 // .next() 174 // .next()
176 // .and_then(|it| it.syntax().parent()) 175 // .and_then(|it| it.syntax().parent())
177 // .and_then(ast::Block::cast) 176 // .and_then(ast::Block::cast)
@@ -181,7 +180,7 @@ fn complete_return(fn_def: ast::FnDef, name_ref: ast::NameRef) -> Option<Complet
181 // return None; 180 // return None;
182 // } 181 // }
183 182
184 let is_stmt = match ancestors(name_ref.syntax()).filter_map(ast::ExprStmt::cast).next() { 183 let is_stmt = match name_ref.syntax().ancestors().filter_map(ast::ExprStmt::cast).next() {
185 None => false, 184 None => false,
186 Some(expr_stmt) => expr_stmt.syntax().range() == name_ref.syntax().range() 185 Some(expr_stmt) => expr_stmt.syntax().range() == name_ref.syntax().range()
187 }; 186 };
diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs
index dc914a26a..2f8a04b2b 100644
--- a/crates/ra_editor/src/extend_selection.rs
+++ b/crates/ra_editor/src/extend_selection.rs
@@ -1,7 +1,7 @@
1use ra_syntax::{ 1use ra_syntax::{
2 File, TextRange, SyntaxNodeRef, TextUnit, 2 File, TextRange, SyntaxNodeRef, TextUnit,
3 SyntaxKind::*, 3 SyntaxKind::*,
4 algo::{find_leaf_at_offset, LeafAtOffset, find_covering_node, ancestors, Direction, siblings}, 4 algo::{find_leaf_at_offset, LeafAtOffset, find_covering_node, Direction, siblings},
5}; 5};
6 6
7pub fn extend_selection(file: &File, range: TextRange) -> Option<TextRange> { 7pub fn extend_selection(file: &File, range: TextRange) -> Option<TextRange> {
@@ -30,7 +30,7 @@ pub(crate) fn extend(root: SyntaxNodeRef, range: TextRange) -> Option<TextRange>
30 } 30 }
31 } 31 }
32 32
33 match ancestors(node).skip_while(|n| n.range() == range).next() { 33 match node.ancestors().skip_while(|n| n.range() == range).next() {
34 None => None, 34 None => None,
35 Some(parent) => Some(parent.range()), 35 Some(parent) => Some(parent.range()),
36 } 36 }
diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs
index 817da28d1..892aaf97b 100644
--- a/crates/ra_editor/src/folding_ranges.rs
+++ b/crates/ra_editor/src/folding_ranges.rs
@@ -3,7 +3,7 @@ use std::collections::HashSet;
3use ra_syntax::{ 3use ra_syntax::{
4 File, TextRange, SyntaxNodeRef, 4 File, TextRange, SyntaxNodeRef,
5 SyntaxKind, 5 SyntaxKind,
6 algo::{walk, Direction, siblings}, 6 algo::{Direction, siblings},
7}; 7};
8 8
9#[derive(Debug, PartialEq, Eq)] 9#[derive(Debug, PartialEq, Eq)]
@@ -19,12 +19,10 @@ pub struct Fold {
19} 19}
20 20
21pub fn folding_ranges(file: &File) -> Vec<Fold> { 21pub fn folding_ranges(file: &File) -> Vec<Fold> {
22 let syntax = file.syntax();
23
24 let mut res = vec![]; 22 let mut res = vec![];
25 let mut visited = HashSet::new(); 23 let mut visited = HashSet::new();
26 24
27 for node in walk::preorder(syntax) { 25 for node in file.syntax().descendants() {
28 if visited.contains(&node) { 26 if visited.contains(&node) {
29 continue; 27 continue;
30 } 28 }
@@ -139,4 +137,4 @@ fn main() {
139 } 137 }
140 138
141 139
142} \ No newline at end of file 140}
diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs
index de929d73a..a93924e00 100644
--- a/crates/ra_editor/src/lib.rs
+++ b/crates/ra_editor/src/lib.rs
@@ -21,7 +21,7 @@ mod test_utils;
21use ra_syntax::{ 21use ra_syntax::{
22 File, TextUnit, TextRange, SyntaxNodeRef, 22 File, TextUnit, TextRange, SyntaxNodeRef,
23 ast::{self, AstNode, NameOwner}, 23 ast::{self, AstNode, NameOwner},
24 algo::{walk, find_leaf_at_offset, ancestors}, 24 algo::find_leaf_at_offset,
25 SyntaxKind::{self, *}, 25 SyntaxKind::{self, *},
26}; 26};
27pub use ra_syntax::AtomEdit; 27pub use ra_syntax::AtomEdit;
@@ -86,7 +86,7 @@ pub fn matching_brace(file: &File, offset: TextUnit) -> Option<TextUnit> {
86 86
87pub fn highlight(file: &File) -> Vec<HighlightedRange> { 87pub fn highlight(file: &File) -> Vec<HighlightedRange> {
88 let mut res = Vec::new(); 88 let mut res = Vec::new();
89 for node in walk::preorder(file.syntax()) { 89 for node in file.syntax().descendants() {
90 let tag = match node.kind() { 90 let tag = match node.kind() {
91 ERROR => "error", 91 ERROR => "error",
92 COMMENT | DOC_COMMENT => "comment", 92 COMMENT | DOC_COMMENT => "comment",
@@ -110,7 +110,7 @@ pub fn highlight(file: &File) -> Vec<HighlightedRange> {
110pub fn diagnostics(file: &File) -> Vec<Diagnostic> { 110pub fn diagnostics(file: &File) -> Vec<Diagnostic> {
111 let mut res = Vec::new(); 111 let mut res = Vec::new();
112 112
113 for node in walk::preorder(file.syntax()) { 113 for node in file.syntax().descendants() {
114 if node.kind() == ERROR { 114 if node.kind() == ERROR {
115 res.push(Diagnostic { 115 res.push(Diagnostic {
116 range: node.range(), 116 range: node.range(),
@@ -130,7 +130,7 @@ pub fn syntax_tree(file: &File) -> String {
130} 130}
131 131
132pub fn runnables(file: &File) -> Vec<Runnable> { 132pub fn runnables(file: &File) -> Vec<Runnable> {
133 walk::preorder(file.syntax()) 133 file.syntax().descendants()
134 .filter_map(ast::FnDef::cast) 134 .filter_map(ast::FnDef::cast)
135 .filter_map(|f| { 135 .filter_map(|f| {
136 let name = f.name()?.text(); 136 let name = f.name()?.text();
@@ -159,7 +159,7 @@ pub fn find_node_at_offset<'a, N: AstNode<'a>>(
159 let leaf = leaves.clone() 159 let leaf = leaves.clone()
160 .find(|leaf| !leaf.kind().is_trivia()) 160 .find(|leaf| !leaf.kind().is_trivia())
161 .or_else(|| leaves.right_biased())?; 161 .or_else(|| leaves.right_biased())?;
162 ancestors(leaf) 162 leaf.ancestors()
163 .filter_map(N::cast) 163 .filter_map(N::cast)
164 .next() 164 .next()
165} 165}
diff --git a/crates/ra_editor/src/scope/fn_scope.rs b/crates/ra_editor/src/scope/fn_scope.rs
index 3ae5276a2..eddd87495 100644
--- a/crates/ra_editor/src/scope/fn_scope.rs
+++ b/crates/ra_editor/src/scope/fn_scope.rs
@@ -6,7 +6,7 @@ use std::{
6use ra_syntax::{ 6use ra_syntax::{
7 SyntaxNodeRef, SyntaxNode, SmolStr, AstNode, 7 SyntaxNodeRef, SyntaxNode, SmolStr, AstNode,
8 ast::{self, NameOwner, LoopBodyOwner, ArgListOwner}, 8 ast::{self, NameOwner, LoopBodyOwner, ArgListOwner},
9 algo::{ancestors, generate, walk::preorder} 9 algo::{generate}
10}; 10};
11 11
12type ScopeId = usize; 12type ScopeId = usize;
@@ -51,7 +51,7 @@ impl FnScopes {
51 res 51 res
52 } 52 }
53 fn add_bindings(&mut self, scope: ScopeId, pat: ast::Pat) { 53 fn add_bindings(&mut self, scope: ScopeId, pat: ast::Pat) {
54 let entries = preorder(pat.syntax()) 54 let entries = pat.syntax().descendants()
55 .filter_map(ast::BindPat::cast) 55 .filter_map(ast::BindPat::cast)
56 .filter_map(ScopeEntry::new); 56 .filter_map(ScopeEntry::new);
57 self.scopes[scope].entries.extend(entries); 57 self.scopes[scope].entries.extend(entries);
@@ -66,7 +66,7 @@ impl FnScopes {
66 self.scope_for.insert(node.owned(), scope); 66 self.scope_for.insert(node.owned(), scope);
67 } 67 }
68 fn scope_for(&self, node: SyntaxNodeRef) -> Option<ScopeId> { 68 fn scope_for(&self, node: SyntaxNodeRef) -> Option<ScopeId> {
69 ancestors(node) 69 node.ancestors()
70 .filter_map(|it| self.scope_for.get(&it.owned()).map(|&scope| scope)) 70 .filter_map(|it| self.scope_for.get(&it.owned()).map(|&scope| scope))
71 .next() 71 .next()
72 } 72 }
diff --git a/crates/ra_editor/src/symbols.rs b/crates/ra_editor/src/symbols.rs
index 917984177..e5cc5ca28 100644
--- a/crates/ra_editor/src/symbols.rs
+++ b/crates/ra_editor/src/symbols.rs
@@ -3,7 +3,7 @@ use ra_syntax::{
3 ast::{self, NameOwner}, 3 ast::{self, NameOwner},
4 algo::{ 4 algo::{
5 visit::{visitor, Visitor}, 5 visit::{visitor, Visitor},
6 walk::{walk, WalkEvent, preorder}, 6 walk::{walk, WalkEvent},
7 }, 7 },
8}; 8};
9use TextRange; 9use TextRange;
@@ -25,7 +25,7 @@ pub struct FileSymbol {
25} 25}
26 26
27pub fn file_symbols(file: &File) -> Vec<FileSymbol> { 27pub fn file_symbols(file: &File) -> Vec<FileSymbol> {
28 preorder(file.syntax()) 28 file.syntax().descendants()
29 .filter_map(to_symbol) 29 .filter_map(to_symbol)
30 .collect() 30 .collect()
31} 31}
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs
index 0f4e7e0d0..512076941 100644
--- a/crates/ra_editor/src/typing.rs
+++ b/crates/ra_editor/src/typing.rs
@@ -4,7 +4,6 @@ use ra_syntax::{
4 TextUnit, TextRange, SyntaxNodeRef, File, AstNode, SyntaxKind, 4 TextUnit, TextRange, SyntaxNodeRef, File, AstNode, SyntaxKind,
5 ast, 5 ast,
6 algo::{ 6 algo::{
7 walk::preorder,
8 find_covering_node, 7 find_covering_node,
9 }, 8 },
10 text_utils::{intersect, contains_offset_nonstrict}, 9 text_utils::{intersect, contains_offset_nonstrict},
@@ -33,7 +32,7 @@ pub fn join_lines(file: &File, range: TextRange) -> LocalEdit {
33 }; 32 };
34 let node = find_covering_node(file.syntax(), range); 33 let node = find_covering_node(file.syntax(), range);
35 let mut edit = EditBuilder::new(); 34 let mut edit = EditBuilder::new();
36 for node in preorder(node) { 35 for node in node.descendants() {
37 let text = match node.leaf_text() { 36 let text = match node.leaf_text() {
38 Some(text) => text, 37 Some(text) => text,
39 None => continue, 38 None => continue,