aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorVille Penttinen <[email protected]>2019-02-21 10:04:14 +0000
committerVille Penttinen <[email protected]>2019-02-21 10:25:55 +0000
commit816971ebc9207c5fb5779d448613dd171c27f398 (patch)
treefe49d209a852bb1b4a51eea9d40449dcf2845209 /crates/ra_ide_api
parentc84561bb624280b84eb2fe6c6b2a6b9fe3f1dbf7 (diff)
Implement basic support for Associated Methods and Constants
This is done in `infer_path_expr`. When `Resolver::resolve_path` returns `PartiallyResolved`, we use the returned `Resolution` together with the given `segment_index` to check if we can find something matching the segment at segment_index in the impls for that particular type.
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs2
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs2
-rw-r--r--crates/ra_ide_api/src/hover.rs20
3 files changed, 22 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index d337fe970..a0c5572d5 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -10,7 +10,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
10 Some(path) => path.clone(), 10 Some(path) => path.clone(),
11 _ => return, 11 _ => return,
12 }; 12 };
13 let def = match ctx.resolver.resolve_path(ctx.db, &path).take_types() { 13 let def = match ctx.resolver.resolve_path(ctx.db, &path).into_per_ns().take_types() {
14 Some(Resolution::Def(def)) => def, 14 Some(Resolution::Def(def)) => def,
15 _ => return, 15 _ => return,
16 }; 16 };
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 96ed8c8e9..76aaebd52 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -79,7 +79,7 @@ pub(crate) fn reference_definition(
79 if let Some(path) = 79 if let Some(path) =
80 name_ref.syntax().ancestors().find_map(ast::Path::cast).and_then(hir::Path::from_ast) 80 name_ref.syntax().ancestors().find_map(ast::Path::cast).and_then(hir::Path::from_ast)
81 { 81 {
82 let resolved = resolver.resolve_path(db, &path); 82 let resolved = resolver.resolve_path(db, &path).into_per_ns();
83 match resolved.clone().take_types().or_else(|| resolved.take_values()) { 83 match resolved.clone().take_types().or_else(|| resolved.take_values()) {
84 Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)), 84 Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)),
85 Some(Resolution::LocalBinding(pat)) => { 85 Some(Resolution::LocalBinding(pat)) => {
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 0888ab6de..38671b394 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -223,4 +223,24 @@ mod tests {
223 assert_eq!("usize", &type_name); 223 assert_eq!("usize", &type_name);
224 } 224 }
225 225
226 #[test]
227 fn test_hover_infer_associated_method_result() {
228 let (analysis, position) = single_file_with_position(
229 "
230 struct Thing { x: u32 };
231
232 impl Thing {
233 fn new() -> Thing {
234 Thing { x: 0 }
235 }
236 }
237
238 fn main() {
239 let foo_<|>test = Thing::new();
240 }
241 ",
242 );
243 let hover = analysis.hover(position).unwrap().unwrap();
244 assert_eq!(hover.info, "Thing");
245 }
226} 246}