mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
add ability to get strcut field source
This commit is contained in:
parent
0044514a4e
commit
9f2574c97e
7 changed files with 131 additions and 37 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue