aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-06-11 01:17:29 +0100
committerAleksey Kladov <[email protected]>2019-06-11 16:28:51 +0100
commit2a1fe26b6d354dbbd1b3843d288d56e74fa00557 (patch)
tree6784274854b9808eb997eb868d5a4f2bc889f9a3 /crates/ra_hir/src
parent91c120ccea4f0cfef20fd4d918154c8152f83816 (diff)
use Source more
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/adt.rs21
-rw-r--r--crates/ra_hir/src/code_model.rs9
-rw-r--r--crates/ra_hir/src/docs.rs4
-rw-r--r--crates/ra_hir/src/generics.rs2
-rw-r--r--crates/ra_hir/src/lib.rs2
5 files changed, 17 insertions, 21 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 36679e99b..2b372333f 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -11,7 +11,7 @@ use ra_syntax::{
11 11
12use crate::{ 12use crate::{
13 Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase, 13 Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase,
14 HirDatabase, HirFileId, StructField, FieldSource, 14 HirDatabase, HirFileId, StructField, FieldSource, Source,
15 type_ref::TypeRef, DefDatabase, 15 type_ref::TypeRef, DefDatabase,
16}; 16};
17 17
@@ -72,15 +72,15 @@ impl EnumVariant {
72 pub(crate) fn source_impl( 72 pub(crate) fn source_impl(
73 &self, 73 &self,
74 db: &(impl DefDatabase + AstDatabase), 74 db: &(impl DefDatabase + AstDatabase),
75 ) -> (HirFileId, TreeArc<ast::EnumVariant>) { 75 ) -> Source<TreeArc<ast::EnumVariant>> {
76 let (file_id, enum_def) = self.parent.source(db); 76 let src = self.parent.source(db);
77 let var = variants(&*enum_def) 77 let ast = variants(&*src.ast)
78 .zip(db.enum_data(self.parent).variants.iter()) 78 .zip(db.enum_data(self.parent).variants.iter())
79 .find(|(_syntax, (id, _))| *id == self.id) 79 .find(|(_syntax, (id, _))| *id == self.id)
80 .unwrap() 80 .unwrap()
81 .0 81 .0
82 .to_owned(); 82 .to_owned();
83 (file_id, var) 83 Source { file_id: src.file_id, ast }
84 } 84 }
85 pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc<VariantData> { 85 pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc<VariantData> {
86 db.enum_data(self.parent).variants[self.id].variant_data.clone() 86 db.enum_data(self.parent).variants[self.id].variant_data.clone()
@@ -95,9 +95,9 @@ pub struct EnumData {
95 95
96impl EnumData { 96impl EnumData {
97 pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc<EnumData> { 97 pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc<EnumData> {
98 let (_file_id, enum_def) = e.source(db); 98 let src = e.source(db);
99 let name = enum_def.name().map(|n| n.as_name()); 99 let name = src.ast.name().map(|n| n.as_name());
100 let variants = variants(&*enum_def) 100 let variants = variants(&*src.ast)
101 .map(|var| EnumVariantData { 101 .map(|var| EnumVariantData {
102 name: var.name().map(|it| it.as_name()), 102 name: var.name().map(|it| it.as_name()),
103 variant_data: Arc::new(VariantData::new(var.kind())), 103 variant_data: Arc::new(VariantData::new(var.kind())),
@@ -215,9 +215,8 @@ impl StructField {
215 (ss.file_id, ss.ast.kind()) 215 (ss.file_id, ss.ast.kind())
216 } 216 }
217 VariantDef::EnumVariant(e) => { 217 VariantDef::EnumVariant(e) => {
218 let (file_id, source) = e.source(db); 218 es = e.source(db);
219 es = source; 219 (es.file_id, es.ast.kind())
220 (file_id, es.kind())
221 } 220 }
222 }; 221 };
223 222
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 3469da18a..63fdca55e 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -456,11 +456,8 @@ pub struct Enum {
456} 456}
457 457
458impl Enum { 458impl Enum {
459 pub fn source( 459 pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> {
460 self, 460 self.id.source(db).into()
461 db: &(impl DefDatabase + AstDatabase),
462 ) -> (HirFileId, TreeArc<ast::EnumDef>) {
463 self.id.source(db)
464 } 461 }
465 462
466 pub fn module(self, db: &impl HirDatabase) -> Module { 463 pub fn module(self, db: &impl HirDatabase) -> Module {
@@ -509,7 +506,7 @@ impl EnumVariant {
509 pub fn source( 506 pub fn source(
510 &self, 507 &self,
511 db: &(impl DefDatabase + AstDatabase), 508 db: &(impl DefDatabase + AstDatabase),
512 ) -> (HirFileId, TreeArc<ast::EnumVariant>) { 509 ) -> Source<TreeArc<ast::EnumVariant>> {
513 self.source_impl(db) 510 self.source_impl(db)
514 } 511 }
515 pub fn module(&self, db: &impl HirDatabase) -> Module { 512 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 edd937901..70b9d13b2 100644
--- a/crates/ra_hir/src/docs.rs
+++ b/crates/ra_hir/src/docs.rs
@@ -77,8 +77,8 @@ pub(crate) fn documentation_query(
77 FieldSource::Pos(..) => return None, 77 FieldSource::Pos(..) => return None,
78 }, 78 },
79 DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast), 79 DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast),
80 DocDef::Enum(it) => docs_from_ast(&*it.source(db).1), 80 DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast),
81 DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).1), 81 DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).ast),
82 DocDef::Static(it) => docs_from_ast(&*it.source(db).1), 82 DocDef::Static(it) => docs_from_ast(&*it.source(db).1),
83 DocDef::Const(it) => docs_from_ast(&*it.source(db).1), 83 DocDef::Const(it) => docs_from_ast(&*it.source(db).1),
84 DocDef::Function(it) => docs_from_ast(&*it.source(db).1), 84 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 294a00721..2a92d5945 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -71,7 +71,7 @@ impl GenericParams {
71 GenericDef::Function(it) => generics.fill(&*it.source(db).1, start), 71 GenericDef::Function(it) => generics.fill(&*it.source(db).1, start),
72 GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start), 72 GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start),
73 GenericDef::Union(it) => generics.fill(&*it.source(db).1, start), 73 GenericDef::Union(it) => generics.fill(&*it.source(db).1, start),
74 GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start), 74 GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, start),
75 GenericDef::Trait(it) => { 75 GenericDef::Trait(it) => {
76 // traits get the Self type as an implicit first type parameter 76 // traits get the Self type as an implicit first type parameter
77 generics.params.push(GenericParam { 77 generics.params.push(GenericParam {
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 0e4aaf678..90e3f1275 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -81,5 +81,5 @@ pub use self::code_model::{
81 StructField, FieldSource, 81 StructField, FieldSource,
82 Static, Const, ConstSignature, 82 Static, Const, ConstSignature,
83 Trait, TypeAlias, MacroDef, Container, 83 Trait, TypeAlias, MacroDef, Container,
84 BuiltinType, 84 BuiltinType, Source,
85}; 85};