add ability to get strcut field source

This commit is contained in:
Aleksey Kladov 2019-01-25 20:32:34 +03:00
parent 0044514a4e
commit 9f2574c97e
7 changed files with 131 additions and 37 deletions

View file

@ -3,7 +3,7 @@ use ra_syntax::{
SyntaxNode, AstNode, SmolStr, TextRange, ast,
SyntaxKind::{self, NAME},
};
use hir::{ModuleSource};
use hir::{ModuleSource, FieldSource};
use crate::{FileSymbol, db::RootDatabase};
@ -101,6 +101,17 @@ impl NavigationTarget {
NavigationTarget::from_named(file_id.original_file(db), &*fn_def)
}
pub(crate) fn from_field(db: &RootDatabase, field: hir::StructField) -> NavigationTarget {
let (file_id, field) = field.source(db);
let file_id = file_id.original_file(db);
match field {
FieldSource::Named(it) => NavigationTarget::from_named(file_id, &*it),
FieldSource::Pos(it) => {
NavigationTarget::from_syntax(file_id, "".into(), None, it.syntax())
}
}
}
// TODO once Def::Item is gone, this should be able to always return a NavigationTarget
pub(crate) fn from_def(
db: &RootDatabase,