Use ImplItems instead of just Function

This commit is contained in:
Jeremy Kolb 2019-03-02 14:05:37 -05:00
parent 49da9a3e81
commit 3d8d880c59
3 changed files with 65 additions and 40 deletions

View file

@ -5,7 +5,7 @@ use ra_syntax::{
SyntaxNode,
};
use test_utils::tested_by;
use hir::Resolution;
use hir::{ImplItem, Resolution};
use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo};
@ -131,14 +131,25 @@ pub(crate) fn reference_definition(
name_ref.syntax().ancestors().find_map(ast::PathExpr::cast)
{
let infer_result = function.infer(db);
let syntax_mapping = function.body_syntax_mapping(db);
let source_map = function.body_source_map(db);
let expr = ast::Expr::cast(path_expr.syntax()).unwrap();
if let Some(func) = syntax_mapping
if let Some(res) = source_map
.node_expr(expr)
.and_then(|it| infer_result.assoc_fn_resolutions(it))
.and_then(|it| infer_result.assoc_resolutions(it.into()))
{
return Exact(NavigationTarget::from_function(db, func));
match res {
ImplItem::Method(f) => {
return Exact(NavigationTarget::from_function(db, f));
}
ImplItem::Const(c) => {
let (file, node) = c.source(db);
let file = file.original_file(db);
let node = &*node;
return Exact(NavigationTarget::from_named(file, node));
}
_ => {}
}
}
}
}

View file

@ -531,7 +531,7 @@ mod tests {
",
);
let hover = analysis.hover(position).unwrap().unwrap();
assert_eq!(hover.info.first(), Some("```rust\nfn new() -> Thing\n```"));
assert_eq!(trim_markup_opt(hover.info.first()), Some("fn new() -> Thing"));
assert_eq!(hover.info.is_exact(), true);
}
}