aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/call_info.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-18 17:35:10 +0000
committerAleksey Kladov <[email protected]>2020-02-26 11:55:50 +0000
commitc3a4c4429de83450654795534e64e878a774a088 (patch)
tree12d89798f61b276f8bd640db07276a7d4e92b1c2 /crates/ra_ide/src/call_info.rs
parent04deae3dba7c9b7054f7a1d64e4b93a05aecc132 (diff)
Refactor primary IDE API
This introduces the new type -- Semantics. Semantics maps SyntaxNodes to various semantic info, such as type, name resolution or macro expansions. To do so, Semantics maintains a HashMap which maps every node it saw to the file from which the node originated. This is enough to get all the necessary hir bits just from syntax.
Diffstat (limited to 'crates/ra_ide/src/call_info.rs')
-rw-r--r--crates/ra_ide/src/call_info.rs27
1 files changed, 13 insertions, 14 deletions
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs
index 7c6322cb4..9a1fc0d35 100644
--- a/crates/ra_ide/src/call_info.rs
+++ b/crates/ra_ide/src/call_info.rs
@@ -1,5 +1,5 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2use hir::db::AstDatabase; 2use hir::Semantics;
3use ra_ide_db::RootDatabase; 3use ra_ide_db::RootDatabase;
4use ra_syntax::{ 4use ra_syntax::{
5 ast::{self, ArgListOwner}, 5 ast::{self, ArgListOwner},
@@ -7,24 +7,23 @@ use ra_syntax::{
7}; 7};
8use test_utils::tested_by; 8use test_utils::tested_by;
9 9
10use crate::{expand::descend_into_macros, CallInfo, FilePosition, FunctionSignature}; 10use crate::{CallInfo, FilePosition, FunctionSignature};
11 11
12/// Computes parameter information for the given call expression. 12/// Computes parameter information for the given call expression.
13pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> { 13pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> {
14 let file = db.parse_or_expand(position.file_id.into())?; 14 let sema = Semantics::new(db);
15 let file = sema.parse(position.file_id);
16 let file = file.syntax();
15 let token = file.token_at_offset(position.offset).next()?; 17 let token = file.token_at_offset(position.offset).next()?;
16 let token = descend_into_macros(db, position.file_id, token); 18 let token = sema.descend_into_macros(token);
17 19
18 // Find the calling expression and it's NameRef 20 // Find the calling expression and it's NameRef
19 let calling_node = FnCallNode::with_node(&token.value.parent())?; 21 let calling_node = FnCallNode::with_node(&token.parent())?;
20 let name_ref = calling_node.name_ref()?;
21 let name_ref = token.with_value(name_ref.syntax());
22 22
23 let analyzer = hir::SourceAnalyzer::new(db, name_ref, None);
24 let (mut call_info, has_self) = match &calling_node { 23 let (mut call_info, has_self) = match &calling_node {
25 FnCallNode::CallExpr(expr) => { 24 FnCallNode::CallExpr(call) => {
26 //FIXME: Type::as_callable is broken 25 //FIXME: Type::as_callable is broken
27 let callable_def = analyzer.type_of(db, &expr.expr()?)?.as_callable()?; 26 let callable_def = sema.type_of_expr(&call.expr()?)?.as_callable()?;
28 match callable_def { 27 match callable_def {
29 hir::CallableDef::FunctionId(it) => { 28 hir::CallableDef::FunctionId(it) => {
30 let fn_def = it.into(); 29 let fn_def = it.into();
@@ -36,12 +35,12 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
36 } 35 }
37 } 36 }
38 } 37 }
39 FnCallNode::MethodCallExpr(expr) => { 38 FnCallNode::MethodCallExpr(method_call) => {
40 let function = analyzer.resolve_method_call(&expr)?; 39 let function = sema.resolve_method_call(&method_call)?;
41 (CallInfo::with_fn(db, function), function.has_self_param(db)) 40 (CallInfo::with_fn(db, function), function.has_self_param(db))
42 } 41 }
43 FnCallNode::MacroCallExpr(expr) => { 42 FnCallNode::MacroCallExpr(macro_call) => {
44 let macro_def = analyzer.resolve_macro_call(db, name_ref.with_value(&expr))?; 43 let macro_def = sema.resolve_macro_call(&macro_call)?;
45 (CallInfo::with_macro(db, macro_def)?, false) 44 (CallInfo::with_macro(db, macro_def)?, false)
46 } 45 }
47 }; 46 };