diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-23 11:50:30 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-23 11:50:30 +0000 |
commit | 102f1984c662544d16441d437e5b0883502d49d1 (patch) | |
tree | 9fbf1b22c02412f15ad4ddb8fcbc405ce8d33795 /crates/ra_hir/src | |
parent | ee300085c016a5b24ff61e0a1406857d4e638618 (diff) | |
parent | 32658a73b4c9078421a1cab92ec459bb5b7236f5 (diff) |
Merge #2372
2372: Note that debugging infra is broken r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 31 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model/docs.rs | 97 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 17 | ||||
-rw-r--r-- | crates/ra_hir/src/debug.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/from_id.rs | 25 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/test_db.rs | 3 |
7 files changed, 45 insertions, 134 deletions
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)] |