diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/adt.rs | 39 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 120 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model/docs.rs (renamed from crates/ra_hir/src/docs.rs) | 26 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model/src.rs | 110 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/expr.rs | 19 | ||||
-rw-r--r-- | crates/ra_hir/src/expr/validation.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/generics.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir/src/ids.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 27 | ||||
-rw-r--r-- | crates/ra_hir/src/lang_item.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/traits.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/type_alias.rs | 4 |
16 files changed, 210 insertions, 195 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index 38ff1d6f6..b3843b35c 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs | |||
@@ -11,7 +11,7 @@ use ra_syntax::{ | |||
11 | 11 | ||
12 | use crate::{ | 12 | use 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, StructField, FieldSource, Source, HasSource, |
15 | type_ref::TypeRef, DefDatabase, | 15 | type_ref::TypeRef, DefDatabase, |
16 | }; | 16 | }; |
17 | 17 | ||
@@ -59,8 +59,8 @@ impl StructData { | |||
59 | db: &(impl DefDatabase + AstDatabase), | 59 | db: &(impl DefDatabase + AstDatabase), |
60 | struct_: Struct, | 60 | struct_: Struct, |
61 | ) -> Arc<StructData> { | 61 | ) -> Arc<StructData> { |
62 | let (_, struct_def) = struct_.source(db); | 62 | let src = struct_.source(db); |
63 | Arc::new(StructData::new(&*struct_def)) | 63 | Arc::new(StructData::new(&*src.ast)) |
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
@@ -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 | ||
96 | impl EnumData { | 96 | impl 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())), |
@@ -201,24 +201,19 @@ impl VariantDef { | |||
201 | } | 201 | } |
202 | 202 | ||
203 | impl StructField { | 203 | impl StructField { |
204 | pub(crate) fn source_impl( | 204 | pub(crate) fn source_impl(&self, db: &(impl DefDatabase + AstDatabase)) -> Source<FieldSource> { |
205 | &self, | ||
206 | db: &(impl DefDatabase + AstDatabase), | ||
207 | ) -> (HirFileId, FieldSource) { | ||
208 | let var_data = self.parent.variant_data(db); | 205 | let var_data = self.parent.variant_data(db); |
209 | let fields = var_data.fields().unwrap(); | 206 | let fields = var_data.fields().unwrap(); |
210 | let ss; | 207 | let ss; |
211 | let es; | 208 | let es; |
212 | let (file_id, struct_kind) = match self.parent { | 209 | let (file_id, struct_kind) = match self.parent { |
213 | VariantDef::Struct(s) => { | 210 | VariantDef::Struct(s) => { |
214 | let (file_id, source) = s.source(db); | 211 | ss = s.source(db); |
215 | ss = source; | 212 | (ss.file_id, ss.ast.kind()) |
216 | (file_id, ss.kind()) | ||
217 | } | 213 | } |
218 | VariantDef::EnumVariant(e) => { | 214 | VariantDef::EnumVariant(e) => { |
219 | let (file_id, source) = e.source(db); | 215 | es = e.source(db); |
220 | es = source; | 216 | (es.file_id, es.ast.kind()) |
221 | (file_id, es.kind()) | ||
222 | } | 217 | } |
223 | }; | 218 | }; |
224 | 219 | ||
@@ -231,12 +226,12 @@ impl StructField { | |||
231 | } | 226 | } |
232 | ast::StructKind::Unit => Vec::new(), | 227 | ast::StructKind::Unit => Vec::new(), |
233 | }; | 228 | }; |
234 | let field = field_sources | 229 | let ast = field_sources |
235 | .into_iter() | 230 | .into_iter() |
236 | .zip(fields.iter()) | 231 | .zip(fields.iter()) |
237 | .find(|(_syntax, (id, _))| *id == self.id) | 232 | .find(|(_syntax, (id, _))| *id == self.id) |
238 | .unwrap() | 233 | .unwrap() |
239 | .0; | 234 | .0; |
240 | (file_id, field) | 235 | Source { file_id, ast } |
241 | } | 236 | } |
242 | } | 237 | } |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 27850028b..830aea1f3 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -1,10 +1,13 @@ | |||
1 | pub(crate) mod src; | ||
2 | pub(crate) mod docs; | ||
3 | |||
1 | use std::sync::Arc; | 4 | use std::sync::Arc; |
2 | 5 | ||
3 | use ra_db::{CrateId, SourceRootId, Edition, FileId}; | 6 | use ra_db::{CrateId, SourceRootId, Edition, FileId}; |
4 | use ra_syntax::{ast::{self, NameOwner, TypeAscriptionOwner}, TreeArc}; | 7 | use ra_syntax::{ast::{self, NameOwner, TypeAscriptionOwner}, TreeArc}; |
5 | 8 | ||
6 | use crate::{ | 9 | use crate::{ |
7 | Name, AsName, AstId, Ty, HirFileId, Either, KnownName, | 10 | Name, AsName, AstId, Ty, Either, KnownName, HasSource, |
8 | HirDatabase, DefDatabase, AstDatabase, | 11 | HirDatabase, DefDatabase, AstDatabase, |
9 | type_ref::TypeRef, | 12 | type_ref::TypeRef, |
10 | nameres::{ModuleScope, Namespace, ImportId, CrateModuleId}, | 13 | nameres::{ModuleScope, Namespace, ImportId, CrateModuleId}, |
@@ -179,40 +182,15 @@ impl Module { | |||
179 | }) | 182 | }) |
180 | } | 183 | } |
181 | 184 | ||
182 | /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. | ||
183 | pub fn definition_source( | ||
184 | self, | ||
185 | db: &(impl DefDatabase + AstDatabase), | ||
186 | ) -> (HirFileId, ModuleSource) { | ||
187 | let def_map = db.crate_def_map(self.krate); | ||
188 | let decl_id = def_map[self.module_id].declaration; | ||
189 | let file_id = def_map[self.module_id].definition; | ||
190 | let module_source = ModuleSource::new(db, file_id, decl_id); | ||
191 | let file_id = file_id.map(HirFileId::from).unwrap_or_else(|| decl_id.unwrap().file_id()); | ||
192 | (file_id, module_source) | ||
193 | } | ||
194 | |||
195 | /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. | ||
196 | /// `None` for the crate root. | ||
197 | pub fn declaration_source( | ||
198 | self, | ||
199 | db: &(impl DefDatabase + AstDatabase), | ||
200 | ) -> Option<(HirFileId, TreeArc<ast::Module>)> { | ||
201 | let def_map = db.crate_def_map(self.krate); | ||
202 | let decl = def_map[self.module_id].declaration?; | ||
203 | let ast = decl.to_node(db); | ||
204 | Some((decl.file_id(), ast)) | ||
205 | } | ||
206 | |||
207 | /// Returns the syntax of the last path segment corresponding to this import | 185 | /// Returns the syntax of the last path segment corresponding to this import |
208 | pub fn import_source( | 186 | pub fn import_source( |
209 | self, | 187 | self, |
210 | db: &impl HirDatabase, | 188 | db: &impl HirDatabase, |
211 | import: ImportId, | 189 | import: ImportId, |
212 | ) -> Either<TreeArc<ast::UseTree>, TreeArc<ast::ExternCrateItem>> { | 190 | ) -> Either<TreeArc<ast::UseTree>, TreeArc<ast::ExternCrateItem>> { |
213 | let (file_id, source) = self.definition_source(db); | 191 | let src = self.definition_source(db); |
214 | let (_, source_map) = db.raw_items_with_source_map(file_id); | 192 | let (_, source_map) = db.raw_items_with_source_map(src.file_id); |
215 | source_map.get(&source, import) | 193 | source_map.get(&src.ast, import) |
216 | } | 194 | } |
217 | 195 | ||
218 | /// Returns the crate this module is part of. | 196 | /// Returns the crate this module is part of. |
@@ -335,10 +313,6 @@ impl StructField { | |||
335 | self.parent.variant_data(db).fields().unwrap()[self.id].name.clone() | 313 | self.parent.variant_data(db).fields().unwrap()[self.id].name.clone() |
336 | } | 314 | } |
337 | 315 | ||
338 | pub fn source(&self, db: &(impl DefDatabase + AstDatabase)) -> (HirFileId, FieldSource) { | ||
339 | self.source_impl(db) | ||
340 | } | ||
341 | |||
342 | pub fn ty(&self, db: &impl HirDatabase) -> Ty { | 316 | pub fn ty(&self, db: &impl HirDatabase) -> Ty { |
343 | db.type_for_field(*self) | 317 | db.type_for_field(*self) |
344 | } | 318 | } |
@@ -354,13 +328,6 @@ pub struct Struct { | |||
354 | } | 328 | } |
355 | 329 | ||
356 | impl Struct { | 330 | impl Struct { |
357 | pub fn source( | ||
358 | self, | ||
359 | db: &(impl DefDatabase + AstDatabase), | ||
360 | ) -> (HirFileId, TreeArc<ast::StructDef>) { | ||
361 | self.id.source(db) | ||
362 | } | ||
363 | |||
364 | pub fn module(self, db: &impl HirDatabase) -> Module { | 331 | pub fn module(self, db: &impl HirDatabase) -> Module { |
365 | self.id.module(db) | 332 | self.id.module(db) |
366 | } | 333 | } |
@@ -415,13 +382,6 @@ pub struct Union { | |||
415 | } | 382 | } |
416 | 383 | ||
417 | impl Union { | 384 | impl Union { |
418 | pub fn source( | ||
419 | self, | ||
420 | db: &(impl DefDatabase + AstDatabase), | ||
421 | ) -> (HirFileId, TreeArc<ast::StructDef>) { | ||
422 | self.id.source(db) | ||
423 | } | ||
424 | |||
425 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { | 385 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { |
426 | db.struct_data(Struct { id: self.id }).name.clone() | 386 | db.struct_data(Struct { id: self.id }).name.clone() |
427 | } | 387 | } |
@@ -448,13 +408,6 @@ pub struct Enum { | |||
448 | } | 408 | } |
449 | 409 | ||
450 | impl Enum { | 410 | impl Enum { |
451 | pub fn source( | ||
452 | self, | ||
453 | db: &(impl DefDatabase + AstDatabase), | ||
454 | ) -> (HirFileId, TreeArc<ast::EnumDef>) { | ||
455 | self.id.source(db) | ||
456 | } | ||
457 | |||
458 | pub fn module(self, db: &impl HirDatabase) -> Module { | 411 | pub fn module(self, db: &impl HirDatabase) -> Module { |
459 | self.id.module(db) | 412 | self.id.module(db) |
460 | } | 413 | } |
@@ -498,12 +451,6 @@ pub struct EnumVariant { | |||
498 | } | 451 | } |
499 | 452 | ||
500 | impl EnumVariant { | 453 | impl EnumVariant { |
501 | pub fn source( | ||
502 | &self, | ||
503 | db: &(impl DefDatabase + AstDatabase), | ||
504 | ) -> (HirFileId, TreeArc<ast::EnumVariant>) { | ||
505 | self.source_impl(db) | ||
506 | } | ||
507 | pub fn module(&self, db: &impl HirDatabase) -> Module { | 454 | pub fn module(&self, db: &impl HirDatabase) -> Module { |
508 | self.parent.module(db) | 455 | self.parent.module(db) |
509 | } | 456 | } |
@@ -588,11 +535,11 @@ impl FnSignature { | |||
588 | db: &(impl DefDatabase + AstDatabase), | 535 | db: &(impl DefDatabase + AstDatabase), |
589 | func: Function, | 536 | func: Function, |
590 | ) -> Arc<FnSignature> { | 537 | ) -> Arc<FnSignature> { |
591 | let (_, node) = func.source(db); | 538 | let src = func.source(db); |
592 | let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); | 539 | let name = src.ast.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); |
593 | let mut params = Vec::new(); | 540 | let mut params = Vec::new(); |
594 | let mut has_self_param = false; | 541 | let mut has_self_param = false; |
595 | if let Some(param_list) = node.param_list() { | 542 | if let Some(param_list) = src.ast.param_list() { |
596 | if let Some(self_param) = param_list.self_param() { | 543 | if let Some(self_param) = param_list.self_param() { |
597 | let self_type = if let Some(type_ref) = self_param.ascribed_type() { | 544 | let self_type = if let Some(type_ref) = self_param.ascribed_type() { |
598 | TypeRef::from_ast(type_ref) | 545 | TypeRef::from_ast(type_ref) |
@@ -616,7 +563,7 @@ impl FnSignature { | |||
616 | params.push(type_ref); | 563 | params.push(type_ref); |
617 | } | 564 | } |
618 | } | 565 | } |
619 | let ret_type = if let Some(type_ref) = node.ret_type().and_then(|rt| rt.type_ref()) { | 566 | let ret_type = if let Some(type_ref) = src.ast.ret_type().and_then(|rt| rt.type_ref()) { |
620 | TypeRef::from_ast(type_ref) | 567 | TypeRef::from_ast(type_ref) |
621 | } else { | 568 | } else { |
622 | TypeRef::unit() | 569 | TypeRef::unit() |
@@ -645,10 +592,6 @@ impl FnSignature { | |||
645 | } | 592 | } |
646 | 593 | ||
647 | impl Function { | 594 | impl Function { |
648 | pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> (HirFileId, TreeArc<ast::FnDef>) { | ||
649 | self.id.source(db) | ||
650 | } | ||
651 | |||
652 | pub fn module(self, db: &impl DefDatabase) -> Module { | 595 | pub fn module(self, db: &impl DefDatabase) -> Module { |
653 | self.id.module(db) | 596 | self.id.module(db) |
654 | } | 597 | } |
@@ -723,13 +666,6 @@ pub struct Const { | |||
723 | } | 666 | } |
724 | 667 | ||
725 | impl Const { | 668 | impl Const { |
726 | pub fn source( | ||
727 | self, | ||
728 | db: &(impl DefDatabase + AstDatabase), | ||
729 | ) -> (HirFileId, TreeArc<ast::ConstDef>) { | ||
730 | self.id.source(db) | ||
731 | } | ||
732 | |||
733 | pub fn module(self, db: &impl DefDatabase) -> Module { | 669 | pub fn module(self, db: &impl DefDatabase) -> Module { |
734 | self.id.module(db) | 670 | self.id.module(db) |
735 | } | 671 | } |
@@ -780,7 +716,7 @@ impl ConstSignature { | |||
780 | db: &(impl DefDatabase + AstDatabase), | 716 | db: &(impl DefDatabase + AstDatabase), |
781 | konst: Const, | 717 | konst: Const, |
782 | ) -> Arc<ConstSignature> { | 718 | ) -> Arc<ConstSignature> { |
783 | let (_, node) = konst.source(db); | 719 | let node = konst.source(db).ast; |
784 | const_signature_for(&*node) | 720 | const_signature_for(&*node) |
785 | } | 721 | } |
786 | 722 | ||
@@ -788,7 +724,7 @@ impl ConstSignature { | |||
788 | db: &(impl DefDatabase + AstDatabase), | 724 | db: &(impl DefDatabase + AstDatabase), |
789 | konst: Static, | 725 | konst: Static, |
790 | ) -> Arc<ConstSignature> { | 726 | ) -> Arc<ConstSignature> { |
791 | let (_, node) = konst.source(db); | 727 | let node = konst.source(db).ast; |
792 | const_signature_for(&*node) | 728 | const_signature_for(&*node) |
793 | } | 729 | } |
794 | } | 730 | } |
@@ -806,13 +742,6 @@ pub struct Static { | |||
806 | } | 742 | } |
807 | 743 | ||
808 | impl Static { | 744 | impl Static { |
809 | pub fn source( | ||
810 | self, | ||
811 | db: &(impl DefDatabase + AstDatabase), | ||
812 | ) -> (HirFileId, TreeArc<ast::StaticDef>) { | ||
813 | self.id.source(db) | ||
814 | } | ||
815 | |||
816 | pub fn module(self, db: &impl DefDatabase) -> Module { | 745 | pub fn module(self, db: &impl DefDatabase) -> Module { |
817 | self.id.module(db) | 746 | self.id.module(db) |
818 | } | 747 | } |
@@ -838,13 +767,6 @@ pub struct Trait { | |||
838 | } | 767 | } |
839 | 768 | ||
840 | impl Trait { | 769 | impl Trait { |
841 | pub fn source( | ||
842 | self, | ||
843 | db: &(impl DefDatabase + AstDatabase), | ||
844 | ) -> (HirFileId, TreeArc<ast::TraitDef>) { | ||
845 | self.id.source(db) | ||
846 | } | ||
847 | |||
848 | pub fn module(self, db: &impl DefDatabase) -> Module { | 770 | pub fn module(self, db: &impl DefDatabase) -> Module { |
849 | self.id.module(db) | 771 | self.id.module(db) |
850 | } | 772 | } |
@@ -884,13 +806,6 @@ pub struct TypeAlias { | |||
884 | } | 806 | } |
885 | 807 | ||
886 | impl TypeAlias { | 808 | impl TypeAlias { |
887 | pub fn source( | ||
888 | self, | ||
889 | db: &(impl DefDatabase + AstDatabase), | ||
890 | ) -> (HirFileId, TreeArc<ast::TypeAliasDef>) { | ||
891 | self.id.source(db) | ||
892 | } | ||
893 | |||
894 | pub fn module(self, db: &impl DefDatabase) -> Module { | 809 | pub fn module(self, db: &impl DefDatabase) -> Module { |
895 | self.id.module(db) | 810 | self.id.module(db) |
896 | } | 811 | } |
@@ -939,14 +854,7 @@ pub struct MacroDef { | |||
939 | pub(crate) id: MacroDefId, | 854 | pub(crate) id: MacroDefId, |
940 | } | 855 | } |
941 | 856 | ||
942 | impl MacroDef { | 857 | impl MacroDef {} |
943 | pub fn source( | ||
944 | &self, | ||
945 | db: &(impl DefDatabase + AstDatabase), | ||
946 | ) -> (HirFileId, TreeArc<ast::MacroCall>) { | ||
947 | (self.id.0.file_id(), self.id.0.to_node(db)) | ||
948 | } | ||
949 | } | ||
950 | 858 | ||
951 | pub enum Container { | 859 | pub enum Container { |
952 | Trait(Trait), | 860 | Trait(Trait), |
diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/code_model/docs.rs index 1b0f84de5..da2b9b854 100644 --- a/crates/ra_hir/src/docs.rs +++ b/crates/ra_hir/src/code_model/docs.rs | |||
@@ -3,7 +3,7 @@ use std::sync::Arc; | |||
3 | use ra_syntax::ast; | 3 | use ra_syntax::ast; |
4 | 4 | ||
5 | use crate::{ | 5 | use crate::{ |
6 | HirDatabase, DefDatabase, AstDatabase, | 6 | HirDatabase, DefDatabase, AstDatabase, HasSource, |
7 | Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource, MacroDef, | 7 | Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource, MacroDef, |
8 | }; | 8 | }; |
9 | 9 | ||
@@ -71,21 +71,21 @@ pub(crate) fn documentation_query( | |||
71 | def: DocDef, | 71 | def: DocDef, |
72 | ) -> Option<Documentation> { | 72 | ) -> Option<Documentation> { |
73 | match def { | 73 | match def { |
74 | DocDef::Module(it) => docs_from_ast(&*it.declaration_source(db)?.1), | 74 | DocDef::Module(it) => docs_from_ast(&*it.declaration_source(db)?.ast), |
75 | DocDef::StructField(it) => match it.source(db).1 { | 75 | DocDef::StructField(it) => match it.source(db).ast { |
76 | FieldSource::Named(named) => docs_from_ast(&*named), | 76 | FieldSource::Named(named) => docs_from_ast(&*named), |
77 | FieldSource::Pos(..) => return None, | 77 | FieldSource::Pos(..) => return None, |
78 | }, | 78 | }, |
79 | DocDef::Struct(it) => docs_from_ast(&*it.source(db).1), | 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).ast), |
83 | DocDef::Const(it) => docs_from_ast(&*it.source(db).1), | 83 | DocDef::Const(it) => docs_from_ast(&*it.source(db).ast), |
84 | DocDef::Function(it) => docs_from_ast(&*it.source(db).1), | 84 | DocDef::Function(it) => docs_from_ast(&*it.source(db).ast), |
85 | DocDef::Union(it) => docs_from_ast(&*it.source(db).1), | 85 | DocDef::Union(it) => docs_from_ast(&*it.source(db).ast), |
86 | DocDef::Trait(it) => docs_from_ast(&*it.source(db).1), | 86 | DocDef::Trait(it) => docs_from_ast(&*it.source(db).ast), |
87 | DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).1), | 87 | DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).ast), |
88 | DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).1), | 88 | DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).ast), |
89 | } | 89 | } |
90 | } | 90 | } |
91 | 91 | ||
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs new file mode 100644 index 000000000..5785d3b26 --- /dev/null +++ b/crates/ra_hir/src/code_model/src.rs | |||
@@ -0,0 +1,110 @@ | |||
1 | use ra_syntax::{TreeArc, ast}; | ||
2 | |||
3 | use crate::{ | ||
4 | HirFileId, DefDatabase, AstDatabase, Module, ModuleSource, | ||
5 | StructField, Struct, Enum, Union, EnumVariant, Function, Static, Trait, Const, TypeAlias, | ||
6 | FieldSource, MacroDef, ids::AstItemDef, | ||
7 | }; | ||
8 | |||
9 | pub struct Source<T> { | ||
10 | pub file_id: HirFileId, | ||
11 | pub ast: T, | ||
12 | } | ||
13 | |||
14 | pub trait HasSource { | ||
15 | type Ast; | ||
16 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<Self::Ast>; | ||
17 | } | ||
18 | |||
19 | /// NB: Module is !HasSource, because it has two source nodes at the same time: | ||
20 | /// definition and declaration. | ||
21 | impl Module { | ||
22 | /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. | ||
23 | pub fn definition_source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ModuleSource> { | ||
24 | let def_map = db.crate_def_map(self.krate); | ||
25 | let decl_id = def_map[self.module_id].declaration; | ||
26 | let file_id = def_map[self.module_id].definition; | ||
27 | let ast = ModuleSource::new(db, file_id, decl_id); | ||
28 | let file_id = file_id.map(HirFileId::from).unwrap_or_else(|| decl_id.unwrap().file_id()); | ||
29 | Source { file_id, ast } | ||
30 | } | ||
31 | |||
32 | /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. | ||
33 | /// `None` for the crate root. | ||
34 | pub fn declaration_source( | ||
35 | self, | ||
36 | db: &(impl DefDatabase + AstDatabase), | ||
37 | ) -> Option<Source<TreeArc<ast::Module>>> { | ||
38 | let def_map = db.crate_def_map(self.krate); | ||
39 | let decl = def_map[self.module_id].declaration?; | ||
40 | let ast = decl.to_node(db); | ||
41 | Some(Source { file_id: decl.file_id(), ast }) | ||
42 | } | ||
43 | } | ||
44 | |||
45 | impl HasSource for StructField { | ||
46 | type Ast = FieldSource; | ||
47 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<FieldSource> { | ||
48 | self.source_impl(db) | ||
49 | } | ||
50 | } | ||
51 | impl HasSource for Struct { | ||
52 | type Ast = TreeArc<ast::StructDef>; | ||
53 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> { | ||
54 | self.id.source(db) | ||
55 | } | ||
56 | } | ||
57 | impl HasSource for Union { | ||
58 | type Ast = TreeArc<ast::StructDef>; | ||
59 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> { | ||
60 | self.id.source(db) | ||
61 | } | ||
62 | } | ||
63 | impl HasSource for Enum { | ||
64 | type Ast = TreeArc<ast::EnumDef>; | ||
65 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> { | ||
66 | self.id.source(db) | ||
67 | } | ||
68 | } | ||
69 | impl HasSource for EnumVariant { | ||
70 | type Ast = TreeArc<ast::EnumVariant>; | ||
71 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumVariant>> { | ||
72 | self.source_impl(db) | ||
73 | } | ||
74 | } | ||
75 | impl HasSource for Function { | ||
76 | type Ast = TreeArc<ast::FnDef>; | ||
77 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::FnDef>> { | ||
78 | self.id.source(db) | ||
79 | } | ||
80 | } | ||
81 | impl HasSource for Const { | ||
82 | type Ast = TreeArc<ast::ConstDef>; | ||
83 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ConstDef>> { | ||
84 | self.id.source(db) | ||
85 | } | ||
86 | } | ||
87 | impl HasSource for Static { | ||
88 | type Ast = TreeArc<ast::StaticDef>; | ||
89 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StaticDef>> { | ||
90 | self.id.source(db) | ||
91 | } | ||
92 | } | ||
93 | impl HasSource for Trait { | ||
94 | type Ast = TreeArc<ast::TraitDef>; | ||
95 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TraitDef>> { | ||
96 | self.id.source(db) | ||
97 | } | ||
98 | } | ||
99 | impl HasSource for TypeAlias { | ||
100 | type Ast = TreeArc<ast::TypeAliasDef>; | ||
101 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TypeAliasDef>> { | ||
102 | self.id.source(db) | ||
103 | } | ||
104 | } | ||
105 | impl HasSource for MacroDef { | ||
106 | type Ast = TreeArc<ast::MacroCall>; | ||
107 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::MacroCall>> { | ||
108 | Source { file_id: self.id.0.file_id(), ast: self.id.0.to_node(db) } | ||
109 | } | ||
110 | } | ||
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index d2a372f3b..d2d6f95b7 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -128,8 +128,8 @@ pub trait DefDatabase: SourceDatabase { | |||
128 | #[salsa::invoke(crate::lang_item::LangItems::lang_item_query)] | 128 | #[salsa::invoke(crate::lang_item::LangItems::lang_item_query)] |
129 | fn lang_item(&self, start_crate: Crate, item: SmolStr) -> Option<LangItemTarget>; | 129 | fn lang_item(&self, start_crate: Crate, item: SmolStr) -> Option<LangItemTarget>; |
130 | 130 | ||
131 | #[salsa::invoke(crate::docs::documentation_query)] | 131 | #[salsa::invoke(crate::code_model::docs::documentation_query)] |
132 | fn documentation(&self, def: crate::docs::DocDef) -> Option<crate::docs::Documentation>; | 132 | fn documentation(&self, def: crate::DocDef) -> Option<crate::Documentation>; |
133 | } | 133 | } |
134 | 134 | ||
135 | #[salsa::query_group(HirDatabaseStorage)] | 135 | #[salsa::query_group(HirDatabaseStorage)] |
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 012f374ec..b1973d19d 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -11,6 +11,7 @@ use ra_syntax::{ | |||
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind, | 13 | Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind, |
14 | HasSource, | ||
14 | name::AsName, | 15 | name::AsName, |
15 | type_ref::{Mutability, TypeRef}, | 16 | type_ref::{Mutability, TypeRef}, |
16 | }; | 17 | }; |
@@ -1018,19 +1019,19 @@ pub(crate) fn body_with_source_map_query( | |||
1018 | 1019 | ||
1019 | match def { | 1020 | match def { |
1020 | DefWithBody::Const(ref c) => { | 1021 | DefWithBody::Const(ref c) => { |
1021 | let (file_id, src) = c.source(db); | 1022 | let src = c.source(db); |
1022 | collector = ExprCollector::new(def, file_id, def.resolver(db), db); | 1023 | collector = ExprCollector::new(def, src.file_id, def.resolver(db), db); |
1023 | collector.collect_const_body(&src) | 1024 | collector.collect_const_body(&src.ast) |
1024 | } | 1025 | } |
1025 | DefWithBody::Function(ref f) => { | 1026 | DefWithBody::Function(ref f) => { |
1026 | let (file_id, src) = f.source(db); | 1027 | let src = f.source(db); |
1027 | collector = ExprCollector::new(def, file_id, def.resolver(db), db); | 1028 | collector = ExprCollector::new(def, src.file_id, def.resolver(db), db); |
1028 | collector.collect_fn_body(&src) | 1029 | collector.collect_fn_body(&src.ast) |
1029 | } | 1030 | } |
1030 | DefWithBody::Static(ref s) => { | 1031 | DefWithBody::Static(ref s) => { |
1031 | let (file_id, src) = s.source(db); | 1032 | let src = s.source(db); |
1032 | collector = ExprCollector::new(def, file_id, def.resolver(db), db); | 1033 | collector = ExprCollector::new(def, src.file_id, def.resolver(db), db); |
1033 | collector.collect_static_body(&src) | 1034 | collector.collect_static_body(&src.ast) |
1034 | } | 1035 | } |
1035 | } | 1036 | } |
1036 | 1037 | ||
diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs index a1b2641da..534fd482b 100644 --- a/crates/ra_hir/src/expr/validation.rs +++ b/crates/ra_hir/src/expr/validation.rs | |||
@@ -5,7 +5,7 @@ use ra_syntax::ast::{AstNode, StructLit}; | |||
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | expr::AstPtr, | 7 | expr::AstPtr, |
8 | HirDatabase, Function, Name, | 8 | HirDatabase, Function, Name, HasSource, |
9 | diagnostics::{DiagnosticSink, MissingFields}, | 9 | diagnostics::{DiagnosticSink, MissingFields}, |
10 | adt::AdtDef, | 10 | adt::AdtDef, |
11 | Path, | 11 | Path, |
@@ -71,7 +71,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
71 | return; | 71 | return; |
72 | } | 72 | } |
73 | let source_map = self.func.body_source_map(db); | 73 | let source_map = self.func.body_source_map(db); |
74 | let file_id = self.func.source(db).0; | 74 | let file_id = self.func.source(db).file_id; |
75 | let source_file = db.parse(file_id.original_file(db)).tree; | 75 | let source_file = db.parse(file_id.original_file(db)).tree; |
76 | if let Some(field_list_node) = source_map | 76 | if let Some(field_list_node) = source_map |
77 | .expr_syntax(id) | 77 | .expr_syntax(id) |
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index b6c5e18d3..462b136b7 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs | |||
@@ -8,8 +8,10 @@ use std::sync::Arc; | |||
8 | use ra_syntax::ast::{self, NameOwner, TypeParamsOwner, TypeBoundsOwner, DefaultTypeParamOwner}; | 8 | use ra_syntax::ast::{self, NameOwner, TypeParamsOwner, TypeBoundsOwner, DefaultTypeParamOwner}; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | HasSource, | ||
12 | Name, AsName, Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, Container, AdtDef, | ||
11 | db::{HirDatabase, DefDatabase, AstDatabase}, | 13 | db::{HirDatabase, DefDatabase, AstDatabase}, |
12 | Name, AsName, Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, Container, path::Path, type_ref::TypeRef, AdtDef | 14 | path::Path, type_ref::TypeRef, |
13 | }; | 15 | }; |
14 | 16 | ||
15 | /// Data about a generic parameter (to a function, struct, impl, ...). | 17 | /// Data about a generic parameter (to a function, struct, impl, ...). |
@@ -68,10 +70,10 @@ impl GenericParams { | |||
68 | generics.parent_params = parent.map(|p| db.generic_params(p)); | 70 | generics.parent_params = parent.map(|p| db.generic_params(p)); |
69 | let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32; | 71 | let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32; |
70 | match def { | 72 | match def { |
71 | GenericDef::Function(it) => generics.fill(&*it.source(db).1, start), | 73 | GenericDef::Function(it) => generics.fill(&*it.source(db).ast, start), |
72 | GenericDef::Struct(it) => generics.fill(&*it.source(db).1, start), | 74 | GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start), |
73 | GenericDef::Union(it) => generics.fill(&*it.source(db).1, start), | 75 | GenericDef::Union(it) => generics.fill(&*it.source(db).ast, start), |
74 | GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start), | 76 | GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, start), |
75 | GenericDef::Trait(it) => { | 77 | GenericDef::Trait(it) => { |
76 | // traits get the Self type as an implicit first type parameter | 78 | // traits get the Self type as an implicit first type parameter |
77 | generics.params.push(GenericParam { | 79 | generics.params.push(GenericParam { |
@@ -79,10 +81,10 @@ impl GenericParams { | |||
79 | name: Name::self_type(), | 81 | name: Name::self_type(), |
80 | default: None, | 82 | default: None, |
81 | }); | 83 | }); |
82 | generics.fill(&*it.source(db).1, start + 1); | 84 | generics.fill(&*it.source(db).ast, start + 1); |
83 | } | 85 | } |
84 | GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).1, start), | 86 | GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).ast, start), |
85 | GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).1, start), | 87 | GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).ast, start), |
86 | } | 88 | } |
87 | 89 | ||
88 | Arc::new(generics) | 90 | Arc::new(generics) |
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index a95561812..352f9ffd9 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -9,7 +9,7 @@ use ra_prof::profile; | |||
9 | use mbe::MacroRules; | 9 | use mbe::MacroRules; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | Module, DefDatabase, AstId, FileAstId, AstDatabase, | 12 | Module, DefDatabase, AstId, FileAstId, AstDatabase, Source, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | /// hir makes heavy use of ids: integer (u32) handlers to various things. You | 15 | /// hir makes heavy use of ids: integer (u32) handlers to various things. You |
@@ -265,10 +265,10 @@ pub(crate) trait AstItemDef<N: AstNode>: salsa::InternKey + Clone { | |||
265 | let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) }; | 265 | let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) }; |
266 | Self::intern(ctx.db, loc) | 266 | Self::intern(ctx.db, loc) |
267 | } | 267 | } |
268 | fn source(self, db: &(impl AstDatabase + DefDatabase)) -> (HirFileId, TreeArc<N>) { | 268 | fn source(self, db: &(impl AstDatabase + DefDatabase)) -> Source<TreeArc<N>> { |
269 | let loc = self.lookup_intern(db); | 269 | let loc = self.lookup_intern(db); |
270 | let ast = loc.ast_id.to_node(db); | 270 | let ast = loc.ast_id.to_node(db); |
271 | (loc.ast_id.file_id(), ast) | 271 | Source { file_id: loc.ast_id.file_id(), ast } |
272 | } | 272 | } |
273 | fn module(self, db: &impl DefDatabase) -> Module { | 273 | fn module(self, db: &impl DefDatabase) -> Module { |
274 | let loc = self.lookup_intern(db); | 274 | let loc = self.lookup_intern(db); |
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index a0d3b33fe..fb9daf1bf 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs | |||
@@ -8,7 +8,7 @@ use ra_syntax::{ | |||
8 | }; | 8 | }; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | Const, TypeAlias, Function, HirFileId, AstDatabase, | 11 | Const, TypeAlias, Function, HirFileId, AstDatabase, HasSource, Source, |
12 | HirDatabase, DefDatabase, TraitRef, | 12 | HirDatabase, DefDatabase, TraitRef, |
13 | type_ref::TypeRef, | 13 | type_ref::TypeRef, |
14 | ids::LocationCtx, | 14 | ids::LocationCtx, |
@@ -44,6 +44,15 @@ pub struct ImplBlock { | |||
44 | impl_id: ImplId, | 44 | impl_id: ImplId, |
45 | } | 45 | } |
46 | 46 | ||
47 | impl HasSource for ImplBlock { | ||
48 | type Ast = TreeArc<ast::ImplBlock>; | ||
49 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ImplBlock>> { | ||
50 | let source_map = db.impls_in_module_with_source_map(self.module).1; | ||
51 | let src = self.module.definition_source(db); | ||
52 | Source { file_id: src.file_id, ast: source_map.get(&src.ast, self.impl_id) } | ||
53 | } | ||
54 | } | ||
55 | |||
47 | impl ImplBlock { | 56 | impl ImplBlock { |
48 | pub(crate) fn containing( | 57 | pub(crate) fn containing( |
49 | module_impl_blocks: Arc<ModuleImplBlocks>, | 58 | module_impl_blocks: Arc<ModuleImplBlocks>, |
@@ -57,16 +66,6 @@ impl ImplBlock { | |||
57 | ImplBlock { module, impl_id } | 66 | ImplBlock { module, impl_id } |
58 | } | 67 | } |
59 | 68 | ||
60 | /// Returns the syntax of the impl block | ||
61 | pub fn source( | ||
62 | &self, | ||
63 | db: &(impl DefDatabase + AstDatabase), | ||
64 | ) -> (HirFileId, TreeArc<ast::ImplBlock>) { | ||
65 | let source_map = db.impls_in_module_with_source_map(self.module).1; | ||
66 | let (file_id, source) = self.module.definition_source(db); | ||
67 | (file_id, source_map.get(&source, self.impl_id)) | ||
68 | } | ||
69 | |||
70 | pub fn id(&self) -> ImplId { | 69 | pub fn id(&self) -> ImplId { |
71 | self.impl_id | 70 | self.impl_id |
72 | } | 71 | } |
@@ -201,8 +200,8 @@ impl ModuleImplBlocks { | |||
201 | impls_by_def: FxHashMap::default(), | 200 | impls_by_def: FxHashMap::default(), |
202 | }; | 201 | }; |
203 | 202 | ||
204 | let (file_id, module_source) = m.module.definition_source(db); | 203 | let src = m.module.definition_source(db); |
205 | let node = match &module_source { | 204 | let node = match &src.ast { |
206 | ModuleSource::SourceFile(node) => node.syntax(), | 205 | ModuleSource::SourceFile(node) => node.syntax(), |
207 | ModuleSource::Module(node) => { | 206 | ModuleSource::Module(node) => { |
208 | node.item_list().expect("inline module should have item list").syntax() | 207 | node.item_list().expect("inline module should have item list").syntax() |
@@ -210,7 +209,7 @@ impl ModuleImplBlocks { | |||
210 | }; | 209 | }; |
211 | 210 | ||
212 | for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) { | 211 | for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) { |
213 | let impl_block = ImplData::from_ast(db, file_id, m.module, impl_block_ast); | 212 | let impl_block = ImplData::from_ast(db, src.file_id, m.module, impl_block_ast); |
214 | let id = m.impls.alloc(impl_block); | 213 | let id = m.impls.alloc(impl_block); |
215 | for &impl_item in &m.impls[id].items { | 214 | for &impl_item in &m.impls[id].items { |
216 | m.impls_by_def.insert(impl_item, id); | 215 | m.impls_by_def.insert(impl_item, id); |
diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs index 684fbc068..cdc9182d6 100644 --- a/crates/ra_hir/src/lang_item.rs +++ b/crates/ra_hir/src/lang_item.rs | |||
@@ -84,7 +84,7 @@ impl LangItems { | |||
84 | ) { | 84 | ) { |
85 | // Look for impl targets | 85 | // Look for impl targets |
86 | let (impl_blocks, source_map) = db.impls_in_module_with_source_map(module.clone()); | 86 | let (impl_blocks, source_map) = db.impls_in_module_with_source_map(module.clone()); |
87 | let source = module.definition_source(db).1; | 87 | let source = module.definition_source(db).ast; |
88 | for (impl_id, _) in impl_blocks.impls.iter() { | 88 | for (impl_id, _) in impl_blocks.impls.iter() { |
89 | let impl_block = source_map.get(&source, impl_id); | 89 | let impl_block = source_map.get(&source, impl_id); |
90 | let lang_item_name = impl_block | 90 | let lang_item_name = impl_block |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 0e4aaf678..2e99bdac8 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -38,7 +38,6 @@ mod impl_block; | |||
38 | mod expr; | 38 | mod expr; |
39 | mod lang_item; | 39 | mod lang_item; |
40 | mod generics; | 40 | mod generics; |
41 | mod docs; | ||
42 | mod resolve; | 41 | mod resolve; |
43 | pub mod diagnostics; | 42 | pub mod diagnostics; |
44 | 43 | ||
@@ -64,7 +63,6 @@ pub use self::{ | |||
64 | nameres::{PerNs, Namespace, ImportId}, | 63 | nameres::{PerNs, Namespace, ImportId}, |
65 | ty::{Ty, ApplicationTy, TypeCtor, TraitRef, Substs, display::HirDisplay, CallableDef}, | 64 | ty::{Ty, ApplicationTy, TypeCtor, TraitRef, Substs, display::HirDisplay, CallableDef}, |
66 | impl_block::{ImplBlock, ImplItem}, | 65 | impl_block::{ImplBlock, ImplItem}, |
67 | docs::{Docs, Documentation}, | ||
68 | adt::AdtDef, | 66 | adt::AdtDef, |
69 | expr::ExprScopes, | 67 | expr::ExprScopes, |
70 | resolve::Resolution, | 68 | resolve::Resolution, |
@@ -82,4 +80,6 @@ pub use self::code_model::{ | |||
82 | Static, Const, ConstSignature, | 80 | Static, Const, ConstSignature, |
83 | Trait, TypeAlias, MacroDef, Container, | 81 | Trait, TypeAlias, MacroDef, Container, |
84 | BuiltinType, | 82 | BuiltinType, |
83 | src::{Source, HasSource}, | ||
84 | docs::{Docs, Documentation, DocDef}, | ||
85 | }; | 85 | }; |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 876ebe0e3..4f9e8c5a9 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -97,13 +97,13 @@ pub fn struct_from_module( | |||
97 | module: Module, | 97 | module: Module, |
98 | struct_def: &ast::StructDef, | 98 | struct_def: &ast::StructDef, |
99 | ) -> Struct { | 99 | ) -> Struct { |
100 | let (file_id, _) = module.definition_source(db); | 100 | let file_id = module.definition_source(db).file_id; |
101 | let ctx = LocationCtx::new(db, module, file_id); | 101 | let ctx = LocationCtx::new(db, module, file_id); |
102 | Struct { id: ctx.to_def(struct_def) } | 102 | Struct { id: ctx.to_def(struct_def) } |
103 | } | 103 | } |
104 | 104 | ||
105 | pub fn enum_from_module(db: &impl HirDatabase, module: Module, enum_def: &ast::EnumDef) -> Enum { | 105 | pub fn enum_from_module(db: &impl HirDatabase, module: Module, enum_def: &ast::EnumDef) -> Enum { |
106 | let (file_id, _) = module.definition_source(db); | 106 | let file_id = module.definition_source(db).file_id; |
107 | let ctx = LocationCtx::new(db, module, file_id); | 107 | let ctx = LocationCtx::new(db, module, file_id); |
108 | Enum { id: ctx.to_def(enum_def) } | 108 | Enum { id: ctx.to_def(enum_def) } |
109 | } | 109 | } |
@@ -113,7 +113,7 @@ pub fn trait_from_module( | |||
113 | module: Module, | 113 | module: Module, |
114 | trait_def: &ast::TraitDef, | 114 | trait_def: &ast::TraitDef, |
115 | ) -> Trait { | 115 | ) -> Trait { |
116 | let (file_id, _) = module.definition_source(db); | 116 | let file_id = module.definition_source(db).file_id; |
117 | let ctx = LocationCtx::new(db, module, file_id); | 117 | let ctx = LocationCtx::new(db, module, file_id); |
118 | Trait { id: ctx.to_def(trait_def) } | 118 | Trait { id: ctx.to_def(trait_def) } |
119 | } | 119 | } |
diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs index 967654e97..f2950e1b2 100644 --- a/crates/ra_hir/src/traits.rs +++ b/crates/ra_hir/src/traits.rs | |||
@@ -6,7 +6,7 @@ use rustc_hash::FxHashMap; | |||
6 | use ra_syntax::ast::{self, NameOwner}; | 6 | use ra_syntax::ast::{self, NameOwner}; |
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | Function, Const, TypeAlias, Name, DefDatabase, Trait, AstDatabase, Module, | 9 | Function, Const, TypeAlias, Name, DefDatabase, Trait, AstDatabase, Module, HasSource, |
10 | ids::LocationCtx, name::AsName, | 10 | ids::LocationCtx, name::AsName, |
11 | }; | 11 | }; |
12 | 12 | ||
@@ -22,12 +22,12 @@ impl TraitData { | |||
22 | db: &(impl DefDatabase + AstDatabase), | 22 | db: &(impl DefDatabase + AstDatabase), |
23 | tr: Trait, | 23 | tr: Trait, |
24 | ) -> Arc<TraitData> { | 24 | ) -> Arc<TraitData> { |
25 | let (file_id, node) = tr.source(db); | 25 | let src = tr.source(db); |
26 | let name = node.name().map(|n| n.as_name()); | 26 | let name = src.ast.name().map(|n| n.as_name()); |
27 | let module = tr.module(db); | 27 | let module = tr.module(db); |
28 | let ctx = LocationCtx::new(db, module, file_id); | 28 | let ctx = LocationCtx::new(db, module, src.file_id); |
29 | let auto = node.is_auto(); | 29 | let auto = src.ast.is_auto(); |
30 | let items = if let Some(item_list) = node.item_list() { | 30 | let items = if let Some(item_list) = src.ast.item_list() { |
31 | item_list | 31 | item_list |
32 | .impl_items() | 32 | .impl_items() |
33 | .map(|item_node| match item_node.kind() { | 33 | .map(|item_node| match item_node.kind() { |
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 6aa727ea1..fef0f1d24 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -1415,7 +1415,7 @@ mod diagnostics { | |||
1415 | use crate::{ | 1415 | use crate::{ |
1416 | expr::ExprId, | 1416 | expr::ExprId, |
1417 | diagnostics::{DiagnosticSink, NoSuchField}, | 1417 | diagnostics::{DiagnosticSink, NoSuchField}, |
1418 | HirDatabase, Function, | 1418 | HirDatabase, Function, HasSource, |
1419 | }; | 1419 | }; |
1420 | 1420 | ||
1421 | #[derive(Debug, PartialEq, Eq, Clone)] | 1421 | #[derive(Debug, PartialEq, Eq, Clone)] |
@@ -1432,7 +1432,7 @@ mod diagnostics { | |||
1432 | ) { | 1432 | ) { |
1433 | match self { | 1433 | match self { |
1434 | InferenceDiagnostic::NoSuchField { expr, field } => { | 1434 | InferenceDiagnostic::NoSuchField { expr, field } => { |
1435 | let (file, _) = owner.source(db); | 1435 | let file = owner.source(db).file_id; |
1436 | let field = owner.body_source_map(db).field_syntax(*expr, *field); | 1436 | let field = owner.body_source_map(db).field_syntax(*expr, *field); |
1437 | sink.push(NoSuchField { file, field }) | 1437 | sink.push(NoSuchField { file, field }) |
1438 | } | 1438 | } |
diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs index 970468e3c..87b9caa8a 100644 --- a/crates/ra_hir/src/type_alias.rs +++ b/crates/ra_hir/src/type_alias.rs | |||
@@ -2,12 +2,12 @@ | |||
2 | 2 | ||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use crate::{TypeAlias, DefDatabase, AstDatabase, type_ref::TypeRef}; | 5 | use crate::{TypeAlias, DefDatabase, AstDatabase, HasSource, type_ref::TypeRef}; |
6 | 6 | ||
7 | pub(crate) fn type_alias_ref_query( | 7 | pub(crate) fn type_alias_ref_query( |
8 | db: &(impl DefDatabase + AstDatabase), | 8 | db: &(impl DefDatabase + AstDatabase), |
9 | typ: TypeAlias, | 9 | typ: TypeAlias, |
10 | ) -> Arc<TypeRef> { | 10 | ) -> Arc<TypeRef> { |
11 | let (_, node) = typ.source(db); | 11 | let node = typ.source(db).ast; |
12 | Arc::new(TypeRef::from_ast_opt(node.type_ref())) | 12 | Arc::new(TypeRef::from_ast_opt(node.type_ref())) |
13 | } | 13 | } |