aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_impl
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-12 21:18:14 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-12 21:18:14 +0000
commiteb931c0d9e0877e573622253ae5b05563841037b (patch)
tree653ef81450a4d39c5b46f98c97c23fa8586dd7f8 /crates/ra_hir/src/code_model_impl
parente56072bfa3e5af69a4c293a38de6e1350ada3573 (diff)
parent1ed7fbfc1badd2c2a42b4dc2feb1b4bf7835d3ef (diff)
Merge #505
505: Inherent methods r=matklad a=flodiebold This adds resolution, type checking and completion for inherent methods. The main open question here is the caching, I think. I'm not sure whether we should be caching method resolutions in a more fine grained way (currently we just build a hash map of types -> impl blocks, and iterate through all potential impl blocks when looking for a method). Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model_impl')
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs11
-rw-r--r--crates/ra_hir/src/code_model_impl/function/scope.rs2
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs15
3 files changed, 23 insertions, 5 deletions
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs
index 1ce939e05..8d6b7fc19 100644
--- a/crates/ra_hir/src/code_model_impl/function.rs
+++ b/crates/ra_hir/src/code_model_impl/function.rs
@@ -42,7 +42,8 @@ impl FnSignature {
42 .name() 42 .name()
43 .map(|n| n.as_name()) 43 .map(|n| n.as_name())
44 .unwrap_or_else(Name::missing); 44 .unwrap_or_else(Name::missing);
45 let mut args = Vec::new(); 45 let mut params = Vec::new();
46 let mut has_self_param = false;
46 if let Some(param_list) = node.param_list() { 47 if let Some(param_list) = node.param_list() {
47 if let Some(self_param) = param_list.self_param() { 48 if let Some(self_param) = param_list.self_param() {
48 let self_type = if let Some(type_ref) = self_param.type_ref() { 49 let self_type = if let Some(type_ref) = self_param.type_ref() {
@@ -59,11 +60,12 @@ impl FnSignature {
59 } 60 }
60 } 61 }
61 }; 62 };
62 args.push(self_type); 63 params.push(self_type);
64 has_self_param = true;
63 } 65 }
64 for param in param_list.params() { 66 for param in param_list.params() {
65 let type_ref = TypeRef::from_ast_opt(param.type_ref()); 67 let type_ref = TypeRef::from_ast_opt(param.type_ref());
66 args.push(type_ref); 68 params.push(type_ref);
67 } 69 }
68 } 70 }
69 let ret_type = if let Some(type_ref) = node.ret_type().and_then(|rt| rt.type_ref()) { 71 let ret_type = if let Some(type_ref) = node.ret_type().and_then(|rt| rt.type_ref()) {
@@ -73,8 +75,9 @@ impl FnSignature {
73 }; 75 };
74 let sig = FnSignature { 76 let sig = FnSignature {
75 name, 77 name,
76 args, 78 params,
77 ret_type, 79 ret_type,
80 has_self_param,
78 }; 81 };
79 Arc::new(sig) 82 Arc::new(sig)
80 } 83 }
diff --git a/crates/ra_hir/src/code_model_impl/function/scope.rs b/crates/ra_hir/src/code_model_impl/function/scope.rs
index ebf6edc1b..7d938c0dd 100644
--- a/crates/ra_hir/src/code_model_impl/function/scope.rs
+++ b/crates/ra_hir/src/code_model_impl/function/scope.rs
@@ -43,7 +43,7 @@ impl FnScopes {
43 scope_for: FxHashMap::default(), 43 scope_for: FxHashMap::default(),
44 }; 44 };
45 let root = scopes.root_scope(); 45 let root = scopes.root_scope();
46 scopes.add_params_bindings(root, body.args()); 46 scopes.add_params_bindings(root, body.params());
47 compute_expr_scopes(body.body_expr(), &body, &mut scopes, root); 47 compute_expr_scopes(body.body_expr(), &body, &mut scopes, root);
48 scopes 48 scopes
49 } 49 }
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index e9ff06dc8..775dd6709 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -95,6 +95,21 @@ impl Module {
95 Module::from_module_id(db, loc.source_root_id, child_id).map(Some) 95 Module::from_module_id(db, loc.source_root_id, child_id).map(Some)
96 } 96 }
97 97
98 /// Iterates over all child modules.
99 pub fn children_impl(&self, db: &impl HirDatabase) -> Cancelable<impl Iterator<Item = Module>> {
100 // FIXME this should be implementable without collecting into a vec, but
101 // it's kind of hard since the iterator needs to keep a reference to the
102 // module tree.
103 let loc = self.def_id.loc(db);
104 let module_tree = db.module_tree(loc.source_root_id)?;
105 let children = loc
106 .module_id
107 .children(&module_tree)
108 .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id))
109 .collect::<Cancelable<Vec<_>>>()?;
110 Ok(children.into_iter())
111 }
112
98 pub fn parent_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { 113 pub fn parent_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> {
99 let loc = self.def_id.loc(db); 114 let loc = self.def_id.loc(db);
100 let module_tree = db.module_tree(loc.source_root_id)?; 115 let module_tree = db.module_tree(loc.source_root_id)?;