Use name resolution for goto definition

This commit is contained in:
Florian Diebold
2019-01-08 00:30:49 +01:00
committed by Florian Diebold
parent dc2a8d5acc
commit a6590ce231
7 changed files with 179 additions and 16 deletions

View File

@@ -34,7 +34,7 @@ pub struct HirFileId(HirFileIdRepr);
impl HirFileId {
/// For macro-expansion files, returns the file original source file the
/// expansionoriginated from.
pub(crate) fn original_file(self, db: &impl HirDatabase) -> FileId {
pub fn original_file(self, db: &impl HirDatabase) -> FileId {
match self.0 {
HirFileIdRepr::File(file_id) => file_id,
HirFileIdRepr::Macro(macro_call_id) => {
@@ -179,6 +179,12 @@ impl DefId {
Ok(res)
}
pub(crate) fn source(self, db: &impl HirDatabase) -> (HirFileId, TreePtr<SyntaxNode>) {
let loc = self.loc(db);
let syntax = db.file_item(loc.source_item_id);
(loc.source_item_id.file_id, syntax)
}
/// For a module, returns that module; for any other def, returns the containing module.
pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> {
let loc = self.loc(db);