diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index 36679e99b0..2b372333fc 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs @@ -11,7 +11,7 @@ use ra_syntax::{ use crate::{ Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase, - HirDatabase, HirFileId, StructField, FieldSource, + HirDatabase, HirFileId, StructField, FieldSource, Source, type_ref::TypeRef, DefDatabase, }; @@ -72,15 +72,15 @@ impl EnumVariant { pub(crate) fn source_impl( &self, db: &(impl DefDatabase + AstDatabase), - ) -> (HirFileId, TreeArc) { - let (file_id, enum_def) = self.parent.source(db); - let var = variants(&*enum_def) + ) -> Source> { + let src = self.parent.source(db); + let ast = variants(&*src.ast) .zip(db.enum_data(self.parent).variants.iter()) .find(|(_syntax, (id, _))| *id == self.id) .unwrap() .0 .to_owned(); - (file_id, var) + Source { file_id: src.file_id, ast } } pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc { db.enum_data(self.parent).variants[self.id].variant_data.clone() @@ -95,9 +95,9 @@ pub struct EnumData { impl EnumData { pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc { - let (_file_id, enum_def) = e.source(db); - let name = enum_def.name().map(|n| n.as_name()); - let variants = variants(&*enum_def) + let src = e.source(db); + let name = src.ast.name().map(|n| n.as_name()); + let variants = variants(&*src.ast) .map(|var| EnumVariantData { name: var.name().map(|it| it.as_name()), variant_data: Arc::new(VariantData::new(var.kind())), @@ -215,9 +215,8 @@ impl StructField { (ss.file_id, ss.ast.kind()) } VariantDef::EnumVariant(e) => { - let (file_id, source) = e.source(db); - es = source; - (file_id, es.kind()) + es = e.source(db); + (es.file_id, es.ast.kind()) } }; diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 3469da18a6..63fdca55ed 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -456,11 +456,8 @@ pub struct Enum { } impl Enum { - pub fn source( - self, - db: &(impl DefDatabase + AstDatabase), - ) -> (HirFileId, TreeArc) { - self.id.source(db) + pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source> { + self.id.source(db).into() } pub fn module(self, db: &impl HirDatabase) -> Module { @@ -509,7 +506,7 @@ impl EnumVariant { pub fn source( &self, db: &(impl DefDatabase + AstDatabase), - ) -> (HirFileId, TreeArc) { + ) -> Source> { self.source_impl(db) } pub fn module(&self, db: &impl HirDatabase) -> Module { diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs index edd937901a..70b9d13b2e 100644 --- a/crates/ra_hir/src/docs.rs +++ b/crates/ra_hir/src/docs.rs @@ -77,8 +77,8 @@ pub(crate) fn documentation_query( FieldSource::Pos(..) => return None, }, 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::Enum(it) => docs_from_ast(&*it.source(db).ast), + DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).ast), DocDef::Static(it) => docs_from_ast(&*it.source(db).1), DocDef::Const(it) => docs_from_ast(&*it.source(db).1), DocDef::Function(it) => docs_from_ast(&*it.source(db).1), diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 294a007216..2a92d59450 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -71,7 +71,7 @@ impl GenericParams { GenericDef::Function(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::Enum(it) => generics.fill(&*it.source(db).ast, start), GenericDef::Trait(it) => { // traits get the Self type as an implicit first type parameter generics.params.push(GenericParam { diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 0e4aaf678e..90e3f1275c 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -81,5 +81,5 @@ pub use self::code_model::{ StructField, FieldSource, Static, Const, ConstSignature, Trait, TypeAlias, MacroDef, Container, - BuiltinType, + BuiltinType, Source, }; diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index c02bc005b1..7c68bb41cc 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -207,12 +207,12 @@ impl NavigationTarget { ) } hir::AdtDef::Enum(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(), ) } } @@ -225,24 +225,9 @@ impl NavigationTarget { let nav = match module_def { hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module), hir::ModuleDef::Function(func) => NavigationTarget::from_function(db, func), - hir::ModuleDef::Struct(s) => { - let src = s.source(db); - NavigationTarget::from_named( - src.file_id.original_file(db), - &*src.ast, - src.ast.doc_comment_text(), - src.ast.short_label(), - ) - } - hir::ModuleDef::Union(s) => { - let (file_id, node) = s.source(db); - NavigationTarget::from_named( - file_id.original_file(db), - &*node, - node.doc_comment_text(), - node.short_label(), - ) - } + hir::ModuleDef::Struct(it) => NavigationTarget::from_adt_def(db, it.into()), + hir::ModuleDef::Enum(it) => NavigationTarget::from_adt_def(db, it.into()), + hir::ModuleDef::Union(it) => NavigationTarget::from_adt_def(db, it.into()), hir::ModuleDef::Const(s) => { let (file_id, node) = s.source(db); NavigationTarget::from_named( @@ -261,22 +246,13 @@ impl NavigationTarget { node.short_label(), ) } - hir::ModuleDef::Enum(e) => { - let (file_id, node) = e.source(db); - NavigationTarget::from_named( - file_id.original_file(db), - &*node, - node.doc_comment_text(), - node.short_label(), - ) - } hir::ModuleDef::EnumVariant(var) => { - let (file_id, node) = var.source(db); + let src = var.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::Trait(e) => { diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 80445761ce..ee0f2dde88 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -144,12 +144,12 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - 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::EnumVariant(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::Const(it) => { let it = it.source(db).1; @@ -187,8 +187,11 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - 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(), + )) } } }