Use source map

This commit is contained in:
kjeremy 2019-03-06 14:40:42 -05:00
parent aac421b135
commit 064707c5a0
2 changed files with 10 additions and 15 deletions

View file

@ -60,7 +60,7 @@ pub use self::{
impl_block::{ImplBlock, ImplItem}, impl_block::{ImplBlock, ImplItem},
docs::{Docs, Documentation}, docs::{Docs, Documentation},
adt::AdtDef, adt::AdtDef,
expr::{ExprScopes, ScopesWithSourceMap, ScopeEntryWithSyntax, Pat}, expr::{ExprScopes, ScopesWithSourceMap, ScopeEntryWithSyntax},
resolve::{Resolver, Resolution}, resolve::{Resolver, Resolution},
}; };

View file

@ -5,7 +5,7 @@ use ra_syntax::{
SyntaxNode, SyntaxNode,
}; };
use test_utils::tested_by; use test_utils::tested_by;
use hir::{Pat, Resolution}; use hir::Resolution;
use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo}; use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo};
@ -149,16 +149,13 @@ pub(crate) fn reference_definition(
name_ref.syntax().ancestors().find_map(ast::PathPat::cast) name_ref.syntax().ancestors().find_map(ast::PathPat::cast)
{ {
let infer_result = function.infer(db); let infer_result = function.infer(db);
let source_map = function.body_source_map(db);
if let Some(p) = path_pat.path().and_then(hir::Path::from_ast) { let pat: &ast::Pat = path_pat.into();
if let Some(pat_id) =
function.body(db).pats().find_map(|(pat_id, pat)| match pat { if let Some(res) = source_map
Pat::Path(ref path) if *path == p => Some(pat_id), .node_pat(pat)
_ => None, .and_then(|it| infer_result.assoc_resolutions_for_pat(it.into()))
})
{
if let Some(res) =
infer_result.assoc_resolutions_for_pat(pat_id.into())
{ {
return Exact(NavigationTarget::from_impl_item(db, res)); return Exact(NavigationTarget::from_impl_item(db, res));
} }
@ -167,8 +164,6 @@ pub(crate) fn reference_definition(
} }
} }
} }
}
}
// If that fails try the index based approach. // If that fails try the index based approach.
let navs = crate::symbol_index::index_resolve(db, name_ref) let navs = crate::symbol_index::index_resolve(db, name_ref)