diff options
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/completion/complete_fn_param.rs | 6 | ||||
-rw-r--r-- | crates/ra_analysis/src/completion/complete_keyword.rs | 6 | ||||
-rw-r--r-- | crates/ra_analysis/src/completion/completion_context.rs | 29 | ||||
-rw-r--r-- | crates/ra_analysis/src/extend_selection.rs | 8 | ||||
-rw-r--r-- | crates/ra_analysis/src/goto_defenition.rs | 4 | ||||
-rw-r--r-- | crates/ra_analysis/src/hover.rs | 30 | ||||
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 28 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_analysis/src/runnables.rs | 12 | ||||
-rw-r--r-- | crates/ra_analysis/src/symbol_index.rs | 8 | ||||
-rw-r--r-- | crates/ra_analysis/src/syntax_highlighting.rs | 2 |
11 files changed, 65 insertions, 76 deletions
diff --git a/crates/ra_analysis/src/completion/complete_fn_param.rs b/crates/ra_analysis/src/completion/complete_fn_param.rs index bb5fdfda0..c1739e47e 100644 --- a/crates/ra_analysis/src/completion/complete_fn_param.rs +++ b/crates/ra_analysis/src/completion/complete_fn_param.rs | |||
@@ -39,9 +39,9 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) | |||
39 | .add_to(acc) | 39 | .add_to(acc) |
40 | }); | 40 | }); |
41 | 41 | ||
42 | fn process<'a, N: ast::FnDefOwner<'a>>( | 42 | fn process<'a, N: ast::FnDefOwner>( |
43 | node: N, | 43 | node: &'a N, |
44 | params: &mut FxHashMap<String, (u32, ast::Param<'a>)>, | 44 | params: &mut FxHashMap<String, (u32, &'a ast::Param)>, |
45 | ) { | 45 | ) { |
46 | node.functions() | 46 | node.functions() |
47 | .filter_map(|it| it.param_list()) | 47 | .filter_map(|it| it.param_list()) |
diff --git a/crates/ra_analysis/src/completion/complete_keyword.rs b/crates/ra_analysis/src/completion/complete_keyword.rs index 28194c908..d350f06ce 100644 --- a/crates/ra_analysis/src/completion/complete_keyword.rs +++ b/crates/ra_analysis/src/completion/complete_keyword.rs | |||
@@ -2,7 +2,7 @@ use ra_syntax::{ | |||
2 | algo::visit::{visitor, Visitor}, | 2 | algo::visit::{visitor, Visitor}, |
3 | AstNode, | 3 | AstNode, |
4 | ast::{self, LoopBodyOwner}, | 4 | ast::{self, LoopBodyOwner}, |
5 | SyntaxKind::*, SyntaxNodeRef, | 5 | SyntaxKind::*, SyntaxNode, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind}; | 8 | use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind}; |
@@ -76,7 +76,7 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte | |||
76 | acc.add_all(complete_return(fn_def, ctx.can_be_stmt)); | 76 | acc.add_all(complete_return(fn_def, ctx.can_be_stmt)); |
77 | } | 77 | } |
78 | 78 | ||
79 | fn is_in_loop_body(leaf: SyntaxNodeRef) -> bool { | 79 | fn is_in_loop_body(leaf: &SyntaxNode) -> bool { |
80 | for node in leaf.ancestors() { | 80 | for node in leaf.ancestors() { |
81 | if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { | 81 | if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { |
82 | break; | 82 | break; |
@@ -95,7 +95,7 @@ fn is_in_loop_body(leaf: SyntaxNodeRef) -> bool { | |||
95 | false | 95 | false |
96 | } | 96 | } |
97 | 97 | ||
98 | fn complete_return(fn_def: ast::FnDef, can_be_stmt: bool) -> Option<CompletionItem> { | 98 | fn complete_return(fn_def: &ast::FnDef, can_be_stmt: bool) -> Option<CompletionItem> { |
99 | let snip = match (can_be_stmt, fn_def.ret_type().is_some()) { | 99 | let snip = match (can_be_stmt, fn_def.ret_type().is_some()) { |
100 | (true, true) => "return $0;", | 100 | (true, true) => "return $0;", |
101 | (true, false) => "return;", | 101 | (true, false) => "return;", |
diff --git a/crates/ra_analysis/src/completion/completion_context.rs b/crates/ra_analysis/src/completion/completion_context.rs index 4584f355d..988c21c58 100644 --- a/crates/ra_analysis/src/completion/completion_context.rs +++ b/crates/ra_analysis/src/completion/completion_context.rs | |||
@@ -1,13 +1,9 @@ | |||
1 | use ra_editor::find_node_at_offset; | 1 | use ra_editor::find_node_at_offset; |
2 | use ra_text_edit::AtomTextEdit; | 2 | use ra_text_edit::AtomTextEdit; |
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | algo::{find_leaf_at_offset, find_covering_node}, | 4 | AstNode, SyntaxNode, SourceFile, TextUnit, TextRange, |
5 | ast, | 5 | ast, |
6 | AstNode, | 6 | algo::{find_leaf_at_offset, find_covering_node}, |
7 | SyntaxNodeRef, | ||
8 | SourceFileNode, | ||
9 | TextUnit, | ||
10 | TextRange, | ||
11 | SyntaxKind::*, | 7 | SyntaxKind::*, |
12 | }; | 8 | }; |
13 | use hir::source_binder; | 9 | use hir::source_binder; |
@@ -20,11 +16,11 @@ use crate::{db, FilePosition, Cancelable}; | |||
20 | pub(super) struct CompletionContext<'a> { | 16 | pub(super) struct CompletionContext<'a> { |
21 | pub(super) db: &'a db::RootDatabase, | 17 | pub(super) db: &'a db::RootDatabase, |
22 | pub(super) offset: TextUnit, | 18 | pub(super) offset: TextUnit, |
23 | pub(super) leaf: SyntaxNodeRef<'a>, | 19 | pub(super) leaf: &'a SyntaxNode, |
24 | pub(super) module: Option<hir::Module>, | 20 | pub(super) module: Option<hir::Module>, |
25 | pub(super) function: Option<hir::Function>, | 21 | pub(super) function: Option<hir::Function>, |
26 | pub(super) function_syntax: Option<ast::FnDef<'a>>, | 22 | pub(super) function_syntax: Option<&'a ast::FnDef>, |
27 | pub(super) use_item_syntax: Option<ast::UseItem<'a>>, | 23 | pub(super) use_item_syntax: Option<&'a ast::UseItem>, |
28 | pub(super) is_param: bool, | 24 | pub(super) is_param: bool, |
29 | /// A single-indent path, like `foo`. | 25 | /// A single-indent path, like `foo`. |
30 | pub(super) is_trivial_path: bool, | 26 | pub(super) is_trivial_path: bool, |
@@ -36,7 +32,7 @@ pub(super) struct CompletionContext<'a> { | |||
36 | /// Something is typed at the "top" level, in module or impl/trait. | 32 | /// Something is typed at the "top" level, in module or impl/trait. |
37 | pub(super) is_new_item: bool, | 33 | pub(super) is_new_item: bool, |
38 | /// The receiver if this is a field or method access, i.e. writing something.<|> | 34 | /// The receiver if this is a field or method access, i.e. writing something.<|> |
39 | pub(super) dot_receiver: Option<ast::Expr<'a>>, | 35 | pub(super) dot_receiver: Option<&'a ast::Expr>, |
40 | /// If this is a method call in particular, i.e. the () are already there. | 36 | /// If this is a method call in particular, i.e. the () are already there. |
41 | pub(super) is_method_call: bool, | 37 | pub(super) is_method_call: bool, |
42 | } | 38 | } |
@@ -44,7 +40,7 @@ pub(super) struct CompletionContext<'a> { | |||
44 | impl<'a> CompletionContext<'a> { | 40 | impl<'a> CompletionContext<'a> { |
45 | pub(super) fn new( | 41 | pub(super) fn new( |
46 | db: &'a db::RootDatabase, | 42 | db: &'a db::RootDatabase, |
47 | original_file: &'a SourceFileNode, | 43 | original_file: &'a SourceFile, |
48 | position: FilePosition, | 44 | position: FilePosition, |
49 | ) -> Cancelable<Option<CompletionContext<'a>>> { | 45 | ) -> Cancelable<Option<CompletionContext<'a>>> { |
50 | let module = source_binder::module_from_position(db, position)?; | 46 | let module = source_binder::module_from_position(db, position)?; |
@@ -71,7 +67,7 @@ impl<'a> CompletionContext<'a> { | |||
71 | Ok(Some(ctx)) | 67 | Ok(Some(ctx)) |
72 | } | 68 | } |
73 | 69 | ||
74 | fn fill(&mut self, original_file: &'a SourceFileNode, offset: TextUnit) { | 70 | fn fill(&mut self, original_file: &'a SourceFile, offset: TextUnit) { |
75 | // Insert a fake ident to get a valid parse tree. We will use this file | 71 | // Insert a fake ident to get a valid parse tree. We will use this file |
76 | // to determine context, though the original_file will be used for | 72 | // to determine context, though the original_file will be used for |
77 | // actual completion. | 73 | // actual completion. |
@@ -100,7 +96,7 @@ impl<'a> CompletionContext<'a> { | |||
100 | } | 96 | } |
101 | } | 97 | } |
102 | } | 98 | } |
103 | fn classify_name_ref(&mut self, original_file: &'a SourceFileNode, name_ref: ast::NameRef) { | 99 | fn classify_name_ref(&mut self, original_file: &'a SourceFile, name_ref: &ast::NameRef) { |
104 | let name_range = name_ref.syntax().range(); | 100 | let name_range = name_ref.syntax().range(); |
105 | let top_node = name_ref | 101 | let top_node = name_ref |
106 | .syntax() | 102 | .syntax() |
@@ -197,15 +193,12 @@ impl<'a> CompletionContext<'a> { | |||
197 | } | 193 | } |
198 | } | 194 | } |
199 | 195 | ||
200 | fn find_node_with_range<'a, N: AstNode<'a>>( | 196 | fn find_node_with_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Option<&N> { |
201 | syntax: SyntaxNodeRef<'a>, | ||
202 | range: TextRange, | ||
203 | ) -> Option<N> { | ||
204 | let node = find_covering_node(syntax, range); | 197 | let node = find_covering_node(syntax, range); |
205 | node.ancestors().find_map(N::cast) | 198 | node.ancestors().find_map(N::cast) |
206 | } | 199 | } |
207 | 200 | ||
208 | fn is_node<'a, N: AstNode<'a>>(node: SyntaxNodeRef<'a>) -> bool { | 201 | fn is_node<N: AstNode>(node: &SyntaxNode) -> bool { |
209 | match node.ancestors().filter_map(N::cast).next() { | 202 | match node.ancestors().filter_map(N::cast).next() { |
210 | None => false, | 203 | None => false, |
211 | Some(n) => n.syntax().range() == node.range(), | 204 | Some(n) => n.syntax().range() == node.range(), |
diff --git a/crates/ra_analysis/src/extend_selection.rs b/crates/ra_analysis/src/extend_selection.rs index f1b77f981..3b130f966 100644 --- a/crates/ra_analysis/src/extend_selection.rs +++ b/crates/ra_analysis/src/extend_selection.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use ra_db::SyntaxDatabase; | 1 | use ra_db::SyntaxDatabase; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | SyntaxNodeRef, AstNode, SourceFileNode, | 3 | SyntaxNode, AstNode, SourceFile, |
4 | ast, algo::find_covering_node, | 4 | ast, algo::find_covering_node, |
5 | }; | 5 | }; |
6 | 6 | ||
@@ -19,18 +19,18 @@ pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRang | |||
19 | 19 | ||
20 | fn extend_selection_in_macro( | 20 | fn extend_selection_in_macro( |
21 | _db: &RootDatabase, | 21 | _db: &RootDatabase, |
22 | source_file: &SourceFileNode, | 22 | source_file: &SourceFile, |
23 | frange: FileRange, | 23 | frange: FileRange, |
24 | ) -> Option<TextRange> { | 24 | ) -> Option<TextRange> { |
25 | let macro_call = find_macro_call(source_file.syntax(), frange.range)?; | 25 | let macro_call = find_macro_call(source_file.syntax(), frange.range)?; |
26 | let (off, exp) = hir::MacroDef::ast_expand(macro_call)?; | 26 | let (off, exp) = hir::MacroDef::ast_expand(macro_call)?; |
27 | let dst_range = exp.map_range_forward(frange.range - off)?; | 27 | let dst_range = exp.map_range_forward(frange.range - off)?; |
28 | let dst_range = ra_editor::extend_selection(exp.syntax().borrowed(), dst_range)?; | 28 | let dst_range = ra_editor::extend_selection(&exp.syntax(), dst_range)?; |
29 | let src_range = exp.map_range_back(dst_range)? + off; | 29 | let src_range = exp.map_range_back(dst_range)? + off; |
30 | Some(src_range) | 30 | Some(src_range) |
31 | } | 31 | } |
32 | 32 | ||
33 | fn find_macro_call(node: SyntaxNodeRef, range: TextRange) -> Option<ast::MacroCall> { | 33 | fn find_macro_call(node: &SyntaxNode, range: TextRange) -> Option<&ast::MacroCall> { |
34 | find_covering_node(node, range) | 34 | find_covering_node(node, range) |
35 | .ancestors() | 35 | .ancestors() |
36 | .find_map(ast::MacroCall::cast) | 36 | .find_map(ast::MacroCall::cast) |
diff --git a/crates/ra_analysis/src/goto_defenition.rs b/crates/ra_analysis/src/goto_defenition.rs index aa0616e3b..0bcf13ebd 100644 --- a/crates/ra_analysis/src/goto_defenition.rs +++ b/crates/ra_analysis/src/goto_defenition.rs | |||
@@ -23,7 +23,7 @@ pub(crate) fn goto_defenition( | |||
23 | pub(crate) fn reference_defenition( | 23 | pub(crate) fn reference_defenition( |
24 | db: &RootDatabase, | 24 | db: &RootDatabase, |
25 | file_id: FileId, | 25 | file_id: FileId, |
26 | name_ref: ast::NameRef, | 26 | name_ref: &ast::NameRef, |
27 | ) -> Cancelable<Vec<NavigationTarget>> { | 27 | ) -> Cancelable<Vec<NavigationTarget>> { |
28 | if let Some(fn_descr) = | 28 | if let Some(fn_descr) = |
29 | hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())? | 29 | hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())? |
@@ -53,7 +53,7 @@ pub(crate) fn reference_defenition( | |||
53 | fn name_defenition( | 53 | fn name_defenition( |
54 | db: &RootDatabase, | 54 | db: &RootDatabase, |
55 | file_id: FileId, | 55 | file_id: FileId, |
56 | name: ast::Name, | 56 | name: &ast::Name, |
57 | ) -> Cancelable<Option<Vec<NavigationTarget>>> { | 57 | ) -> Cancelable<Option<Vec<NavigationTarget>>> { |
58 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { | 58 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { |
59 | if module.has_semi() { | 59 | if module.has_semi() { |
diff --git a/crates/ra_analysis/src/hover.rs b/crates/ra_analysis/src/hover.rs index 06632df4f..5607c3ef3 100644 --- a/crates/ra_analysis/src/hover.rs +++ b/crates/ra_analysis/src/hover.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use ra_db::{Cancelable, SyntaxDatabase}; | 1 | use ra_db::{Cancelable, SyntaxDatabase}; |
2 | use ra_editor::find_node_at_offset; | 2 | use ra_editor::find_node_at_offset; |
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | AstNode, SyntaxNode, | 4 | AstNode, SyntaxNode, TreePtr, |
5 | ast::{self, NameOwner}, | 5 | ast::{self, NameOwner}, |
6 | algo::{find_covering_node, find_leaf_at_offset, visit::{visitor, Visitor}}, | 6 | algo::{find_covering_node, find_leaf_at_offset, visit::{visitor, Visitor}}, |
7 | }; | 7 | }; |
@@ -88,20 +88,19 @@ fn doc_text_for(db: &RootDatabase, nav: NavigationTarget) -> Cancelable<Option<S | |||
88 | } | 88 | } |
89 | 89 | ||
90 | impl NavigationTarget { | 90 | impl NavigationTarget { |
91 | fn node(&self, db: &RootDatabase) -> Option<SyntaxNode> { | 91 | fn node(&self, db: &RootDatabase) -> Option<TreePtr<SyntaxNode>> { |
92 | let source_file = db.source_file(self.file_id); | 92 | let source_file = db.source_file(self.file_id); |
93 | let source_file = source_file.syntax(); | 93 | let source_file = source_file.syntax(); |
94 | let node = source_file | 94 | let node = source_file |
95 | .descendants() | 95 | .descendants() |
96 | .find(|node| node.kind() == self.kind && node.range() == self.range)? | 96 | .find(|node| node.kind() == self.kind && node.range() == self.range)? |
97 | .owned(); | 97 | .to_owned(); |
98 | Some(node) | 98 | Some(node) |
99 | } | 99 | } |
100 | 100 | ||
101 | fn docs(&self, db: &RootDatabase) -> Option<String> { | 101 | fn docs(&self, db: &RootDatabase) -> Option<String> { |
102 | let node = self.node(db)?; | 102 | let node = self.node(db)?; |
103 | let node = node.borrowed(); | 103 | fn doc_comments<N: ast::DocCommentsOwner>(node: &N) -> Option<String> { |
104 | fn doc_comments<'a, N: ast::DocCommentsOwner<'a>>(node: N) -> Option<String> { | ||
105 | let comments = node.doc_comment_text(); | 104 | let comments = node.doc_comment_text(); |
106 | if comments.is_empty() { | 105 | if comments.is_empty() { |
107 | None | 106 | None |
@@ -119,7 +118,7 @@ impl NavigationTarget { | |||
119 | .visit(doc_comments::<ast::TypeDef>) | 118 | .visit(doc_comments::<ast::TypeDef>) |
120 | .visit(doc_comments::<ast::ConstDef>) | 119 | .visit(doc_comments::<ast::ConstDef>) |
121 | .visit(doc_comments::<ast::StaticDef>) | 120 | .visit(doc_comments::<ast::StaticDef>) |
122 | .accept(node)? | 121 | .accept(&node)? |
123 | } | 122 | } |
124 | 123 | ||
125 | /// Get a description of this node. | 124 | /// Get a description of this node. |
@@ -128,50 +127,49 @@ impl NavigationTarget { | |||
128 | fn description(&self, db: &RootDatabase) -> Option<String> { | 127 | fn description(&self, db: &RootDatabase) -> Option<String> { |
129 | // TODO: After type inference is done, add type information to improve the output | 128 | // TODO: After type inference is done, add type information to improve the output |
130 | let node = self.node(db)?; | 129 | let node = self.node(db)?; |
131 | let node = node.borrowed(); | ||
132 | // TODO: Refactor to be have less repetition | 130 | // TODO: Refactor to be have less repetition |
133 | visitor() | 131 | visitor() |
134 | .visit(|node: ast::FnDef| { | 132 | .visit(|node: &ast::FnDef| { |
135 | let mut string = "fn ".to_string(); | 133 | let mut string = "fn ".to_string(); |
136 | node.name()?.syntax().text().push_to(&mut string); | 134 | node.name()?.syntax().text().push_to(&mut string); |
137 | Some(string) | 135 | Some(string) |
138 | }) | 136 | }) |
139 | .visit(|node: ast::StructDef| { | 137 | .visit(|node: &ast::StructDef| { |
140 | let mut string = "struct ".to_string(); | 138 | let mut string = "struct ".to_string(); |
141 | node.name()?.syntax().text().push_to(&mut string); | 139 | node.name()?.syntax().text().push_to(&mut string); |
142 | Some(string) | 140 | Some(string) |
143 | }) | 141 | }) |
144 | .visit(|node: ast::EnumDef| { | 142 | .visit(|node: &ast::EnumDef| { |
145 | let mut string = "enum ".to_string(); | 143 | let mut string = "enum ".to_string(); |
146 | node.name()?.syntax().text().push_to(&mut string); | 144 | node.name()?.syntax().text().push_to(&mut string); |
147 | Some(string) | 145 | Some(string) |
148 | }) | 146 | }) |
149 | .visit(|node: ast::TraitDef| { | 147 | .visit(|node: &ast::TraitDef| { |
150 | let mut string = "trait ".to_string(); | 148 | let mut string = "trait ".to_string(); |
151 | node.name()?.syntax().text().push_to(&mut string); | 149 | node.name()?.syntax().text().push_to(&mut string); |
152 | Some(string) | 150 | Some(string) |
153 | }) | 151 | }) |
154 | .visit(|node: ast::Module| { | 152 | .visit(|node: &ast::Module| { |
155 | let mut string = "mod ".to_string(); | 153 | let mut string = "mod ".to_string(); |
156 | node.name()?.syntax().text().push_to(&mut string); | 154 | node.name()?.syntax().text().push_to(&mut string); |
157 | Some(string) | 155 | Some(string) |
158 | }) | 156 | }) |
159 | .visit(|node: ast::TypeDef| { | 157 | .visit(|node: &ast::TypeDef| { |
160 | let mut string = "type ".to_string(); | 158 | let mut string = "type ".to_string(); |
161 | node.name()?.syntax().text().push_to(&mut string); | 159 | node.name()?.syntax().text().push_to(&mut string); |
162 | Some(string) | 160 | Some(string) |
163 | }) | 161 | }) |
164 | .visit(|node: ast::ConstDef| { | 162 | .visit(|node: &ast::ConstDef| { |
165 | let mut string = "const ".to_string(); | 163 | let mut string = "const ".to_string(); |
166 | node.name()?.syntax().text().push_to(&mut string); | 164 | node.name()?.syntax().text().push_to(&mut string); |
167 | Some(string) | 165 | Some(string) |
168 | }) | 166 | }) |
169 | .visit(|node: ast::StaticDef| { | 167 | .visit(|node: &ast::StaticDef| { |
170 | let mut string = "static ".to_string(); | 168 | let mut string = "static ".to_string(); |
171 | node.name()?.syntax().text().push_to(&mut string); | 169 | node.name()?.syntax().text().push_to(&mut string); |
172 | Some(string) | 170 | Some(string) |
173 | }) | 171 | }) |
174 | .accept(node)? | 172 | .accept(&node)? |
175 | } | 173 | } |
176 | } | 174 | } |
177 | 175 | ||
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 07a966290..8ac430e41 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -8,10 +8,9 @@ use hir::{ | |||
8 | use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; | 8 | use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; |
9 | use ra_editor::{self, find_node_at_offset, assists, LocalEdit, Severity}; | 9 | use ra_editor::{self, find_node_at_offset, assists, LocalEdit, Severity}; |
10 | use ra_syntax::{ | 10 | use ra_syntax::{ |
11 | ast::{self, ArgListOwner, Expr, NameOwner}, | 11 | SyntaxNode, TextRange, TextUnit, AstNode, SourceFile, |
12 | AstNode, SourceFileNode, | 12 | ast::{self, ArgListOwner, NameOwner}, |
13 | SyntaxKind::*, | 13 | SyntaxKind::*, |
14 | SyntaxNodeRef, TextRange, TextUnit, | ||
15 | }; | 14 | }; |
16 | 15 | ||
17 | use crate::{ | 16 | use crate::{ |
@@ -113,7 +112,6 @@ impl db::RootDatabase { | |||
113 | None => return Ok(Vec::new()), | 112 | None => return Ok(Vec::new()), |
114 | Some(it) => it, | 113 | Some(it) => it, |
115 | }; | 114 | }; |
116 | let ast_module = ast_module.borrowed(); | ||
117 | let name = ast_module.name().unwrap(); | 115 | let name = ast_module.name().unwrap(); |
118 | Ok(vec![NavigationTarget { | 116 | Ok(vec![NavigationTarget { |
119 | file_id, | 117 | file_id, |
@@ -163,9 +161,9 @@ impl db::RootDatabase { | |||
163 | 161 | ||
164 | fn find_binding<'a>( | 162 | fn find_binding<'a>( |
165 | db: &db::RootDatabase, | 163 | db: &db::RootDatabase, |
166 | source_file: &'a SourceFileNode, | 164 | source_file: &'a SourceFile, |
167 | position: FilePosition, | 165 | position: FilePosition, |
168 | ) -> Cancelable<Option<(ast::BindPat<'a>, hir::Function)>> { | 166 | ) -> Cancelable<Option<(&'a ast::BindPat, hir::Function)>> { |
169 | let syntax = source_file.syntax(); | 167 | let syntax = source_file.syntax(); |
170 | if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { | 168 | if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { |
171 | let descr = ctry!(source_binder::function_from_child_node( | 169 | let descr = ctry!(source_binder::function_from_child_node( |
@@ -281,7 +279,7 @@ impl db::RootDatabase { | |||
281 | if symbol.ptr.kind() == FN_DEF { | 279 | if symbol.ptr.kind() == FN_DEF { |
282 | let fn_file = self.source_file(symbol.file_id); | 280 | let fn_file = self.source_file(symbol.file_id); |
283 | let fn_def = symbol.ptr.resolve(&fn_file); | 281 | let fn_def = symbol.ptr.resolve(&fn_file); |
284 | let fn_def = ast::FnDef::cast(fn_def.borrowed()).unwrap(); | 282 | let fn_def = ast::FnDef::cast(&fn_def).unwrap(); |
285 | let descr = ctry!(source_binder::function_from_source( | 283 | let descr = ctry!(source_binder::function_from_source( |
286 | self, | 284 | self, |
287 | symbol.file_id, | 285 | symbol.file_id, |
@@ -352,7 +350,7 @@ impl db::RootDatabase { | |||
352 | .collect::<Vec<_>>(); | 350 | .collect::<Vec<_>>(); |
353 | Ok(res) | 351 | Ok(res) |
354 | } | 352 | } |
355 | pub(crate) fn index_resolve(&self, name_ref: ast::NameRef) -> Cancelable<Vec<FileSymbol>> { | 353 | pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Cancelable<Vec<FileSymbol>> { |
356 | let name = name_ref.text(); | 354 | let name = name_ref.text(); |
357 | let mut query = Query::new(name.to_string()); | 355 | let mut query = Query::new(name.to_string()); |
358 | query.exact(); | 356 | query.exact(); |
@@ -379,12 +377,12 @@ impl SourceChange { | |||
379 | } | 377 | } |
380 | 378 | ||
381 | enum FnCallNode<'a> { | 379 | enum FnCallNode<'a> { |
382 | CallExpr(ast::CallExpr<'a>), | 380 | CallExpr(&'a ast::CallExpr), |
383 | MethodCallExpr(ast::MethodCallExpr<'a>), | 381 | MethodCallExpr(&'a ast::MethodCallExpr), |
384 | } | 382 | } |
385 | 383 | ||
386 | impl<'a> FnCallNode<'a> { | 384 | impl<'a> FnCallNode<'a> { |
387 | pub fn with_node(syntax: SyntaxNodeRef, offset: TextUnit) -> Option<FnCallNode> { | 385 | pub fn with_node(syntax: &'a SyntaxNode, offset: TextUnit) -> Option<FnCallNode<'a>> { |
388 | if let Some(expr) = find_node_at_offset::<ast::CallExpr>(syntax, offset) { | 386 | if let Some(expr) = find_node_at_offset::<ast::CallExpr>(syntax, offset) { |
389 | return Some(FnCallNode::CallExpr(expr)); | 387 | return Some(FnCallNode::CallExpr(expr)); |
390 | } | 388 | } |
@@ -394,10 +392,10 @@ impl<'a> FnCallNode<'a> { | |||
394 | None | 392 | None |
395 | } | 393 | } |
396 | 394 | ||
397 | pub fn name_ref(&self) -> Option<ast::NameRef> { | 395 | pub fn name_ref(&self) -> Option<&'a ast::NameRef> { |
398 | match *self { | 396 | match *self { |
399 | FnCallNode::CallExpr(call_expr) => Some(match call_expr.expr()? { | 397 | FnCallNode::CallExpr(call_expr) => Some(match call_expr.expr()?.kind() { |
400 | Expr::PathExpr(path_expr) => path_expr.path()?.segment()?.name_ref()?, | 398 | ast::ExprKind::PathExpr(path_expr) => path_expr.path()?.segment()?.name_ref()?, |
401 | _ => return None, | 399 | _ => return None, |
402 | }), | 400 | }), |
403 | 401 | ||
@@ -409,7 +407,7 @@ impl<'a> FnCallNode<'a> { | |||
409 | } | 407 | } |
410 | } | 408 | } |
411 | 409 | ||
412 | pub fn arg_list(&self) -> Option<ast::ArgList> { | 410 | pub fn arg_list(&self) -> Option<&'a ast::ArgList> { |
413 | match *self { | 411 | match *self { |
414 | FnCallNode::CallExpr(expr) => expr.arg_list(), | 412 | FnCallNode::CallExpr(expr) => expr.arg_list(), |
415 | FnCallNode::MethodCallExpr(expr) => expr.arg_list(), | 413 | FnCallNode::MethodCallExpr(expr) => expr.arg_list(), |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index c8f846c56..ec400ffe2 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -26,7 +26,7 @@ mod syntax_highlighting; | |||
26 | 26 | ||
27 | use std::{fmt, sync::Arc}; | 27 | use std::{fmt, sync::Arc}; |
28 | 28 | ||
29 | use ra_syntax::{SmolStr, SourceFileNode, SyntaxKind, TextRange, TextUnit}; | 29 | use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit}; |
30 | use ra_text_edit::TextEdit; | 30 | use ra_text_edit::TextEdit; |
31 | use rayon::prelude::*; | 31 | use rayon::prelude::*; |
32 | use relative_path::RelativePathBuf; | 32 | use relative_path::RelativePathBuf; |
@@ -308,7 +308,7 @@ impl Analysis { | |||
308 | self.db.file_text(file_id) | 308 | self.db.file_text(file_id) |
309 | } | 309 | } |
310 | /// Gets the syntax tree of the file. | 310 | /// Gets the syntax tree of the file. |
311 | pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode { | 311 | pub fn file_syntax(&self, file_id: FileId) -> TreePtr<SourceFile> { |
312 | self.db.source_file(file_id).clone() | 312 | self.db.source_file(file_id).clone() |
313 | } | 313 | } |
314 | /// Gets the file's `LineIndex`: data structure to convert between absolute | 314 | /// Gets the file's `LineIndex`: data structure to convert between absolute |
@@ -322,7 +322,7 @@ impl Analysis { | |||
322 | } | 322 | } |
323 | /// Returns position of the mathcing brace (all types of braces are | 323 | /// Returns position of the mathcing brace (all types of braces are |
324 | /// supported). | 324 | /// supported). |
325 | pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> { | 325 | pub fn matching_brace(&self, file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { |
326 | ra_editor::matching_brace(file, offset) | 326 | ra_editor::matching_brace(file, offset) |
327 | } | 327 | } |
328 | /// Returns a syntax tree represented as `String`, for debug purposes. | 328 | /// Returns a syntax tree represented as `String`, for debug purposes. |
@@ -469,7 +469,7 @@ impl LibraryData { | |||
469 | files: Vec<(FileId, RelativePathBuf, Arc<String>)>, | 469 | files: Vec<(FileId, RelativePathBuf, Arc<String>)>, |
470 | ) -> LibraryData { | 470 | ) -> LibraryData { |
471 | let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, _, text)| { | 471 | let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, _, text)| { |
472 | let file = SourceFileNode::parse(text); | 472 | let file = SourceFile::parse(text); |
473 | (*file_id, file) | 473 | (*file_id, file) |
474 | })); | 474 | })); |
475 | let mut root_change = RootChange::default(); | 475 | let mut root_change = RootChange::default(); |
diff --git a/crates/ra_analysis/src/runnables.rs b/crates/ra_analysis/src/runnables.rs index 216209098..98b1d2d55 100644 --- a/crates/ra_analysis/src/runnables.rs +++ b/crates/ra_analysis/src/runnables.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use itertools::Itertools; | 1 | use itertools::Itertools; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | TextRange, SyntaxNode, | ||
3 | ast::{self, AstNode, NameOwner, ModuleItemOwner}, | 4 | ast::{self, AstNode, NameOwner, ModuleItemOwner}, |
4 | TextRange, SyntaxNodeRef, | ||
5 | }; | 5 | }; |
6 | use ra_db::{Cancelable, SyntaxDatabase}; | 6 | use ra_db::{Cancelable, SyntaxDatabase}; |
7 | 7 | ||
@@ -30,7 +30,7 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Cancelable<Vec<Ru | |||
30 | Ok(res) | 30 | Ok(res) |
31 | } | 31 | } |
32 | 32 | ||
33 | fn runnable(db: &RootDatabase, file_id: FileId, item: SyntaxNodeRef) -> Option<Runnable> { | 33 | fn runnable(db: &RootDatabase, file_id: FileId, item: &SyntaxNode) -> Option<Runnable> { |
34 | if let Some(fn_def) = ast::FnDef::cast(item) { | 34 | if let Some(fn_def) = ast::FnDef::cast(item) { |
35 | runnable_fn(fn_def) | 35 | runnable_fn(fn_def) |
36 | } else if let Some(m) = ast::Module::cast(item) { | 36 | } else if let Some(m) = ast::Module::cast(item) { |
@@ -40,7 +40,7 @@ fn runnable(db: &RootDatabase, file_id: FileId, item: SyntaxNodeRef) -> Option<R | |||
40 | } | 40 | } |
41 | } | 41 | } |
42 | 42 | ||
43 | fn runnable_fn(fn_def: ast::FnDef) -> Option<Runnable> { | 43 | fn runnable_fn(fn_def: &ast::FnDef) -> Option<Runnable> { |
44 | let name = fn_def.name()?.text(); | 44 | let name = fn_def.name()?.text(); |
45 | let kind = if name == "main" { | 45 | let kind = if name == "main" { |
46 | RunnableKind::Bin | 46 | RunnableKind::Bin |
@@ -57,12 +57,12 @@ fn runnable_fn(fn_def: ast::FnDef) -> Option<Runnable> { | |||
57 | }) | 57 | }) |
58 | } | 58 | } |
59 | 59 | ||
60 | fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Option<Runnable> { | 60 | fn runnable_mod(db: &RootDatabase, file_id: FileId, module: &ast::Module) -> Option<Runnable> { |
61 | let has_test_function = module | 61 | let has_test_function = module |
62 | .item_list()? | 62 | .item_list()? |
63 | .items() | 63 | .items() |
64 | .filter_map(|it| match it { | 64 | .filter_map(|it| match it.kind() { |
65 | ast::ModuleItem::FnDef(it) => Some(it), | 65 | ast::ModuleItemKind::FnDef(it) => Some(it), |
66 | _ => None, | 66 | _ => None, |
67 | }) | 67 | }) |
68 | .any(|f| f.has_atom_attr("test")); | 68 | .any(|f| f.has_atom_attr("test")); |
diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs index e2b1c88fe..ed1796756 100644 --- a/crates/ra_analysis/src/symbol_index.rs +++ b/crates/ra_analysis/src/symbol_index.rs | |||
@@ -27,7 +27,7 @@ use std::{ | |||
27 | 27 | ||
28 | use fst::{self, Streamer}; | 28 | use fst::{self, Streamer}; |
29 | use ra_syntax::{ | 29 | use ra_syntax::{ |
30 | SyntaxNodeRef, SourceFileNode, SmolStr, | 30 | SyntaxNode, SourceFile, SmolStr, TreePtr, AstNode, |
31 | algo::{visit::{visitor, Visitor}, find_covering_node}, | 31 | algo::{visit::{visitor, Visitor}, find_covering_node}, |
32 | SyntaxKind::{self, *}, | 32 | SyntaxKind::{self, *}, |
33 | ast::{self, NameOwner}, | 33 | ast::{self, NameOwner}, |
@@ -141,7 +141,7 @@ impl SymbolIndex { | |||
141 | } | 141 | } |
142 | 142 | ||
143 | pub(crate) fn for_files( | 143 | pub(crate) fn for_files( |
144 | files: impl ParallelIterator<Item = (FileId, SourceFileNode)>, | 144 | files: impl ParallelIterator<Item = (FileId, TreePtr<SourceFile>)>, |
145 | ) -> SymbolIndex { | 145 | ) -> SymbolIndex { |
146 | let symbols = files | 146 | let symbols = files |
147 | .flat_map(|(file_id, file)| { | 147 | .flat_map(|(file_id, file)| { |
@@ -203,8 +203,8 @@ pub(crate) struct FileSymbol { | |||
203 | pub(crate) ptr: LocalSyntaxPtr, | 203 | pub(crate) ptr: LocalSyntaxPtr, |
204 | } | 204 | } |
205 | 205 | ||
206 | fn to_symbol(node: SyntaxNodeRef) -> Option<(SmolStr, LocalSyntaxPtr)> { | 206 | fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, LocalSyntaxPtr)> { |
207 | fn decl<'a, N: NameOwner<'a>>(node: N) -> Option<(SmolStr, LocalSyntaxPtr)> { | 207 | fn decl<N: NameOwner>(node: &N) -> Option<(SmolStr, LocalSyntaxPtr)> { |
208 | let name = node.name()?.text(); | 208 | let name = node.name()?.text(); |
209 | let ptr = LocalSyntaxPtr::new(node.syntax()); | 209 | let ptr = LocalSyntaxPtr::new(node.syntax()); |
210 | Some((name, ptr)) | 210 | Some((name, ptr)) |
diff --git a/crates/ra_analysis/src/syntax_highlighting.rs b/crates/ra_analysis/src/syntax_highlighting.rs index 35e153ca0..d2dc6cfbb 100644 --- a/crates/ra_analysis/src/syntax_highlighting.rs +++ b/crates/ra_analysis/src/syntax_highlighting.rs | |||
@@ -16,7 +16,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Cancelable<Vec<Hi | |||
16 | .filter_map(ast::MacroCall::cast) | 16 | .filter_map(ast::MacroCall::cast) |
17 | { | 17 | { |
18 | if let Some((off, exp)) = hir::MacroDef::ast_expand(macro_call) { | 18 | if let Some((off, exp)) = hir::MacroDef::ast_expand(macro_call) { |
19 | let mapped_ranges = ra_editor::highlight(exp.syntax().borrowed()) | 19 | let mapped_ranges = ra_editor::highlight(&exp.syntax()) |
20 | .into_iter() | 20 | .into_iter() |
21 | .filter_map(|r| { | 21 | .filter_map(|r| { |
22 | let mapped_range = exp.map_range_back(r.range)?; | 22 | let mapped_range = exp.map_range_back(r.range)?; |