introduce Source struct
This commit is contained in:
parent
e505fe9d7b
commit
91c120ccea
@ -59,8 +59,8 @@ impl StructData {
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
struct_: Struct,
|
||||
) -> Arc<StructData> {
|
||||
let (_, struct_def) = struct_.source(db);
|
||||
Arc::new(StructData::new(&*struct_def))
|
||||
let src = struct_.source(db);
|
||||
Arc::new(StructData::new(&*src.ast))
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,9 +211,8 @@ impl StructField {
|
||||
let es;
|
||||
let (file_id, struct_kind) = match self.parent {
|
||||
VariantDef::Struct(s) => {
|
||||
let (file_id, source) = s.source(db);
|
||||
ss = source;
|
||||
(file_id, ss.kind())
|
||||
ss = s.source(db);
|
||||
(ss.file_id, ss.ast.kind())
|
||||
}
|
||||
VariantDef::EnumVariant(e) => {
|
||||
let (file_id, source) = e.source(db);
|
||||
|
@ -20,6 +20,17 @@ use crate::{
|
||||
type_ref::Mutability,
|
||||
};
|
||||
|
||||
pub struct Source<T> {
|
||||
pub file_id: HirFileId,
|
||||
pub ast: T,
|
||||
}
|
||||
|
||||
impl<T> From<(HirFileId, T)> for Source<T> {
|
||||
fn from((file_id, ast): (HirFileId, T)) -> Self {
|
||||
Source { file_id, ast }
|
||||
}
|
||||
}
|
||||
|
||||
/// hir::Crate describes a single crate. It's the main interface with which
|
||||
/// a crate's dependencies interact. Mostly, it should be just a proxy for the
|
||||
/// root module.
|
||||
@ -354,11 +365,8 @@ pub struct Struct {
|
||||
}
|
||||
|
||||
impl Struct {
|
||||
pub fn source(
|
||||
self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::StructDef>) {
|
||||
self.id.source(db)
|
||||
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
|
||||
self.id.source(db).into()
|
||||
}
|
||||
|
||||
pub fn module(self, db: &impl HirDatabase) -> Module {
|
||||
|
@ -76,7 +76,7 @@ pub(crate) fn documentation_query(
|
||||
FieldSource::Named(named) => docs_from_ast(&*named),
|
||||
FieldSource::Pos(..) => return None,
|
||||
},
|
||||
DocDef::Struct(it) => docs_from_ast(&*it.source(db).1),
|
||||
DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast),
|
||||
DocDef::Enum(it) => docs_from_ast(&*it.source(db).1),
|
||||
DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).1),
|
||||
DocDef::Static(it) => docs_from_ast(&*it.source(db).1),
|
||||
|
@ -69,7 +69,7 @@ impl GenericParams {
|
||||
let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32;
|
||||
match def {
|
||||
GenericDef::Function(it) => generics.fill(&*it.source(db).1, start),
|
||||
GenericDef::Struct(it) => generics.fill(&*it.source(db).1, start),
|
||||
GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start),
|
||||
GenericDef::Union(it) => generics.fill(&*it.source(db).1, start),
|
||||
GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start),
|
||||
GenericDef::Trait(it) => {
|
||||
|
@ -189,12 +189,12 @@ impl NavigationTarget {
|
||||
pub(crate) fn from_adt_def(db: &RootDatabase, adt_def: hir::AdtDef) -> NavigationTarget {
|
||||
match adt_def {
|
||||
hir::AdtDef::Struct(s) => {
|
||||
let (file_id, node) = s.source(db);
|
||||
let src = s.source(db);
|
||||
NavigationTarget::from_named(
|
||||
file_id.original_file(db),
|
||||
&*node,
|
||||
node.doc_comment_text(),
|
||||
node.short_label(),
|
||||
src.file_id.original_file(db),
|
||||
&*src.ast,
|
||||
src.ast.doc_comment_text(),
|
||||
src.ast.short_label(),
|
||||
)
|
||||
}
|
||||
hir::AdtDef::Union(s) => {
|
||||
@ -226,12 +226,12 @@ impl NavigationTarget {
|
||||
hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module),
|
||||
hir::ModuleDef::Function(func) => NavigationTarget::from_function(db, func),
|
||||
hir::ModuleDef::Struct(s) => {
|
||||
let (file_id, node) = s.source(db);
|
||||
let src = s.source(db);
|
||||
NavigationTarget::from_named(
|
||||
file_id.original_file(db),
|
||||
&*node,
|
||||
node.doc_comment_text(),
|
||||
node.short_label(),
|
||||
src.file_id.original_file(db),
|
||||
&*src.ast,
|
||||
src.ast.doc_comment_text(),
|
||||
src.ast.short_label(),
|
||||
)
|
||||
}
|
||||
hir::ModuleDef::Union(s) => {
|
||||
|
@ -136,8 +136,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
||||
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
||||
}
|
||||
hir::ModuleDef::Struct(it) => {
|
||||
let it = it.source(db).1;
|
||||
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
||||
let src = it.source(db);
|
||||
res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()))
|
||||
}
|
||||
hir::ModuleDef::Union(it) => {
|
||||
let it = it.source(db).1;
|
||||
@ -176,8 +176,11 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
||||
if let Some((adt_def, _)) = ty.as_adt() {
|
||||
match adt_def {
|
||||
hir::AdtDef::Struct(it) => {
|
||||
let it = it.source(db).1;
|
||||
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
||||
let src = it.source(db);
|
||||
res.extend(hover_text(
|
||||
src.ast.doc_comment_text(),
|
||||
src.ast.short_label(),
|
||||
))
|
||||
}
|
||||
hir::AdtDef::Union(it) => {
|
||||
let it = it.source(db).1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user