diff options
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 28 |
1 files changed, 13 insertions, 15 deletions
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(), |