diff options
28 files changed, 236 insertions, 262 deletions
diff --git a/crates/ra_assists/src/test_db.rs b/crates/ra_assists/src/test_db.rs index 5be7383ed..5f96c974b 100644 --- a/crates/ra_assists/src/test_db.rs +++ b/crates/ra_assists/src/test_db.rs | |||
@@ -10,7 +10,6 @@ use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath | |||
10 | hir::db::InternDatabaseStorage, | 10 | hir::db::InternDatabaseStorage, |
11 | hir::db::AstDatabaseStorage, | 11 | hir::db::AstDatabaseStorage, |
12 | hir::db::DefDatabaseStorage, | 12 | hir::db::DefDatabaseStorage, |
13 | hir::db::DefDatabase2Storage, | ||
14 | hir::db::HirDatabaseStorage | 13 | hir::db::HirDatabaseStorage |
15 | )] | 14 | )] |
16 | #[derive(Debug, Default)] | 15 | #[derive(Debug, Default)] |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 496b4ee8a..4b3ec5457 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | pub(crate) mod src; | 3 | pub(crate) mod src; |
4 | pub(crate) mod docs; | ||
5 | 4 | ||
6 | use std::sync::Arc; | 5 | use std::sync::Arc; |
7 | 6 | ||
@@ -9,11 +8,12 @@ use hir_def::{ | |||
9 | adt::VariantData, | 8 | adt::VariantData, |
10 | body::scope::ExprScopes, | 9 | body::scope::ExprScopes, |
11 | builtin_type::BuiltinType, | 10 | builtin_type::BuiltinType, |
11 | docs::Documentation, | ||
12 | nameres::per_ns::PerNs, | 12 | nameres::per_ns::PerNs, |
13 | resolver::{HasResolver, TypeNs}, | 13 | resolver::{HasResolver, TypeNs}, |
14 | type_ref::TypeRef, | 14 | type_ref::TypeRef, |
15 | AdtId, ContainerId, CrateModuleId, EnumVariantId, HasModule, ImplId, LocalEnumVariantId, | 15 | ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup, |
16 | LocalStructFieldId, Lookup, ModuleId, StructFieldId, UnionId, | 16 | ModuleId, UnionId, |
17 | }; | 17 | }; |
18 | use hir_expand::{ | 18 | use hir_expand::{ |
19 | diagnostics::DiagnosticSink, | 19 | diagnostics::DiagnosticSink, |
@@ -1024,18 +1024,17 @@ pub trait HasAttrs { | |||
1024 | 1024 | ||
1025 | impl<T: Into<AttrDef>> HasAttrs for T { | 1025 | impl<T: Into<AttrDef>> HasAttrs for T { |
1026 | fn attrs(self, db: &impl DefDatabase) -> Attrs { | 1026 | fn attrs(self, db: &impl DefDatabase) -> Attrs { |
1027 | let def = self.into(); | 1027 | let def: AttrDef = self.into(); |
1028 | match def { | 1028 | db.attrs(def.into()) |
1029 | AttrDef::Module(it) => db.attrs(it.id.into()), | 1029 | } |
1030 | AttrDef::StructField(it) => db.attrs(StructFieldId::from(it).into()), | 1030 | } |
1031 | AttrDef::Adt(it) => db.attrs(AdtId::from(it).into()), | 1031 | |
1032 | AttrDef::Function(it) => db.attrs(it.id.into()), | 1032 | pub trait Docs { |
1033 | AttrDef::EnumVariant(it) => db.attrs(EnumVariantId::from(it).into()), | 1033 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation>; |
1034 | AttrDef::Static(it) => db.attrs(it.id.into()), | 1034 | } |
1035 | AttrDef::Const(it) => db.attrs(it.id.into()), | 1035 | impl<T: Into<AttrDef> + Copy> Docs for T { |
1036 | AttrDef::Trait(it) => db.attrs(it.id.into()), | 1036 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { |
1037 | AttrDef::TypeAlias(it) => db.attrs(it.id.into()), | 1037 | let def: AttrDef = (*self).into(); |
1038 | AttrDef::MacroDef(it) => db.attrs(it.id.into()), | 1038 | db.documentation(def.into()) |
1039 | } | ||
1040 | } | 1039 | } |
1041 | } | 1040 | } |
diff --git a/crates/ra_hir/src/code_model/docs.rs b/crates/ra_hir/src/code_model/docs.rs deleted file mode 100644 index e40efef34..000000000 --- a/crates/ra_hir/src/code_model/docs.rs +++ /dev/null | |||
@@ -1,97 +0,0 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use std::sync::Arc; | ||
4 | |||
5 | use ra_syntax::ast; | ||
6 | |||
7 | use crate::{ | ||
8 | db::{AstDatabase, DefDatabase, HirDatabase}, | ||
9 | Adt, Const, Enum, EnumVariant, FieldSource, Function, HasSource, MacroDef, Module, Static, | ||
10 | Struct, StructField, Trait, TypeAlias, Union, | ||
11 | }; | ||
12 | |||
13 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
14 | pub enum DocDef { | ||
15 | Module(Module), | ||
16 | StructField(StructField), | ||
17 | Adt(Adt), | ||
18 | EnumVariant(EnumVariant), | ||
19 | Static(Static), | ||
20 | Const(Const), | ||
21 | Function(Function), | ||
22 | Trait(Trait), | ||
23 | TypeAlias(TypeAlias), | ||
24 | MacroDef(MacroDef), | ||
25 | } | ||
26 | |||
27 | impl_froms!( | ||
28 | DocDef: Module, | ||
29 | StructField, | ||
30 | Adt(Struct, Enum, Union), | ||
31 | EnumVariant, | ||
32 | Static, | ||
33 | Const, | ||
34 | Function, | ||
35 | Trait, | ||
36 | TypeAlias, | ||
37 | MacroDef | ||
38 | ); | ||
39 | |||
40 | /// Holds documentation | ||
41 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
42 | pub struct Documentation(Arc<str>); | ||
43 | |||
44 | impl Documentation { | ||
45 | fn new(s: &str) -> Documentation { | ||
46 | Documentation(s.into()) | ||
47 | } | ||
48 | |||
49 | pub fn as_str(&self) -> &str { | ||
50 | &*self.0 | ||
51 | } | ||
52 | } | ||
53 | |||
54 | impl Into<String> for Documentation { | ||
55 | fn into(self) -> String { | ||
56 | self.as_str().to_owned() | ||
57 | } | ||
58 | } | ||
59 | |||
60 | pub trait Docs { | ||
61 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation>; | ||
62 | } | ||
63 | |||
64 | pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option<Documentation> { | ||
65 | node.doc_comment_text().map(|it| Documentation::new(&it)) | ||
66 | } | ||
67 | |||
68 | pub(crate) fn documentation_query( | ||
69 | db: &(impl DefDatabase + AstDatabase), | ||
70 | def: DocDef, | ||
71 | ) -> Option<Documentation> { | ||
72 | match def { | ||
73 | DocDef::Module(it) => docs_from_ast(&it.declaration_source(db)?.value), | ||
74 | DocDef::StructField(it) => match it.source(db).value { | ||
75 | FieldSource::Named(named) => docs_from_ast(&named), | ||
76 | FieldSource::Pos(..) => None, | ||
77 | }, | ||
78 | DocDef::Adt(it) => match it { | ||
79 | Adt::Struct(it) => docs_from_ast(&it.source(db).value), | ||
80 | Adt::Enum(it) => docs_from_ast(&it.source(db).value), | ||
81 | Adt::Union(it) => docs_from_ast(&it.source(db).value), | ||
82 | }, | ||
83 | DocDef::EnumVariant(it) => docs_from_ast(&it.source(db).value), | ||
84 | DocDef::Static(it) => docs_from_ast(&it.source(db).value), | ||
85 | DocDef::Const(it) => docs_from_ast(&it.source(db).value), | ||
86 | DocDef::Function(it) => docs_from_ast(&it.source(db).value), | ||
87 | DocDef::Trait(it) => docs_from_ast(&it.source(db).value), | ||
88 | DocDef::TypeAlias(it) => docs_from_ast(&it.source(db).value), | ||
89 | DocDef::MacroDef(it) => docs_from_ast(&it.source(db).value), | ||
90 | } | ||
91 | } | ||
92 | |||
93 | impl<T: Into<DocDef> + Copy> Docs for T { | ||
94 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { | ||
95 | db.documentation((*self).into()) | ||
96 | } | ||
97 | } | ||
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index cae305f98..399101b83 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -5,7 +5,6 @@ use std::sync::Arc; | |||
5 | use ra_db::salsa; | 5 | use ra_db::salsa; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | debug::HirDebugDatabase, | ||
9 | ids, | 8 | ids, |
10 | ty::{ | 9 | ty::{ |
11 | method_resolution::CrateImplBlocks, | 10 | method_resolution::CrateImplBlocks, |
@@ -18,24 +17,16 @@ use crate::{ | |||
18 | 17 | ||
19 | pub use hir_def::db::{ | 18 | pub use hir_def::db::{ |
20 | BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery, | 19 | BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery, |
21 | DefDatabase2, DefDatabase2Storage, EnumDataQuery, ExprScopesQuery, FunctionDataQuery, | 20 | DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery, ExprScopesQuery, |
22 | GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage, LangItemQuery, | 21 | FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage, |
23 | ModuleLangItemsQuery, RawItemsQuery, RawItemsWithSourceMapQuery, StaticDataQuery, | 22 | LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, RawItemsWithSourceMapQuery, |
24 | StructDataQuery, TraitDataQuery, TypeAliasDataQuery, | 23 | StaticDataQuery, StructDataQuery, TraitDataQuery, TypeAliasDataQuery, |
25 | }; | 24 | }; |
26 | pub use hir_expand::db::{ | 25 | pub use hir_expand::db::{ |
27 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, | 26 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, |
28 | ParseMacroQuery, | 27 | ParseMacroQuery, |
29 | }; | 28 | }; |
30 | 29 | ||
31 | // This database uses `AstDatabase` internally, | ||
32 | #[salsa::query_group(DefDatabaseStorage)] | ||
33 | #[salsa::requires(AstDatabase)] | ||
34 | pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { | ||
35 | #[salsa::invoke(crate::code_model::docs::documentation_query)] | ||
36 | fn documentation(&self, def: crate::DocDef) -> Option<crate::Documentation>; | ||
37 | } | ||
38 | |||
39 | #[salsa::query_group(HirDatabaseStorage)] | 30 | #[salsa::query_group(HirDatabaseStorage)] |
40 | #[salsa::requires(salsa::Database)] | 31 | #[salsa::requires(salsa::Database)] |
41 | pub trait HirDatabase: DefDatabase + AstDatabase { | 32 | pub trait HirDatabase: DefDatabase + AstDatabase { |
diff --git a/crates/ra_hir/src/debug.rs b/crates/ra_hir/src/debug.rs index 4f3e922c3..8ec371f6e 100644 --- a/crates/ra_hir/src/debug.rs +++ b/crates/ra_hir/src/debug.rs | |||
@@ -1,3 +1,5 @@ | |||
1 | //! XXX: This does not work at the moment. | ||
2 | //! | ||
1 | //! printf debugging infrastructure for rust-analyzer. | 3 | //! printf debugging infrastructure for rust-analyzer. |
2 | //! | 4 | //! |
3 | //! When you print a hir type, like a module, using `eprintln!("{:?}", module)`, | 5 | //! When you print a hir type, like a module, using `eprintln!("{:?}", module)`, |
diff --git a/crates/ra_hir/src/from_id.rs b/crates/ra_hir/src/from_id.rs index 5d7af00ab..529ac8251 100644 --- a/crates/ra_hir/src/from_id.rs +++ b/crates/ra_hir/src/from_id.rs | |||
@@ -4,14 +4,14 @@ | |||
4 | //! are splitting the hir. | 4 | //! are splitting the hir. |
5 | 5 | ||
6 | use hir_def::{ | 6 | use hir_def::{ |
7 | AdtId, AssocItemId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId, | 7 | AdtId, AssocItemId, AttrDefId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, |
8 | ModuleDefId, StaticId, StructFieldId, StructId, TypeAliasId, UnionId, VariantId, | 8 | GenericDefId, ModuleDefId, StaticId, StructFieldId, StructId, TypeAliasId, UnionId, VariantId, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | ty::{CallableDef, TypableDef}, | 12 | ty::{CallableDef, TypableDef}, |
13 | Adt, AssocItem, Const, Crate, DefWithBody, EnumVariant, Function, GenericDef, ModuleDef, | 13 | Adt, AssocItem, AttrDef, Const, Crate, DefWithBody, EnumVariant, Function, GenericDef, |
14 | Static, StructField, TypeAlias, VariantDef, | 14 | ModuleDef, Static, StructField, TypeAlias, VariantDef, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | impl From<ra_db::CrateId> for Crate { | 17 | impl From<ra_db::CrateId> for Crate { |
@@ -240,3 +240,20 @@ impl From<StructField> for StructFieldId { | |||
240 | StructFieldId { parent: def.parent.into(), local_id: def.id } | 240 | StructFieldId { parent: def.parent.into(), local_id: def.id } |
241 | } | 241 | } |
242 | } | 242 | } |
243 | |||
244 | impl From<AttrDef> for AttrDefId { | ||
245 | fn from(def: AttrDef) -> Self { | ||
246 | match def { | ||
247 | AttrDef::Module(it) => AttrDefId::ModuleId(it.id), | ||
248 | AttrDef::StructField(it) => AttrDefId::StructFieldId(it.into()), | ||
249 | AttrDef::Adt(it) => AttrDefId::AdtId(it.into()), | ||
250 | AttrDef::Function(it) => AttrDefId::FunctionId(it.id), | ||
251 | AttrDef::EnumVariant(it) => AttrDefId::EnumVariantId(it.into()), | ||
252 | AttrDef::Static(it) => AttrDefId::StaticId(it.id), | ||
253 | AttrDef::Const(it) => AttrDefId::ConstId(it.id), | ||
254 | AttrDef::Trait(it) => AttrDefId::TraitId(it.id), | ||
255 | AttrDef::TypeAlias(it) => AttrDefId::TypeAliasId(it.id), | ||
256 | AttrDef::MacroDef(it) => AttrDefId::MacroDefId(it.id), | ||
257 | } | ||
258 | } | ||
259 | } | ||
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 22da05a97..868df5b6b 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -50,9 +50,8 @@ mod marks; | |||
50 | 50 | ||
51 | pub use crate::{ | 51 | pub use crate::{ |
52 | code_model::{ | 52 | code_model::{ |
53 | docs::{DocDef, Docs, Documentation}, | ||
54 | src::{HasBodySource, HasSource}, | 53 | src::{HasBodySource, HasSource}, |
55 | Adt, AssocItem, AttrDef, Const, Container, Crate, CrateDependency, DefWithBody, Enum, | 54 | Adt, AssocItem, AttrDef, Const, Container, Crate, CrateDependency, DefWithBody, Docs, Enum, |
56 | EnumVariant, FieldSource, Function, GenericDef, GenericParam, HasAttrs, HasBody, ImplBlock, | 55 | EnumVariant, FieldSource, Function, GenericDef, GenericParam, HasAttrs, HasBody, ImplBlock, |
57 | Local, MacroDef, Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, | 56 | Local, MacroDef, Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, |
58 | Trait, TypeAlias, Union, VariantDef, | 57 | Trait, TypeAlias, Union, VariantDef, |
@@ -70,6 +69,7 @@ pub use crate::{ | |||
70 | 69 | ||
71 | pub use hir_def::{ | 70 | pub use hir_def::{ |
72 | builtin_type::BuiltinType, | 71 | builtin_type::BuiltinType, |
72 | docs::Documentation, | ||
73 | nameres::{per_ns::PerNs, raw::ImportId}, | 73 | nameres::{per_ns::PerNs, raw::ImportId}, |
74 | path::{Path, PathKind}, | 74 | path::{Path, PathKind}, |
75 | type_ref::Mutability, | 75 | type_ref::Mutability, |
diff --git a/crates/ra_hir/src/test_db.rs b/crates/ra_hir/src/test_db.rs index 1caa2e875..03c7ac155 100644 --- a/crates/ra_hir/src/test_db.rs +++ b/crates/ra_hir/src/test_db.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use std::{panic, sync::Arc}; | 3 | use std::{panic, sync::Arc}; |
4 | 4 | ||
5 | use hir_def::{db::DefDatabase2, ModuleId}; | 5 | use hir_def::{db::DefDatabase, ModuleId}; |
6 | use hir_expand::diagnostics::DiagnosticSink; | 6 | use hir_expand::diagnostics::DiagnosticSink; |
7 | use parking_lot::Mutex; | 7 | use parking_lot::Mutex; |
8 | use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, SourceDatabase}; | 8 | use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, SourceDatabase}; |
@@ -15,7 +15,6 @@ use crate::{db, debug::HirDebugHelper}; | |||
15 | db::InternDatabaseStorage, | 15 | db::InternDatabaseStorage, |
16 | db::AstDatabaseStorage, | 16 | db::AstDatabaseStorage, |
17 | db::DefDatabaseStorage, | 17 | db::DefDatabaseStorage, |
18 | db::DefDatabase2Storage, | ||
19 | db::HirDatabaseStorage | 18 | db::HirDatabaseStorage |
20 | )] | 19 | )] |
21 | #[derive(Debug, Default)] | 20 | #[derive(Debug, Default)] |
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index ae99afe39..20e9a1eb5 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs | |||
@@ -11,7 +11,7 @@ use ra_arena::{map::ArenaMap, Arena}; | |||
11 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | 11 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | db::DefDatabase2, trace::Trace, type_ref::TypeRef, AstItemDef, EnumId, HasChildSource, | 14 | db::DefDatabase, trace::Trace, type_ref::TypeRef, AstItemDef, EnumId, HasChildSource, |
15 | LocalEnumVariantId, LocalStructFieldId, StructOrUnionId, VariantId, | 15 | LocalEnumVariantId, LocalStructFieldId, StructOrUnionId, VariantId, |
16 | }; | 16 | }; |
17 | 17 | ||
@@ -49,10 +49,7 @@ pub struct StructFieldData { | |||
49 | } | 49 | } |
50 | 50 | ||
51 | impl StructData { | 51 | impl StructData { |
52 | pub(crate) fn struct_data_query( | 52 | pub(crate) fn struct_data_query(db: &impl DefDatabase, id: StructOrUnionId) -> Arc<StructData> { |
53 | db: &impl DefDatabase2, | ||
54 | id: StructOrUnionId, | ||
55 | ) -> Arc<StructData> { | ||
56 | let src = id.source(db); | 53 | let src = id.source(db); |
57 | let name = src.value.name().map(|n| n.as_name()); | 54 | let name = src.value.name().map(|n| n.as_name()); |
58 | let variant_data = VariantData::new(src.value.kind()); | 55 | let variant_data = VariantData::new(src.value.kind()); |
@@ -62,7 +59,7 @@ impl StructData { | |||
62 | } | 59 | } |
63 | 60 | ||
64 | impl EnumData { | 61 | impl EnumData { |
65 | pub(crate) fn enum_data_query(db: &impl DefDatabase2, e: EnumId) -> Arc<EnumData> { | 62 | pub(crate) fn enum_data_query(db: &impl DefDatabase, e: EnumId) -> Arc<EnumData> { |
66 | let src = e.source(db); | 63 | let src = e.source(db); |
67 | let name = src.value.name().map(|n| n.as_name()); | 64 | let name = src.value.name().map(|n| n.as_name()); |
68 | let mut trace = Trace::new_for_arena(); | 65 | let mut trace = Trace::new_for_arena(); |
@@ -79,7 +76,7 @@ impl EnumData { | |||
79 | impl HasChildSource for EnumId { | 76 | impl HasChildSource for EnumId { |
80 | type ChildId = LocalEnumVariantId; | 77 | type ChildId = LocalEnumVariantId; |
81 | type Value = ast::EnumVariant; | 78 | type Value = ast::EnumVariant; |
82 | fn child_source(&self, db: &impl DefDatabase2) -> Source<ArenaMap<Self::ChildId, Self::Value>> { | 79 | fn child_source(&self, db: &impl DefDatabase) -> Source<ArenaMap<Self::ChildId, Self::Value>> { |
83 | let src = self.source(db); | 80 | let src = self.source(db); |
84 | let mut trace = Trace::new_for_map(); | 81 | let mut trace = Trace::new_for_map(); |
85 | lower_enum(&mut trace, &src.value); | 82 | lower_enum(&mut trace, &src.value); |
@@ -124,7 +121,7 @@ impl HasChildSource for VariantId { | |||
124 | type ChildId = LocalStructFieldId; | 121 | type ChildId = LocalStructFieldId; |
125 | type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>; | 122 | type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>; |
126 | 123 | ||
127 | fn child_source(&self, db: &impl DefDatabase2) -> Source<ArenaMap<Self::ChildId, Self::Value>> { | 124 | fn child_source(&self, db: &impl DefDatabase) -> Source<ArenaMap<Self::ChildId, Self::Value>> { |
128 | let src = match self { | 125 | let src = match self { |
129 | VariantId::EnumVariantId(it) => { | 126 | VariantId::EnumVariantId(it) => { |
130 | // I don't really like the fact that we call into parent source | 127 | // I don't really like the fact that we call into parent source |
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index eee5e44bf..48ce8cd93 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs | |||
@@ -12,7 +12,7 @@ use ra_syntax::{ | |||
12 | use tt::Subtree; | 12 | use tt::Subtree; |
13 | 13 | ||
14 | use crate::{ | 14 | use crate::{ |
15 | db::DefDatabase2, path::Path, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup, | 15 | db::DefDatabase, path::Path, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | #[derive(Default, Debug, Clone, PartialEq, Eq)] | 18 | #[derive(Default, Debug, Clone, PartialEq, Eq)] |
@@ -32,7 +32,7 @@ impl ops::Deref for Attrs { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | impl Attrs { | 34 | impl Attrs { |
35 | pub(crate) fn attrs_query(db: &impl DefDatabase2, def: AttrDefId) -> Attrs { | 35 | pub(crate) fn attrs_query(db: &impl DefDatabase, def: AttrDefId) -> Attrs { |
36 | match def { | 36 | match def { |
37 | AttrDefId::ModuleId(module) => { | 37 | AttrDefId::ModuleId(module) => { |
38 | let def_map = db.crate_def_map(module.krate); | 38 | let def_map = db.crate_def_map(module.krate); |
@@ -162,7 +162,7 @@ impl Attr { | |||
162 | fn attrs_from_ast<D, N>(src: AstId<N>, db: &D) -> Attrs | 162 | fn attrs_from_ast<D, N>(src: AstId<N>, db: &D) -> Attrs |
163 | where | 163 | where |
164 | N: ast::AttrsOwner, | 164 | N: ast::AttrsOwner, |
165 | D: DefDatabase2, | 165 | D: DefDatabase, |
166 | { | 166 | { |
167 | let hygiene = Hygiene::new(db, src.file_id()); | 167 | let hygiene = Hygiene::new(db, src.file_id()); |
168 | Attr::from_attrs_owner(&src.to_node(db), &hygiene) | 168 | Attr::from_attrs_owner(&src.to_node(db), &hygiene) |
@@ -172,7 +172,7 @@ fn attrs_from_loc<T, D>(node: T, db: &D) -> Attrs | |||
172 | where | 172 | where |
173 | T: HasSource, | 173 | T: HasSource, |
174 | T::Value: ast::AttrsOwner, | 174 | T::Value: ast::AttrsOwner, |
175 | D: DefDatabase2, | 175 | D: DefDatabase, |
176 | { | 176 | { |
177 | let src = node.source(db); | 177 | let src = node.source(db); |
178 | let hygiene = Hygiene::new(db, src.file_id); | 178 | let hygiene = Hygiene::new(db, src.file_id); |
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index dfb79a30a..225638b42 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs | |||
@@ -13,7 +13,7 @@ use ra_syntax::{ast, AstNode, AstPtr}; | |||
13 | use rustc_hash::FxHashMap; | 13 | use rustc_hash::FxHashMap; |
14 | 14 | ||
15 | use crate::{ | 15 | use crate::{ |
16 | db::DefDatabase2, | 16 | db::DefDatabase, |
17 | expr::{Expr, ExprId, Pat, PatId}, | 17 | expr::{Expr, ExprId, Pat, PatId}, |
18 | nameres::CrateDefMap, | 18 | nameres::CrateDefMap, |
19 | path::Path, | 19 | path::Path, |
@@ -28,7 +28,7 @@ pub struct Expander { | |||
28 | } | 28 | } |
29 | 29 | ||
30 | impl Expander { | 30 | impl Expander { |
31 | pub fn new(db: &impl DefDatabase2, current_file_id: HirFileId, module: ModuleId) -> Expander { | 31 | pub fn new(db: &impl DefDatabase, current_file_id: HirFileId, module: ModuleId) -> Expander { |
32 | let crate_def_map = db.crate_def_map(module.krate); | 32 | let crate_def_map = db.crate_def_map(module.krate); |
33 | let hygiene = Hygiene::new(db, current_file_id); | 33 | let hygiene = Hygiene::new(db, current_file_id); |
34 | Expander { crate_def_map, current_file_id, hygiene, module } | 34 | Expander { crate_def_map, current_file_id, hygiene, module } |
@@ -36,7 +36,7 @@ impl Expander { | |||
36 | 36 | ||
37 | fn enter_expand( | 37 | fn enter_expand( |
38 | &mut self, | 38 | &mut self, |
39 | db: &impl DefDatabase2, | 39 | db: &impl DefDatabase, |
40 | macro_call: ast::MacroCall, | 40 | macro_call: ast::MacroCall, |
41 | ) -> Option<(Mark, ast::Expr)> { | 41 | ) -> Option<(Mark, ast::Expr)> { |
42 | let ast_id = AstId::new( | 42 | let ast_id = AstId::new( |
@@ -67,7 +67,7 @@ impl Expander { | |||
67 | None | 67 | None |
68 | } | 68 | } |
69 | 69 | ||
70 | fn exit(&mut self, db: &impl DefDatabase2, mark: Mark) { | 70 | fn exit(&mut self, db: &impl DefDatabase, mark: Mark) { |
71 | self.hygiene = Hygiene::new(db, mark.file_id); | 71 | self.hygiene = Hygiene::new(db, mark.file_id); |
72 | self.current_file_id = mark.file_id; | 72 | self.current_file_id = mark.file_id; |
73 | std::mem::forget(mark); | 73 | std::mem::forget(mark); |
@@ -81,7 +81,7 @@ impl Expander { | |||
81 | Path::from_src(path, &self.hygiene) | 81 | Path::from_src(path, &self.hygiene) |
82 | } | 82 | } |
83 | 83 | ||
84 | fn resolve_path_as_macro(&self, db: &impl DefDatabase2, path: &Path) -> Option<MacroDefId> { | 84 | fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> { |
85 | self.crate_def_map.resolve_path(db, self.module.module_id, path).0.get_macros() | 85 | self.crate_def_map.resolve_path(db, self.module.module_id, path).0.get_macros() |
86 | } | 86 | } |
87 | } | 87 | } |
@@ -142,7 +142,7 @@ pub struct BodySourceMap { | |||
142 | 142 | ||
143 | impl Body { | 143 | impl Body { |
144 | pub(crate) fn body_with_source_map_query( | 144 | pub(crate) fn body_with_source_map_query( |
145 | db: &impl DefDatabase2, | 145 | db: &impl DefDatabase, |
146 | def: DefWithBodyId, | 146 | def: DefWithBodyId, |
147 | ) -> (Arc<Body>, Arc<BodySourceMap>) { | 147 | ) -> (Arc<Body>, Arc<BodySourceMap>) { |
148 | let mut params = None; | 148 | let mut params = None; |
@@ -169,12 +169,12 @@ impl Body { | |||
169 | (Arc::new(body), Arc::new(source_map)) | 169 | (Arc::new(body), Arc::new(source_map)) |
170 | } | 170 | } |
171 | 171 | ||
172 | pub(crate) fn body_query(db: &impl DefDatabase2, def: DefWithBodyId) -> Arc<Body> { | 172 | pub(crate) fn body_query(db: &impl DefDatabase, def: DefWithBodyId) -> Arc<Body> { |
173 | db.body_with_source_map(def).0 | 173 | db.body_with_source_map(def).0 |
174 | } | 174 | } |
175 | 175 | ||
176 | fn new( | 176 | fn new( |
177 | db: &impl DefDatabase2, | 177 | db: &impl DefDatabase, |
178 | expander: Expander, | 178 | expander: Expander, |
179 | params: Option<ast::ParamList>, | 179 | params: Option<ast::ParamList>, |
180 | body: Option<ast::Expr>, | 180 | body: Option<ast::Expr>, |
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index d8e911aa5..f4640dfa4 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -17,7 +17,7 @@ use test_utils::tested_by; | |||
17 | use crate::{ | 17 | use crate::{ |
18 | body::{Body, BodySourceMap, Expander, PatPtr}, | 18 | body::{Body, BodySourceMap, Expander, PatPtr}, |
19 | builtin_type::{BuiltinFloat, BuiltinInt}, | 19 | builtin_type::{BuiltinFloat, BuiltinInt}, |
20 | db::DefDatabase2, | 20 | db::DefDatabase, |
21 | expr::{ | 21 | expr::{ |
22 | ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, LogicOp, | 22 | ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, LogicOp, |
23 | MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, | 23 | MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, |
@@ -28,7 +28,7 @@ use crate::{ | |||
28 | }; | 28 | }; |
29 | 29 | ||
30 | pub(super) fn lower( | 30 | pub(super) fn lower( |
31 | db: &impl DefDatabase2, | 31 | db: &impl DefDatabase, |
32 | expander: Expander, | 32 | expander: Expander, |
33 | params: Option<ast::ParamList>, | 33 | params: Option<ast::ParamList>, |
34 | body: Option<ast::Expr>, | 34 | body: Option<ast::Expr>, |
@@ -57,7 +57,7 @@ struct ExprCollector<DB> { | |||
57 | 57 | ||
58 | impl<'a, DB> ExprCollector<&'a DB> | 58 | impl<'a, DB> ExprCollector<&'a DB> |
59 | where | 59 | where |
60 | DB: DefDatabase2, | 60 | DB: DefDatabase, |
61 | { | 61 | { |
62 | fn collect( | 62 | fn collect( |
63 | mut self, | 63 | mut self, |
diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs index 58740b679..20d707bc4 100644 --- a/crates/ra_hir_def/src/body/scope.rs +++ b/crates/ra_hir_def/src/body/scope.rs | |||
@@ -7,7 +7,7 @@ use rustc_hash::FxHashMap; | |||
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | body::Body, | 9 | body::Body, |
10 | db::DefDatabase2, | 10 | db::DefDatabase, |
11 | expr::{Expr, ExprId, Pat, PatId, Statement}, | 11 | expr::{Expr, ExprId, Pat, PatId, Statement}, |
12 | DefWithBodyId, | 12 | DefWithBodyId, |
13 | }; | 13 | }; |
@@ -45,7 +45,7 @@ pub struct ScopeData { | |||
45 | } | 45 | } |
46 | 46 | ||
47 | impl ExprScopes { | 47 | impl ExprScopes { |
48 | pub(crate) fn expr_scopes_query(db: &impl DefDatabase2, def: DefWithBodyId) -> Arc<ExprScopes> { | 48 | pub(crate) fn expr_scopes_query(db: &impl DefDatabase, def: DefWithBodyId) -> Arc<ExprScopes> { |
49 | let body = db.body(def); | 49 | let body = db.body(def); |
50 | Arc::new(ExprScopes::new(&*body)) | 50 | Arc::new(ExprScopes::new(&*body)) |
51 | } | 51 | } |
@@ -176,7 +176,7 @@ mod tests { | |||
176 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; | 176 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; |
177 | use test_utils::{assert_eq_text, covers, extract_offset}; | 177 | use test_utils::{assert_eq_text, covers, extract_offset}; |
178 | 178 | ||
179 | use crate::{db::DefDatabase2, test_db::TestDB, FunctionId, ModuleDefId}; | 179 | use crate::{db::DefDatabase, test_db::TestDB, FunctionId, ModuleDefId}; |
180 | 180 | ||
181 | fn find_function(db: &TestDB, file_id: FileId) -> FunctionId { | 181 | fn find_function(db: &TestDB, file_id: FileId) -> FunctionId { |
182 | let krate = db.test_crate(); | 182 | let krate = db.test_crate(); |
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 91bac7415..f0b3e198a 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs | |||
@@ -9,7 +9,7 @@ use hir_expand::{ | |||
9 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | 9 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | db::DefDatabase2, | 12 | db::DefDatabase, |
13 | type_ref::{Mutability, TypeRef}, | 13 | type_ref::{Mutability, TypeRef}, |
14 | AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource, | 14 | AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource, |
15 | ImplId, Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc, | 15 | ImplId, Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc, |
@@ -26,7 +26,7 @@ pub struct FunctionData { | |||
26 | } | 26 | } |
27 | 27 | ||
28 | impl FunctionData { | 28 | impl FunctionData { |
29 | pub(crate) fn fn_data_query(db: &impl DefDatabase2, func: FunctionId) -> Arc<FunctionData> { | 29 | pub(crate) fn fn_data_query(db: &impl DefDatabase, func: FunctionId) -> Arc<FunctionData> { |
30 | let src = func.lookup(db).source(db); | 30 | let src = func.lookup(db).source(db); |
31 | let name = src.value.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); | 31 | let name = src.value.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); |
32 | let mut params = Vec::new(); | 32 | let mut params = Vec::new(); |
@@ -74,7 +74,7 @@ pub struct TypeAliasData { | |||
74 | 74 | ||
75 | impl TypeAliasData { | 75 | impl TypeAliasData { |
76 | pub(crate) fn type_alias_data_query( | 76 | pub(crate) fn type_alias_data_query( |
77 | db: &impl DefDatabase2, | 77 | db: &impl DefDatabase, |
78 | typ: TypeAliasId, | 78 | typ: TypeAliasId, |
79 | ) -> Arc<TypeAliasData> { | 79 | ) -> Arc<TypeAliasData> { |
80 | let node = typ.lookup(db).source(db).value; | 80 | let node = typ.lookup(db).source(db).value; |
@@ -92,7 +92,7 @@ pub struct TraitData { | |||
92 | } | 92 | } |
93 | 93 | ||
94 | impl TraitData { | 94 | impl TraitData { |
95 | pub(crate) fn trait_data_query(db: &impl DefDatabase2, tr: TraitId) -> Arc<TraitData> { | 95 | pub(crate) fn trait_data_query(db: &impl DefDatabase, tr: TraitId) -> Arc<TraitData> { |
96 | let src = tr.source(db); | 96 | let src = tr.source(db); |
97 | let name = src.value.name().map(|n| n.as_name()); | 97 | let name = src.value.name().map(|n| n.as_name()); |
98 | let auto = src.value.is_auto(); | 98 | let auto = src.value.is_auto(); |
@@ -144,7 +144,7 @@ pub struct ImplData { | |||
144 | } | 144 | } |
145 | 145 | ||
146 | impl ImplData { | 146 | impl ImplData { |
147 | pub(crate) fn impl_data_query(db: &impl DefDatabase2, id: ImplId) -> Arc<ImplData> { | 147 | pub(crate) fn impl_data_query(db: &impl DefDatabase, id: ImplId) -> Arc<ImplData> { |
148 | let src = id.source(db); | 148 | let src = id.source(db); |
149 | let items = db.ast_id_map(src.file_id); | 149 | let items = db.ast_id_map(src.file_id); |
150 | 150 | ||
@@ -198,12 +198,12 @@ pub struct ConstData { | |||
198 | } | 198 | } |
199 | 199 | ||
200 | impl ConstData { | 200 | impl ConstData { |
201 | pub(crate) fn const_data_query(db: &impl DefDatabase2, konst: ConstId) -> Arc<ConstData> { | 201 | pub(crate) fn const_data_query(db: &impl DefDatabase, konst: ConstId) -> Arc<ConstData> { |
202 | let node = konst.lookup(db).source(db).value; | 202 | let node = konst.lookup(db).source(db).value; |
203 | const_data_for(&node) | 203 | const_data_for(&node) |
204 | } | 204 | } |
205 | 205 | ||
206 | pub(crate) fn static_data_query(db: &impl DefDatabase2, konst: StaticId) -> Arc<ConstData> { | 206 | pub(crate) fn static_data_query(db: &impl DefDatabase, konst: StaticId) -> Arc<ConstData> { |
207 | let node = konst.source(db).value; | 207 | let node = konst.source(db).value; |
208 | const_data_for(&node) | 208 | const_data_for(&node) |
209 | } | 209 | } |
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index e87bd525a..cf3a6ccd8 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs | |||
@@ -10,6 +10,7 @@ use crate::{ | |||
10 | attr::Attrs, | 10 | attr::Attrs, |
11 | body::{scope::ExprScopes, Body, BodySourceMap}, | 11 | body::{scope::ExprScopes, Body, BodySourceMap}, |
12 | data::{ConstData, FunctionData, ImplData, TraitData, TypeAliasData}, | 12 | data::{ConstData, FunctionData, ImplData, TraitData, TypeAliasData}, |
13 | docs::Documentation, | ||
13 | generics::GenericParams, | 14 | generics::GenericParams, |
14 | lang_item::{LangItemTarget, LangItems}, | 15 | lang_item::{LangItemTarget, LangItems}, |
15 | nameres::{ | 16 | nameres::{ |
@@ -40,8 +41,8 @@ pub trait InternDatabase: SourceDatabase { | |||
40 | fn intern_impl(&self, loc: ItemLoc<ast::ImplBlock>) -> crate::ImplId; | 41 | fn intern_impl(&self, loc: ItemLoc<ast::ImplBlock>) -> crate::ImplId; |
41 | } | 42 | } |
42 | 43 | ||
43 | #[salsa::query_group(DefDatabase2Storage)] | 44 | #[salsa::query_group(DefDatabaseStorage)] |
44 | pub trait DefDatabase2: InternDatabase + AstDatabase { | 45 | pub trait DefDatabase: InternDatabase + AstDatabase { |
45 | #[salsa::invoke(RawItems::raw_items_with_source_map_query)] | 46 | #[salsa::invoke(RawItems::raw_items_with_source_map_query)] |
46 | fn raw_items_with_source_map( | 47 | fn raw_items_with_source_map( |
47 | &self, | 48 | &self, |
@@ -101,4 +102,9 @@ pub trait DefDatabase2: InternDatabase + AstDatabase { | |||
101 | 102 | ||
102 | #[salsa::invoke(LangItems::lang_item_query)] | 103 | #[salsa::invoke(LangItems::lang_item_query)] |
103 | fn lang_item(&self, start_crate: CrateId, item: SmolStr) -> Option<LangItemTarget>; | 104 | fn lang_item(&self, start_crate: CrateId, item: SmolStr) -> Option<LangItemTarget>; |
105 | |||
106 | // FIXME(https://github.com/rust-analyzer/rust-analyzer/issues/2148#issuecomment-550519102) | ||
107 | // Remove this query completely, in favor of `Attrs::docs` method | ||
108 | #[salsa::invoke(Documentation::documentation_query)] | ||
109 | fn documentation(&self, def: AttrDefId) -> Option<Documentation>; | ||
104 | } | 110 | } |
diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs new file mode 100644 index 000000000..69846fd1b --- /dev/null +++ b/crates/ra_hir_def/src/docs.rs | |||
@@ -0,0 +1,68 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use std::sync::Arc; | ||
4 | |||
5 | use hir_expand::either::Either; | ||
6 | use ra_syntax::ast; | ||
7 | |||
8 | use crate::{db::DefDatabase, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup}; | ||
9 | |||
10 | /// Holds documentation | ||
11 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
12 | pub struct Documentation(Arc<str>); | ||
13 | |||
14 | impl Into<String> for Documentation { | ||
15 | fn into(self) -> String { | ||
16 | self.as_str().to_owned() | ||
17 | } | ||
18 | } | ||
19 | |||
20 | impl Documentation { | ||
21 | fn new(s: &str) -> Documentation { | ||
22 | Documentation(s.into()) | ||
23 | } | ||
24 | |||
25 | pub fn as_str(&self) -> &str { | ||
26 | &*self.0 | ||
27 | } | ||
28 | |||
29 | pub(crate) fn documentation_query( | ||
30 | db: &impl DefDatabase, | ||
31 | def: AttrDefId, | ||
32 | ) -> Option<Documentation> { | ||
33 | match def { | ||
34 | AttrDefId::ModuleId(module) => { | ||
35 | let def_map = db.crate_def_map(module.krate); | ||
36 | let src = def_map[module.module_id].declaration_source(db)?; | ||
37 | docs_from_ast(&src.value) | ||
38 | } | ||
39 | AttrDefId::StructFieldId(it) => { | ||
40 | let src = it.parent.child_source(db); | ||
41 | match &src.value[it.local_id] { | ||
42 | Either::A(_tuple) => None, | ||
43 | Either::B(record) => docs_from_ast(record), | ||
44 | } | ||
45 | } | ||
46 | AttrDefId::AdtId(it) => match it { | ||
47 | AdtId::StructId(it) => docs_from_ast(&it.0.source(db).value), | ||
48 | AdtId::EnumId(it) => docs_from_ast(&it.source(db).value), | ||
49 | AdtId::UnionId(it) => docs_from_ast(&it.0.source(db).value), | ||
50 | }, | ||
51 | AttrDefId::EnumVariantId(it) => { | ||
52 | let src = it.parent.child_source(db); | ||
53 | docs_from_ast(&src.value[it.local_id]) | ||
54 | } | ||
55 | AttrDefId::StaticId(it) => docs_from_ast(&it.source(db).value), | ||
56 | AttrDefId::TraitId(it) => docs_from_ast(&it.source(db).value), | ||
57 | AttrDefId::MacroDefId(it) => docs_from_ast(&it.ast_id.to_node(db)), | ||
58 | AttrDefId::ConstId(it) => docs_from_ast(&it.lookup(db).source(db).value), | ||
59 | AttrDefId::FunctionId(it) => docs_from_ast(&it.lookup(db).source(db).value), | ||
60 | AttrDefId::TypeAliasId(it) => docs_from_ast(&it.lookup(db).source(db).value), | ||
61 | AttrDefId::ImplId(_) => None, | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | |||
66 | pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option<Documentation> { | ||
67 | node.doc_comment_text().map(|it| Documentation::new(&it)) | ||
68 | } | ||
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index 9e2e4c3cc..015fe772e 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs | |||
@@ -8,7 +8,7 @@ use hir_expand::name::{self, AsName, Name}; | |||
8 | use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner}; | 8 | use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner}; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | db::DefDatabase2, | 11 | db::DefDatabase, |
12 | type_ref::{TypeBound, TypeRef}, | 12 | type_ref::{TypeBound, TypeRef}, |
13 | AdtId, AstItemDef, ContainerId, GenericDefId, HasSource, Lookup, | 13 | AdtId, AstItemDef, ContainerId, GenericDefId, HasSource, Lookup, |
14 | }; | 14 | }; |
@@ -42,7 +42,7 @@ pub struct WherePredicate { | |||
42 | 42 | ||
43 | impl GenericParams { | 43 | impl GenericParams { |
44 | pub(crate) fn generic_params_query( | 44 | pub(crate) fn generic_params_query( |
45 | db: &impl DefDatabase2, | 45 | db: &impl DefDatabase, |
46 | def: GenericDefId, | 46 | def: GenericDefId, |
47 | ) -> Arc<GenericParams> { | 47 | ) -> Arc<GenericParams> { |
48 | let parent_generics = parent_generic_def(db, def).map(|it| db.generic_params(it)); | 48 | let parent_generics = parent_generic_def(db, def).map(|it| db.generic_params(it)); |
@@ -50,7 +50,7 @@ impl GenericParams { | |||
50 | } | 50 | } |
51 | 51 | ||
52 | fn new( | 52 | fn new( |
53 | db: &impl DefDatabase2, | 53 | db: &impl DefDatabase, |
54 | def: GenericDefId, | 54 | def: GenericDefId, |
55 | parent_params: Option<Arc<GenericParams>>, | 55 | parent_params: Option<Arc<GenericParams>>, |
56 | ) -> GenericParams { | 56 | ) -> GenericParams { |
@@ -168,7 +168,7 @@ impl GenericParams { | |||
168 | } | 168 | } |
169 | } | 169 | } |
170 | 170 | ||
171 | fn parent_generic_def(db: &impl DefDatabase2, def: GenericDefId) -> Option<GenericDefId> { | 171 | fn parent_generic_def(db: &impl DefDatabase, def: GenericDefId) -> Option<GenericDefId> { |
172 | let container = match def { | 172 | let container = match def { |
173 | GenericDefId::FunctionId(it) => it.lookup(db).container, | 173 | GenericDefId::FunctionId(it) => it.lookup(db).container, |
174 | GenericDefId::TypeAliasId(it) => it.lookup(db).container, | 174 | GenericDefId::TypeAliasId(it) => it.lookup(db).container, |
diff --git a/crates/ra_hir_def/src/lang_item.rs b/crates/ra_hir_def/src/lang_item.rs index 4c1a764ea..df951c533 100644 --- a/crates/ra_hir_def/src/lang_item.rs +++ b/crates/ra_hir_def/src/lang_item.rs | |||
@@ -8,7 +8,7 @@ use ra_syntax::SmolStr; | |||
8 | use rustc_hash::FxHashMap; | 8 | use rustc_hash::FxHashMap; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | db::DefDatabase2, AdtId, AttrDefId, CrateId, EnumId, FunctionId, ImplId, ModuleDefId, ModuleId, | 11 | db::DefDatabase, AdtId, AttrDefId, CrateId, EnumId, FunctionId, ImplId, ModuleDefId, ModuleId, |
12 | StaticId, StructId, TraitId, | 12 | StaticId, StructId, TraitId, |
13 | }; | 13 | }; |
14 | 14 | ||
@@ -33,7 +33,7 @@ impl LangItems { | |||
33 | } | 33 | } |
34 | 34 | ||
35 | /// Salsa query. This will look for lang items in a specific crate. | 35 | /// Salsa query. This will look for lang items in a specific crate. |
36 | pub(crate) fn crate_lang_items_query(db: &impl DefDatabase2, krate: CrateId) -> Arc<LangItems> { | 36 | pub(crate) fn crate_lang_items_query(db: &impl DefDatabase, krate: CrateId) -> Arc<LangItems> { |
37 | let mut lang_items = LangItems::default(); | 37 | let mut lang_items = LangItems::default(); |
38 | 38 | ||
39 | let crate_def_map = db.crate_def_map(krate); | 39 | let crate_def_map = db.crate_def_map(krate); |
@@ -47,7 +47,7 @@ impl LangItems { | |||
47 | } | 47 | } |
48 | 48 | ||
49 | pub(crate) fn module_lang_items_query( | 49 | pub(crate) fn module_lang_items_query( |
50 | db: &impl DefDatabase2, | 50 | db: &impl DefDatabase, |
51 | module: ModuleId, | 51 | module: ModuleId, |
52 | ) -> Option<Arc<LangItems>> { | 52 | ) -> Option<Arc<LangItems>> { |
53 | let mut lang_items = LangItems::default(); | 53 | let mut lang_items = LangItems::default(); |
@@ -62,7 +62,7 @@ impl LangItems { | |||
62 | /// Salsa query. Look for a lang item, starting from the specified crate and recursively | 62 | /// Salsa query. Look for a lang item, starting from the specified crate and recursively |
63 | /// traversing its dependencies. | 63 | /// traversing its dependencies. |
64 | pub(crate) fn lang_item_query( | 64 | pub(crate) fn lang_item_query( |
65 | db: &impl DefDatabase2, | 65 | db: &impl DefDatabase, |
66 | start_crate: CrateId, | 66 | start_crate: CrateId, |
67 | item: SmolStr, | 67 | item: SmolStr, |
68 | ) -> Option<LangItemTarget> { | 68 | ) -> Option<LangItemTarget> { |
@@ -76,7 +76,7 @@ impl LangItems { | |||
76 | .find_map(|dep| db.lang_item(dep.crate_id, item.clone())) | 76 | .find_map(|dep| db.lang_item(dep.crate_id, item.clone())) |
77 | } | 77 | } |
78 | 78 | ||
79 | fn collect_lang_items(&mut self, db: &impl DefDatabase2, module: ModuleId) { | 79 | fn collect_lang_items(&mut self, db: &impl DefDatabase, module: ModuleId) { |
80 | // Look for impl targets | 80 | // Look for impl targets |
81 | let def_map = db.crate_def_map(module.krate); | 81 | let def_map = db.crate_def_map(module.krate); |
82 | let module_data = &def_map[module.module_id]; | 82 | let module_data = &def_map[module.module_id]; |
@@ -106,7 +106,7 @@ impl LangItems { | |||
106 | 106 | ||
107 | fn collect_lang_item<T>( | 107 | fn collect_lang_item<T>( |
108 | &mut self, | 108 | &mut self, |
109 | db: &impl DefDatabase2, | 109 | db: &impl DefDatabase, |
110 | item: T, | 110 | item: T, |
111 | constructor: fn(T) -> LangItemTarget, | 111 | constructor: fn(T) -> LangItemTarget, |
112 | ) where | 112 | ) where |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 899510be4..1b2bc6f45 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -20,6 +20,7 @@ pub mod generics; | |||
20 | pub mod resolver; | 20 | pub mod resolver; |
21 | pub mod data; | 21 | pub mod data; |
22 | pub mod lang_item; | 22 | pub mod lang_item; |
23 | pub mod docs; | ||
23 | 24 | ||
24 | mod trace; | 25 | mod trace; |
25 | 26 | ||
@@ -47,7 +48,7 @@ pub enum ModuleSource { | |||
47 | 48 | ||
48 | impl ModuleSource { | 49 | impl ModuleSource { |
49 | pub fn new( | 50 | pub fn new( |
50 | db: &impl db::DefDatabase2, | 51 | db: &impl db::DefDatabase, |
51 | file_id: Option<FileId>, | 52 | file_id: Option<FileId>, |
52 | decl_id: Option<AstId<ast::Module>>, | 53 | decl_id: Option<AstId<ast::Module>>, |
53 | ) -> ModuleSource { | 54 | ) -> ModuleSource { |
@@ -66,10 +67,7 @@ impl ModuleSource { | |||
66 | } | 67 | } |
67 | 68 | ||
68 | // FIXME: this methods do not belong here | 69 | // FIXME: this methods do not belong here |
69 | pub fn from_position( | 70 | pub fn from_position(db: &impl db::DefDatabase, position: ra_db::FilePosition) -> ModuleSource { |
70 | db: &impl db::DefDatabase2, | ||
71 | position: ra_db::FilePosition, | ||
72 | ) -> ModuleSource { | ||
73 | let parse = db.parse(position.file_id); | 71 | let parse = db.parse(position.file_id); |
74 | match &ra_syntax::algo::find_node_at_offset::<ast::Module>( | 72 | match &ra_syntax::algo::find_node_at_offset::<ast::Module>( |
75 | parse.tree().syntax(), | 73 | parse.tree().syntax(), |
@@ -83,7 +81,7 @@ impl ModuleSource { | |||
83 | } | 81 | } |
84 | } | 82 | } |
85 | 83 | ||
86 | pub fn from_child_node(db: &impl db::DefDatabase2, child: Source<&SyntaxNode>) -> ModuleSource { | 84 | pub fn from_child_node(db: &impl db::DefDatabase, child: Source<&SyntaxNode>) -> ModuleSource { |
87 | if let Some(m) = | 85 | if let Some(m) = |
88 | child.value.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) | 86 | child.value.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) |
89 | { | 87 | { |
@@ -95,7 +93,7 @@ impl ModuleSource { | |||
95 | } | 93 | } |
96 | } | 94 | } |
97 | 95 | ||
98 | pub fn from_file_id(db: &impl db::DefDatabase2, file_id: FileId) -> ModuleSource { | 96 | pub fn from_file_id(db: &impl db::DefDatabase, file_id: FileId) -> ModuleSource { |
99 | let source_file = db.parse(file_id).tree(); | 97 | let source_file = db.parse(file_id).tree(); |
100 | ModuleSource::SourceFile(source_file) | 98 | ModuleSource::SourceFile(source_file) |
101 | } | 99 | } |
@@ -210,14 +208,14 @@ pub struct FunctionLoc { | |||
210 | 208 | ||
211 | impl Intern for FunctionLoc { | 209 | impl Intern for FunctionLoc { |
212 | type ID = FunctionId; | 210 | type ID = FunctionId; |
213 | fn intern(self, db: &impl db::DefDatabase2) -> FunctionId { | 211 | fn intern(self, db: &impl db::DefDatabase) -> FunctionId { |
214 | db.intern_function(self) | 212 | db.intern_function(self) |
215 | } | 213 | } |
216 | } | 214 | } |
217 | 215 | ||
218 | impl Lookup for FunctionId { | 216 | impl Lookup for FunctionId { |
219 | type Data = FunctionLoc; | 217 | type Data = FunctionLoc; |
220 | fn lookup(&self, db: &impl db::DefDatabase2) -> FunctionLoc { | 218 | fn lookup(&self, db: &impl db::DefDatabase) -> FunctionLoc { |
221 | db.lookup_intern_function(*self) | 219 | db.lookup_intern_function(*self) |
222 | } | 220 | } |
223 | } | 221 | } |
@@ -300,14 +298,14 @@ pub struct ConstLoc { | |||
300 | 298 | ||
301 | impl Intern for ConstLoc { | 299 | impl Intern for ConstLoc { |
302 | type ID = ConstId; | 300 | type ID = ConstId; |
303 | fn intern(self, db: &impl db::DefDatabase2) -> ConstId { | 301 | fn intern(self, db: &impl db::DefDatabase) -> ConstId { |
304 | db.intern_const(self) | 302 | db.intern_const(self) |
305 | } | 303 | } |
306 | } | 304 | } |
307 | 305 | ||
308 | impl Lookup for ConstId { | 306 | impl Lookup for ConstId { |
309 | type Data = ConstLoc; | 307 | type Data = ConstLoc; |
310 | fn lookup(&self, db: &impl db::DefDatabase2) -> ConstLoc { | 308 | fn lookup(&self, db: &impl db::DefDatabase) -> ConstLoc { |
311 | db.lookup_intern_const(*self) | 309 | db.lookup_intern_const(*self) |
312 | } | 310 | } |
313 | } | 311 | } |
@@ -348,14 +346,14 @@ pub struct TypeAliasLoc { | |||
348 | 346 | ||
349 | impl Intern for TypeAliasLoc { | 347 | impl Intern for TypeAliasLoc { |
350 | type ID = TypeAliasId; | 348 | type ID = TypeAliasId; |
351 | fn intern(self, db: &impl db::DefDatabase2) -> TypeAliasId { | 349 | fn intern(self, db: &impl db::DefDatabase) -> TypeAliasId { |
352 | db.intern_type_alias(self) | 350 | db.intern_type_alias(self) |
353 | } | 351 | } |
354 | } | 352 | } |
355 | 353 | ||
356 | impl Lookup for TypeAliasId { | 354 | impl Lookup for TypeAliasId { |
357 | type Data = TypeAliasLoc; | 355 | type Data = TypeAliasLoc; |
358 | fn lookup(&self, db: &impl db::DefDatabase2) -> TypeAliasLoc { | 356 | fn lookup(&self, db: &impl db::DefDatabase) -> TypeAliasLoc { |
359 | db.lookup_intern_type_alias(*self) | 357 | db.lookup_intern_type_alias(*self) |
360 | } | 358 | } |
361 | } | 359 | } |
@@ -509,20 +507,20 @@ impl_froms!( | |||
509 | 507 | ||
510 | trait Intern { | 508 | trait Intern { |
511 | type ID; | 509 | type ID; |
512 | fn intern(self, db: &impl db::DefDatabase2) -> Self::ID; | 510 | fn intern(self, db: &impl db::DefDatabase) -> Self::ID; |
513 | } | 511 | } |
514 | 512 | ||
515 | pub trait Lookup { | 513 | pub trait Lookup { |
516 | type Data; | 514 | type Data; |
517 | fn lookup(&self, db: &impl db::DefDatabase2) -> Self::Data; | 515 | fn lookup(&self, db: &impl db::DefDatabase) -> Self::Data; |
518 | } | 516 | } |
519 | 517 | ||
520 | pub trait HasModule { | 518 | pub trait HasModule { |
521 | fn module(&self, db: &impl db::DefDatabase2) -> ModuleId; | 519 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId; |
522 | } | 520 | } |
523 | 521 | ||
524 | impl HasModule for FunctionLoc { | 522 | impl HasModule for FunctionLoc { |
525 | fn module(&self, db: &impl db::DefDatabase2) -> ModuleId { | 523 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { |
526 | match self.container { | 524 | match self.container { |
527 | ContainerId::ModuleId(it) => it, | 525 | ContainerId::ModuleId(it) => it, |
528 | ContainerId::ImplId(it) => it.module(db), | 526 | ContainerId::ImplId(it) => it.module(db), |
@@ -532,7 +530,7 @@ impl HasModule for FunctionLoc { | |||
532 | } | 530 | } |
533 | 531 | ||
534 | impl HasModule for TypeAliasLoc { | 532 | impl HasModule for TypeAliasLoc { |
535 | fn module(&self, db: &impl db::DefDatabase2) -> ModuleId { | 533 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { |
536 | match self.container { | 534 | match self.container { |
537 | ContainerId::ModuleId(it) => it, | 535 | ContainerId::ModuleId(it) => it, |
538 | ContainerId::ImplId(it) => it.module(db), | 536 | ContainerId::ImplId(it) => it.module(db), |
@@ -542,7 +540,7 @@ impl HasModule for TypeAliasLoc { | |||
542 | } | 540 | } |
543 | 541 | ||
544 | impl HasModule for ConstLoc { | 542 | impl HasModule for ConstLoc { |
545 | fn module(&self, db: &impl db::DefDatabase2) -> ModuleId { | 543 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { |
546 | match self.container { | 544 | match self.container { |
547 | ContainerId::ModuleId(it) => it, | 545 | ContainerId::ModuleId(it) => it, |
548 | ContainerId::ImplId(it) => it.module(db), | 546 | ContainerId::ImplId(it) => it.module(db), |
@@ -553,13 +551,13 @@ impl HasModule for ConstLoc { | |||
553 | 551 | ||
554 | pub trait HasSource { | 552 | pub trait HasSource { |
555 | type Value; | 553 | type Value; |
556 | fn source(&self, db: &impl db::DefDatabase2) -> Source<Self::Value>; | 554 | fn source(&self, db: &impl db::DefDatabase) -> Source<Self::Value>; |
557 | } | 555 | } |
558 | 556 | ||
559 | impl HasSource for FunctionLoc { | 557 | impl HasSource for FunctionLoc { |
560 | type Value = ast::FnDef; | 558 | type Value = ast::FnDef; |
561 | 559 | ||
562 | fn source(&self, db: &impl db::DefDatabase2) -> Source<ast::FnDef> { | 560 | fn source(&self, db: &impl db::DefDatabase) -> Source<ast::FnDef> { |
563 | let node = self.ast_id.to_node(db); | 561 | let node = self.ast_id.to_node(db); |
564 | Source::new(self.ast_id.file_id(), node) | 562 | Source::new(self.ast_id.file_id(), node) |
565 | } | 563 | } |
@@ -568,7 +566,7 @@ impl HasSource for FunctionLoc { | |||
568 | impl HasSource for TypeAliasLoc { | 566 | impl HasSource for TypeAliasLoc { |
569 | type Value = ast::TypeAliasDef; | 567 | type Value = ast::TypeAliasDef; |
570 | 568 | ||
571 | fn source(&self, db: &impl db::DefDatabase2) -> Source<ast::TypeAliasDef> { | 569 | fn source(&self, db: &impl db::DefDatabase) -> Source<ast::TypeAliasDef> { |
572 | let node = self.ast_id.to_node(db); | 570 | let node = self.ast_id.to_node(db); |
573 | Source::new(self.ast_id.file_id(), node) | 571 | Source::new(self.ast_id.file_id(), node) |
574 | } | 572 | } |
@@ -577,7 +575,7 @@ impl HasSource for TypeAliasLoc { | |||
577 | impl HasSource for ConstLoc { | 575 | impl HasSource for ConstLoc { |
578 | type Value = ast::ConstDef; | 576 | type Value = ast::ConstDef; |
579 | 577 | ||
580 | fn source(&self, db: &impl db::DefDatabase2) -> Source<ast::ConstDef> { | 578 | fn source(&self, db: &impl db::DefDatabase) -> Source<ast::ConstDef> { |
581 | let node = self.ast_id.to_node(db); | 579 | let node = self.ast_id.to_node(db); |
582 | Source::new(self.ast_id.file_id(), node) | 580 | Source::new(self.ast_id.file_id(), node) |
583 | } | 581 | } |
@@ -588,6 +586,6 @@ pub trait HasChildSource { | |||
588 | type Value; | 586 | type Value; |
589 | fn child_source( | 587 | fn child_source( |
590 | &self, | 588 | &self, |
591 | db: &impl db::DefDatabase2, | 589 | db: &impl db::DefDatabase, |
592 | ) -> Source<ArenaMap<Self::ChildId, Self::Value>>; | 590 | ) -> Source<ArenaMap<Self::ChildId, Self::Value>>; |
593 | } | 591 | } |
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 6723465a5..101203b7b 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs | |||
@@ -71,7 +71,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; | |||
71 | 71 | ||
72 | use crate::{ | 72 | use crate::{ |
73 | builtin_type::BuiltinType, | 73 | builtin_type::BuiltinType, |
74 | db::DefDatabase2, | 74 | db::DefDatabase, |
75 | nameres::{ | 75 | nameres::{ |
76 | diagnostics::DefDiagnostic, path_resolution::ResolveMode, per_ns::PerNs, raw::ImportId, | 76 | diagnostics::DefDiagnostic, path_resolution::ResolveMode, per_ns::PerNs, raw::ImportId, |
77 | }, | 77 | }, |
@@ -220,7 +220,7 @@ impl CrateDefMap { | |||
220 | pub(crate) fn crate_def_map_query( | 220 | pub(crate) fn crate_def_map_query( |
221 | // Note that this doesn't have `+ AstDatabase`! | 221 | // Note that this doesn't have `+ AstDatabase`! |
222 | // This gurantess that `CrateDefMap` is stable across reparses. | 222 | // This gurantess that `CrateDefMap` is stable across reparses. |
223 | db: &impl DefDatabase2, | 223 | db: &impl DefDatabase, |
224 | krate: CrateId, | 224 | krate: CrateId, |
225 | ) -> Arc<CrateDefMap> { | 225 | ) -> Arc<CrateDefMap> { |
226 | let _p = profile("crate_def_map_query"); | 226 | let _p = profile("crate_def_map_query"); |
@@ -262,7 +262,7 @@ impl CrateDefMap { | |||
262 | 262 | ||
263 | pub fn add_diagnostics( | 263 | pub fn add_diagnostics( |
264 | &self, | 264 | &self, |
265 | db: &impl DefDatabase2, | 265 | db: &impl DefDatabase, |
266 | module: CrateModuleId, | 266 | module: CrateModuleId, |
267 | sink: &mut DiagnosticSink, | 267 | sink: &mut DiagnosticSink, |
268 | ) { | 268 | ) { |
@@ -271,7 +271,7 @@ impl CrateDefMap { | |||
271 | 271 | ||
272 | pub fn resolve_path( | 272 | pub fn resolve_path( |
273 | &self, | 273 | &self, |
274 | db: &impl DefDatabase2, | 274 | db: &impl DefDatabase, |
275 | original_module: CrateModuleId, | 275 | original_module: CrateModuleId, |
276 | path: &Path, | 276 | path: &Path, |
277 | ) -> (PerNs, Option<usize>) { | 277 | ) -> (PerNs, Option<usize>) { |
@@ -295,7 +295,7 @@ impl ModuleData { | |||
295 | /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. | 295 | /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. |
296 | pub fn definition_source( | 296 | pub fn definition_source( |
297 | &self, | 297 | &self, |
298 | db: &impl DefDatabase2, | 298 | db: &impl DefDatabase, |
299 | ) -> Source<Either<ast::SourceFile, ast::Module>> { | 299 | ) -> Source<Either<ast::SourceFile, ast::Module>> { |
300 | if let Some(file_id) = self.definition { | 300 | if let Some(file_id) = self.definition { |
301 | let sf = db.parse(file_id).tree(); | 301 | let sf = db.parse(file_id).tree(); |
@@ -307,7 +307,7 @@ impl ModuleData { | |||
307 | 307 | ||
308 | /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. | 308 | /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. |
309 | /// `None` for the crate root. | 309 | /// `None` for the crate root. |
310 | pub fn declaration_source(&self, db: &impl DefDatabase2) -> Option<Source<ast::Module>> { | 310 | pub fn declaration_source(&self, db: &impl DefDatabase) -> Option<Source<ast::Module>> { |
311 | let decl = self.declaration?; | 311 | let decl = self.declaration?; |
312 | let value = decl.to_node(db); | 312 | let value = decl.to_node(db); |
313 | Some(Source { file_id: decl.file_id(), value }) | 313 | Some(Source { file_id: decl.file_id(), value }) |
@@ -319,7 +319,7 @@ mod diagnostics { | |||
319 | use ra_db::RelativePathBuf; | 319 | use ra_db::RelativePathBuf; |
320 | use ra_syntax::{ast, AstPtr}; | 320 | use ra_syntax::{ast, AstPtr}; |
321 | 321 | ||
322 | use crate::{db::DefDatabase2, diagnostics::UnresolvedModule, nameres::CrateModuleId, AstId}; | 322 | use crate::{db::DefDatabase, diagnostics::UnresolvedModule, nameres::CrateModuleId, AstId}; |
323 | 323 | ||
324 | #[derive(Debug, PartialEq, Eq)] | 324 | #[derive(Debug, PartialEq, Eq)] |
325 | pub(super) enum DefDiagnostic { | 325 | pub(super) enum DefDiagnostic { |
@@ -333,7 +333,7 @@ mod diagnostics { | |||
333 | impl DefDiagnostic { | 333 | impl DefDiagnostic { |
334 | pub(super) fn add_to( | 334 | pub(super) fn add_to( |
335 | &self, | 335 | &self, |
336 | db: &impl DefDatabase2, | 336 | db: &impl DefDatabase, |
337 | target_module: CrateModuleId, | 337 | target_module: CrateModuleId, |
338 | sink: &mut DiagnosticSink, | 338 | sink: &mut DiagnosticSink, |
339 | ) { | 339 | ) { |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 7902293e8..1894b072a 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -13,7 +13,7 @@ use test_utils::tested_by; | |||
13 | 13 | ||
14 | use crate::{ | 14 | use crate::{ |
15 | attr::Attrs, | 15 | attr::Attrs, |
16 | db::DefDatabase2, | 16 | db::DefDatabase, |
17 | nameres::{ | 17 | nameres::{ |
18 | diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint, | 18 | diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint, |
19 | per_ns::PerNs, raw, CrateDefMap, ModuleData, Resolution, ResolveMode, | 19 | per_ns::PerNs, raw, CrateDefMap, ModuleData, Resolution, ResolveMode, |
@@ -24,7 +24,7 @@ use crate::{ | |||
24 | StructOrUnionId, TraitId, TypeAliasLoc, UnionId, | 24 | StructOrUnionId, TraitId, TypeAliasLoc, UnionId, |
25 | }; | 25 | }; |
26 | 26 | ||
27 | pub(super) fn collect_defs(db: &impl DefDatabase2, mut def_map: CrateDefMap) -> CrateDefMap { | 27 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { |
28 | let crate_graph = db.crate_graph(); | 28 | let crate_graph = db.crate_graph(); |
29 | 29 | ||
30 | // populate external prelude | 30 | // populate external prelude |
@@ -108,7 +108,7 @@ struct DefCollector<'a, DB> { | |||
108 | 108 | ||
109 | impl<DB> DefCollector<'_, DB> | 109 | impl<DB> DefCollector<'_, DB> |
110 | where | 110 | where |
111 | DB: DefDatabase2, | 111 | DB: DefDatabase, |
112 | { | 112 | { |
113 | fn collect(&mut self) { | 113 | fn collect(&mut self) { |
114 | let crate_graph = self.db.crate_graph(); | 114 | let crate_graph = self.db.crate_graph(); |
@@ -530,7 +530,7 @@ struct ModCollector<'a, D> { | |||
530 | 530 | ||
531 | impl<DB> ModCollector<'_, &'_ mut DefCollector<'_, DB>> | 531 | impl<DB> ModCollector<'_, &'_ mut DefCollector<'_, DB>> |
532 | where | 532 | where |
533 | DB: DefDatabase2, | 533 | DB: DefDatabase, |
534 | { | 534 | { |
535 | fn collect(&mut self, items: &[raw::RawItem]) { | 535 | fn collect(&mut self, items: &[raw::RawItem]) { |
536 | // Note: don't assert that inserted value is fresh: it's simply not true | 536 | // Note: don't assert that inserted value is fresh: it's simply not true |
@@ -798,12 +798,12 @@ mod tests { | |||
798 | use ra_db::{fixture::WithFixture, SourceDatabase}; | 798 | use ra_db::{fixture::WithFixture, SourceDatabase}; |
799 | use rustc_hash::FxHashSet; | 799 | use rustc_hash::FxHashSet; |
800 | 800 | ||
801 | use crate::{db::DefDatabase2, test_db::TestDB}; | 801 | use crate::{db::DefDatabase, test_db::TestDB}; |
802 | 802 | ||
803 | use super::*; | 803 | use super::*; |
804 | 804 | ||
805 | fn do_collect_defs( | 805 | fn do_collect_defs( |
806 | db: &impl DefDatabase2, | 806 | db: &impl DefDatabase, |
807 | def_map: CrateDefMap, | 807 | def_map: CrateDefMap, |
808 | monitor: MacroStackMonitor, | 808 | monitor: MacroStackMonitor, |
809 | ) -> CrateDefMap { | 809 | ) -> CrateDefMap { |
diff --git a/crates/ra_hir_def/src/nameres/mod_resolution.rs b/crates/ra_hir_def/src/nameres/mod_resolution.rs index b3b1379d0..14fb8ba3a 100644 --- a/crates/ra_hir_def/src/nameres/mod_resolution.rs +++ b/crates/ra_hir_def/src/nameres/mod_resolution.rs | |||
@@ -3,7 +3,7 @@ use hir_expand::name::Name; | |||
3 | use ra_db::{FileId, RelativePathBuf}; | 3 | use ra_db::{FileId, RelativePathBuf}; |
4 | use ra_syntax::SmolStr; | 4 | use ra_syntax::SmolStr; |
5 | 5 | ||
6 | use crate::{db::DefDatabase2, HirFileId}; | 6 | use crate::{db::DefDatabase, HirFileId}; |
7 | 7 | ||
8 | #[derive(Clone, Debug)] | 8 | #[derive(Clone, Debug)] |
9 | pub(super) struct ModDir { | 9 | pub(super) struct ModDir { |
@@ -40,7 +40,7 @@ impl ModDir { | |||
40 | 40 | ||
41 | pub(super) fn resolve_declaration( | 41 | pub(super) fn resolve_declaration( |
42 | &self, | 42 | &self, |
43 | db: &impl DefDatabase2, | 43 | db: &impl DefDatabase, |
44 | file_id: HirFileId, | 44 | file_id: HirFileId, |
45 | name: &Name, | 45 | name: &Name, |
46 | attr_path: Option<&SmolStr>, | 46 | attr_path: Option<&SmolStr>, |
diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs index 95692f826..102009ac7 100644 --- a/crates/ra_hir_def/src/nameres/path_resolution.rs +++ b/crates/ra_hir_def/src/nameres/path_resolution.rs | |||
@@ -15,7 +15,7 @@ use ra_db::Edition; | |||
15 | use test_utils::tested_by; | 15 | use test_utils::tested_by; |
16 | 16 | ||
17 | use crate::{ | 17 | use crate::{ |
18 | db::DefDatabase2, | 18 | db::DefDatabase, |
19 | nameres::{per_ns::PerNs, CrateDefMap}, | 19 | nameres::{per_ns::PerNs, CrateDefMap}, |
20 | path::{Path, PathKind}, | 20 | path::{Path, PathKind}, |
21 | AdtId, CrateModuleId, EnumVariantId, ModuleDefId, ModuleId, | 21 | AdtId, CrateModuleId, EnumVariantId, ModuleDefId, ModuleId, |
@@ -63,7 +63,7 @@ impl CrateDefMap { | |||
63 | // the result. | 63 | // the result. |
64 | pub(super) fn resolve_path_fp_with_macro( | 64 | pub(super) fn resolve_path_fp_with_macro( |
65 | &self, | 65 | &self, |
66 | db: &impl DefDatabase2, | 66 | db: &impl DefDatabase, |
67 | mode: ResolveMode, | 67 | mode: ResolveMode, |
68 | original_module: CrateModuleId, | 68 | original_module: CrateModuleId, |
69 | path: &Path, | 69 | path: &Path, |
@@ -216,7 +216,7 @@ impl CrateDefMap { | |||
216 | 216 | ||
217 | fn resolve_name_in_module( | 217 | fn resolve_name_in_module( |
218 | &self, | 218 | &self, |
219 | db: &impl DefDatabase2, | 219 | db: &impl DefDatabase, |
220 | module: CrateModuleId, | 220 | module: CrateModuleId, |
221 | name: &Name, | 221 | name: &Name, |
222 | ) -> PerNs { | 222 | ) -> PerNs { |
@@ -243,7 +243,7 @@ impl CrateDefMap { | |||
243 | from_crate_root.or(from_extern_prelude) | 243 | from_crate_root.or(from_extern_prelude) |
244 | } | 244 | } |
245 | 245 | ||
246 | fn resolve_in_prelude(&self, db: &impl DefDatabase2, name: &Name) -> PerNs { | 246 | fn resolve_in_prelude(&self, db: &impl DefDatabase, name: &Name) -> PerNs { |
247 | if let Some(prelude) = self.prelude { | 247 | if let Some(prelude) = self.prelude { |
248 | let keep; | 248 | let keep; |
249 | let def_map = if prelude.krate == self.krate { | 249 | let def_map = if prelude.krate == self.krate { |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 55a9634f8..7618cb059 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -18,7 +18,7 @@ use test_utils::tested_by; | |||
18 | 18 | ||
19 | use crate::{ | 19 | use crate::{ |
20 | attr::{Attr, Attrs}, | 20 | attr::{Attr, Attrs}, |
21 | db::DefDatabase2, | 21 | db::DefDatabase, |
22 | path::Path, | 22 | path::Path, |
23 | FileAstId, HirFileId, ModuleSource, Source, | 23 | FileAstId, HirFileId, ModuleSource, Source, |
24 | }; | 24 | }; |
@@ -67,14 +67,14 @@ impl ImportSourceMap { | |||
67 | 67 | ||
68 | impl RawItems { | 68 | impl RawItems { |
69 | pub(crate) fn raw_items_query( | 69 | pub(crate) fn raw_items_query( |
70 | db: &(impl DefDatabase2 + AstDatabase), | 70 | db: &(impl DefDatabase + AstDatabase), |
71 | file_id: HirFileId, | 71 | file_id: HirFileId, |
72 | ) -> Arc<RawItems> { | 72 | ) -> Arc<RawItems> { |
73 | db.raw_items_with_source_map(file_id).0 | 73 | db.raw_items_with_source_map(file_id).0 |
74 | } | 74 | } |
75 | 75 | ||
76 | pub(crate) fn raw_items_with_source_map_query( | 76 | pub(crate) fn raw_items_with_source_map_query( |
77 | db: &(impl DefDatabase2 + AstDatabase), | 77 | db: &(impl DefDatabase + AstDatabase), |
78 | file_id: HirFileId, | 78 | file_id: HirFileId, |
79 | ) -> (Arc<RawItems>, Arc<ImportSourceMap>) { | 79 | ) -> (Arc<RawItems>, Arc<ImportSourceMap>) { |
80 | let mut collector = RawItemsCollector { | 80 | let mut collector = RawItemsCollector { |
diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs index 256f7d4be..b5053ba20 100644 --- a/crates/ra_hir_def/src/nameres/tests.rs +++ b/crates/ra_hir_def/src/nameres/tests.rs | |||
@@ -10,7 +10,7 @@ use insta::assert_snapshot; | |||
10 | use ra_db::{fixture::WithFixture, SourceDatabase}; | 10 | use ra_db::{fixture::WithFixture, SourceDatabase}; |
11 | use test_utils::covers; | 11 | use test_utils::covers; |
12 | 12 | ||
13 | use crate::{db::DefDatabase2, nameres::*, test_db::TestDB, CrateModuleId}; | 13 | use crate::{db::DefDatabase, nameres::*, test_db::TestDB, CrateModuleId}; |
14 | 14 | ||
15 | fn def_map(fixtute: &str) -> String { | 15 | fn def_map(fixtute: &str) -> String { |
16 | let dm = compute_crate_def_map(fixtute); | 16 | let dm = compute_crate_def_map(fixtute); |
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index 7b5c3ec06..48a836a20 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -11,7 +11,7 @@ use rustc_hash::FxHashSet; | |||
11 | use crate::{ | 11 | use crate::{ |
12 | body::scope::{ExprScopes, ScopeId}, | 12 | body::scope::{ExprScopes, ScopeId}, |
13 | builtin_type::BuiltinType, | 13 | builtin_type::BuiltinType, |
14 | db::DefDatabase2, | 14 | db::DefDatabase, |
15 | expr::{ExprId, PatId}, | 15 | expr::{ExprId, PatId}, |
16 | generics::GenericParams, | 16 | generics::GenericParams, |
17 | nameres::{per_ns::PerNs, CrateDefMap}, | 17 | nameres::{per_ns::PerNs, CrateDefMap}, |
@@ -87,7 +87,7 @@ pub enum ValueNs { | |||
87 | 87 | ||
88 | impl Resolver { | 88 | impl Resolver { |
89 | /// Resolve known trait from std, like `std::futures::Future` | 89 | /// Resolve known trait from std, like `std::futures::Future` |
90 | pub fn resolve_known_trait(&self, db: &impl DefDatabase2, path: &Path) -> Option<TraitId> { | 90 | pub fn resolve_known_trait(&self, db: &impl DefDatabase, path: &Path) -> Option<TraitId> { |
91 | let res = self.resolve_module_path(db, path).take_types()?; | 91 | let res = self.resolve_module_path(db, path).take_types()?; |
92 | match res { | 92 | match res { |
93 | ModuleDefId::TraitId(it) => Some(it), | 93 | ModuleDefId::TraitId(it) => Some(it), |
@@ -96,7 +96,7 @@ impl Resolver { | |||
96 | } | 96 | } |
97 | 97 | ||
98 | /// Resolve known struct from std, like `std::boxed::Box` | 98 | /// Resolve known struct from std, like `std::boxed::Box` |
99 | pub fn resolve_known_struct(&self, db: &impl DefDatabase2, path: &Path) -> Option<StructId> { | 99 | pub fn resolve_known_struct(&self, db: &impl DefDatabase, path: &Path) -> Option<StructId> { |
100 | let res = self.resolve_module_path(db, path).take_types()?; | 100 | let res = self.resolve_module_path(db, path).take_types()?; |
101 | match res { | 101 | match res { |
102 | ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it), | 102 | ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it), |
@@ -105,7 +105,7 @@ impl Resolver { | |||
105 | } | 105 | } |
106 | 106 | ||
107 | /// Resolve known enum from std, like `std::result::Result` | 107 | /// Resolve known enum from std, like `std::result::Result` |
108 | pub fn resolve_known_enum(&self, db: &impl DefDatabase2, path: &Path) -> Option<EnumId> { | 108 | pub fn resolve_known_enum(&self, db: &impl DefDatabase, path: &Path) -> Option<EnumId> { |
109 | let res = self.resolve_module_path(db, path).take_types()?; | 109 | let res = self.resolve_module_path(db, path).take_types()?; |
110 | match res { | 110 | match res { |
111 | ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it), | 111 | ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it), |
@@ -114,7 +114,7 @@ impl Resolver { | |||
114 | } | 114 | } |
115 | 115 | ||
116 | /// pub only for source-binder | 116 | /// pub only for source-binder |
117 | pub fn resolve_module_path(&self, db: &impl DefDatabase2, path: &Path) -> PerNs { | 117 | pub fn resolve_module_path(&self, db: &impl DefDatabase, path: &Path) -> PerNs { |
118 | let (item_map, module) = match self.module() { | 118 | let (item_map, module) = match self.module() { |
119 | Some(it) => it, | 119 | Some(it) => it, |
120 | None => return PerNs::none(), | 120 | None => return PerNs::none(), |
@@ -128,7 +128,7 @@ impl Resolver { | |||
128 | 128 | ||
129 | pub fn resolve_path_in_type_ns( | 129 | pub fn resolve_path_in_type_ns( |
130 | &self, | 130 | &self, |
131 | db: &impl DefDatabase2, | 131 | db: &impl DefDatabase, |
132 | path: &Path, | 132 | path: &Path, |
133 | ) -> Option<(TypeNs, Option<usize>)> { | 133 | ) -> Option<(TypeNs, Option<usize>)> { |
134 | if path.is_type_relative() { | 134 | if path.is_type_relative() { |
@@ -184,7 +184,7 @@ impl Resolver { | |||
184 | 184 | ||
185 | pub fn resolve_path_in_type_ns_fully( | 185 | pub fn resolve_path_in_type_ns_fully( |
186 | &self, | 186 | &self, |
187 | db: &impl DefDatabase2, | 187 | db: &impl DefDatabase, |
188 | path: &Path, | 188 | path: &Path, |
189 | ) -> Option<TypeNs> { | 189 | ) -> Option<TypeNs> { |
190 | let (res, unresolved) = self.resolve_path_in_type_ns(db, path)?; | 190 | let (res, unresolved) = self.resolve_path_in_type_ns(db, path)?; |
@@ -196,7 +196,7 @@ impl Resolver { | |||
196 | 196 | ||
197 | pub fn resolve_path_in_value_ns<'p>( | 197 | pub fn resolve_path_in_value_ns<'p>( |
198 | &self, | 198 | &self, |
199 | db: &impl DefDatabase2, | 199 | db: &impl DefDatabase, |
200 | path: &'p Path, | 200 | path: &'p Path, |
201 | ) -> Option<ResolveValueResult> { | 201 | ) -> Option<ResolveValueResult> { |
202 | if path.is_type_relative() { | 202 | if path.is_type_relative() { |
@@ -296,7 +296,7 @@ impl Resolver { | |||
296 | 296 | ||
297 | pub fn resolve_path_in_value_ns_fully( | 297 | pub fn resolve_path_in_value_ns_fully( |
298 | &self, | 298 | &self, |
299 | db: &impl DefDatabase2, | 299 | db: &impl DefDatabase, |
300 | path: &Path, | 300 | path: &Path, |
301 | ) -> Option<ValueNs> { | 301 | ) -> Option<ValueNs> { |
302 | match self.resolve_path_in_value_ns(db, path)? { | 302 | match self.resolve_path_in_value_ns(db, path)? { |
@@ -305,18 +305,18 @@ impl Resolver { | |||
305 | } | 305 | } |
306 | } | 306 | } |
307 | 307 | ||
308 | pub fn resolve_path_as_macro(&self, db: &impl DefDatabase2, path: &Path) -> Option<MacroDefId> { | 308 | pub fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> { |
309 | let (item_map, module) = self.module()?; | 309 | let (item_map, module) = self.module()?; |
310 | item_map.resolve_path(db, module, path).0.get_macros() | 310 | item_map.resolve_path(db, module, path).0.get_macros() |
311 | } | 311 | } |
312 | 312 | ||
313 | pub fn process_all_names(&self, db: &impl DefDatabase2, f: &mut dyn FnMut(Name, ScopeDef)) { | 313 | pub fn process_all_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { |
314 | for scope in self.scopes.iter().rev() { | 314 | for scope in self.scopes.iter().rev() { |
315 | scope.process_names(db, f); | 315 | scope.process_names(db, f); |
316 | } | 316 | } |
317 | } | 317 | } |
318 | 318 | ||
319 | pub fn traits_in_scope(&self, db: &impl DefDatabase2) -> FxHashSet<TraitId> { | 319 | pub fn traits_in_scope(&self, db: &impl DefDatabase) -> FxHashSet<TraitId> { |
320 | let mut traits = FxHashSet::default(); | 320 | let mut traits = FxHashSet::default(); |
321 | for scope in &self.scopes { | 321 | for scope in &self.scopes { |
322 | if let Scope::ModuleScope(m) = scope { | 322 | if let Scope::ModuleScope(m) = scope { |
@@ -378,7 +378,7 @@ pub enum ScopeDef { | |||
378 | } | 378 | } |
379 | 379 | ||
380 | impl Scope { | 380 | impl Scope { |
381 | fn process_names(&self, db: &impl DefDatabase2, f: &mut dyn FnMut(Name, ScopeDef)) { | 381 | fn process_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { |
382 | match self { | 382 | match self { |
383 | Scope::ModuleScope(m) => { | 383 | Scope::ModuleScope(m) => { |
384 | // FIXME: should we provide `self` here? | 384 | // FIXME: should we provide `self` here? |
@@ -425,17 +425,13 @@ impl Scope { | |||
425 | } | 425 | } |
426 | 426 | ||
427 | // needs arbitrary_self_types to be a method... or maybe move to the def? | 427 | // needs arbitrary_self_types to be a method... or maybe move to the def? |
428 | pub fn resolver_for_expr( | 428 | pub fn resolver_for_expr(db: &impl DefDatabase, owner: DefWithBodyId, expr_id: ExprId) -> Resolver { |
429 | db: &impl DefDatabase2, | ||
430 | owner: DefWithBodyId, | ||
431 | expr_id: ExprId, | ||
432 | ) -> Resolver { | ||
433 | let scopes = db.expr_scopes(owner); | 429 | let scopes = db.expr_scopes(owner); |
434 | resolver_for_scope(db, owner, scopes.scope_for(expr_id)) | 430 | resolver_for_scope(db, owner, scopes.scope_for(expr_id)) |
435 | } | 431 | } |
436 | 432 | ||
437 | pub fn resolver_for_scope( | 433 | pub fn resolver_for_scope( |
438 | db: &impl DefDatabase2, | 434 | db: &impl DefDatabase, |
439 | owner: DefWithBodyId, | 435 | owner: DefWithBodyId, |
440 | scope_id: Option<ScopeId>, | 436 | scope_id: Option<ScopeId>, |
441 | ) -> Resolver { | 437 | ) -> Resolver { |
@@ -454,7 +450,7 @@ impl Resolver { | |||
454 | self | 450 | self |
455 | } | 451 | } |
456 | 452 | ||
457 | fn push_generic_params_scope(self, db: &impl DefDatabase2, def: GenericDefId) -> Resolver { | 453 | fn push_generic_params_scope(self, db: &impl DefDatabase, def: GenericDefId) -> Resolver { |
458 | let params = db.generic_params(def); | 454 | let params = db.generic_params(def); |
459 | if params.params.is_empty() { | 455 | if params.params.is_empty() { |
460 | self | 456 | self |
@@ -487,24 +483,24 @@ impl Resolver { | |||
487 | 483 | ||
488 | pub trait HasResolver { | 484 | pub trait HasResolver { |
489 | /// Builds a resolver for type references inside this def. | 485 | /// Builds a resolver for type references inside this def. |
490 | fn resolver(self, db: &impl DefDatabase2) -> Resolver; | 486 | fn resolver(self, db: &impl DefDatabase) -> Resolver; |
491 | } | 487 | } |
492 | 488 | ||
493 | impl HasResolver for ModuleId { | 489 | impl HasResolver for ModuleId { |
494 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | 490 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
495 | let def_map = db.crate_def_map(self.krate); | 491 | let def_map = db.crate_def_map(self.krate); |
496 | Resolver::default().push_module_scope(def_map, self.module_id) | 492 | Resolver::default().push_module_scope(def_map, self.module_id) |
497 | } | 493 | } |
498 | } | 494 | } |
499 | 495 | ||
500 | impl HasResolver for TraitId { | 496 | impl HasResolver for TraitId { |
501 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | 497 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
502 | self.module(db).resolver(db).push_generic_params_scope(db, self.into()) | 498 | self.module(db).resolver(db).push_generic_params_scope(db, self.into()) |
503 | } | 499 | } |
504 | } | 500 | } |
505 | 501 | ||
506 | impl<T: Into<AdtId>> HasResolver for T { | 502 | impl<T: Into<AdtId>> HasResolver for T { |
507 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | 503 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
508 | let def = self.into(); | 504 | let def = self.into(); |
509 | let module = match def { | 505 | let module = match def { |
510 | AdtId::StructId(it) => it.0.module(db), | 506 | AdtId::StructId(it) => it.0.module(db), |
@@ -520,13 +516,13 @@ impl<T: Into<AdtId>> HasResolver for T { | |||
520 | } | 516 | } |
521 | 517 | ||
522 | impl HasResolver for FunctionId { | 518 | impl HasResolver for FunctionId { |
523 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | 519 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
524 | self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into()) | 520 | self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into()) |
525 | } | 521 | } |
526 | } | 522 | } |
527 | 523 | ||
528 | impl HasResolver for DefWithBodyId { | 524 | impl HasResolver for DefWithBodyId { |
529 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | 525 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
530 | match self { | 526 | match self { |
531 | DefWithBodyId::ConstId(c) => c.resolver(db), | 527 | DefWithBodyId::ConstId(c) => c.resolver(db), |
532 | DefWithBodyId::FunctionId(f) => f.resolver(db), | 528 | DefWithBodyId::FunctionId(f) => f.resolver(db), |
@@ -536,25 +532,25 @@ impl HasResolver for DefWithBodyId { | |||
536 | } | 532 | } |
537 | 533 | ||
538 | impl HasResolver for ConstId { | 534 | impl HasResolver for ConstId { |
539 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | 535 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
540 | self.lookup(db).container.resolver(db) | 536 | self.lookup(db).container.resolver(db) |
541 | } | 537 | } |
542 | } | 538 | } |
543 | 539 | ||
544 | impl HasResolver for StaticId { | 540 | impl HasResolver for StaticId { |
545 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | 541 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
546 | self.module(db).resolver(db) | 542 | self.module(db).resolver(db) |
547 | } | 543 | } |
548 | } | 544 | } |
549 | 545 | ||
550 | impl HasResolver for TypeAliasId { | 546 | impl HasResolver for TypeAliasId { |
551 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | 547 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
552 | self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into()) | 548 | self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into()) |
553 | } | 549 | } |
554 | } | 550 | } |
555 | 551 | ||
556 | impl HasResolver for ContainerId { | 552 | impl HasResolver for ContainerId { |
557 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | 553 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
558 | match self { | 554 | match self { |
559 | ContainerId::TraitId(it) => it.resolver(db), | 555 | ContainerId::TraitId(it) => it.resolver(db), |
560 | ContainerId::ImplId(it) => it.resolver(db), | 556 | ContainerId::ImplId(it) => it.resolver(db), |
@@ -564,7 +560,7 @@ impl HasResolver for ContainerId { | |||
564 | } | 560 | } |
565 | 561 | ||
566 | impl HasResolver for GenericDefId { | 562 | impl HasResolver for GenericDefId { |
567 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | 563 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
568 | match self { | 564 | match self { |
569 | GenericDefId::FunctionId(inner) => inner.resolver(db), | 565 | GenericDefId::FunctionId(inner) => inner.resolver(db), |
570 | GenericDefId::AdtId(adt) => adt.resolver(db), | 566 | GenericDefId::AdtId(adt) => adt.resolver(db), |
@@ -578,7 +574,7 @@ impl HasResolver for GenericDefId { | |||
578 | } | 574 | } |
579 | 575 | ||
580 | impl HasResolver for ImplId { | 576 | impl HasResolver for ImplId { |
581 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | 577 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
582 | self.module(db) | 578 | self.module(db) |
583 | .resolver(db) | 579 | .resolver(db) |
584 | .push_generic_params_scope(db, self.into()) | 580 | .push_generic_params_scope(db, self.into()) |
diff --git a/crates/ra_hir_def/src/test_db.rs b/crates/ra_hir_def/src/test_db.rs index 8ee8e40d0..439e8a412 100644 --- a/crates/ra_hir_def/src/test_db.rs +++ b/crates/ra_hir_def/src/test_db.rs | |||
@@ -12,7 +12,7 @@ use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath | |||
12 | ra_db::SourceDatabaseStorage, | 12 | ra_db::SourceDatabaseStorage, |
13 | hir_expand::db::AstDatabaseStorage, | 13 | hir_expand::db::AstDatabaseStorage, |
14 | crate::db::InternDatabaseStorage, | 14 | crate::db::InternDatabaseStorage, |
15 | crate::db::DefDatabase2Storage | 15 | crate::db::DefDatabaseStorage |
16 | )] | 16 | )] |
17 | #[derive(Debug, Default)] | 17 | #[derive(Debug, Default)] |
18 | pub struct TestDB { | 18 | pub struct TestDB { |
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index c96465b6a..c2a9dcdd1 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs | |||
@@ -22,7 +22,6 @@ use crate::{ | |||
22 | hir::db::InternDatabaseStorage, | 22 | hir::db::InternDatabaseStorage, |
23 | hir::db::AstDatabaseStorage, | 23 | hir::db::AstDatabaseStorage, |
24 | hir::db::DefDatabaseStorage, | 24 | hir::db::DefDatabaseStorage, |
25 | hir::db::DefDatabase2Storage, | ||
26 | hir::db::HirDatabaseStorage | 25 | hir::db::HirDatabaseStorage |
27 | )] | 26 | )] |
28 | #[derive(Debug)] | 27 | #[derive(Debug)] |