diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_assists/src/test_db.rs | 1 | ||||
-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/from_id.rs | 25 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/test_db.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir_def/src/db.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/docs.rs | 68 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_ide_api/src/db.rs | 1 |
11 files changed, 118 insertions, 134 deletions
diff --git a/crates/ra_assists/src/test_db.rs b/crates/ra_assists/src/test_db.rs index 5be7383ed..715270344 100644 --- a/crates/ra_assists/src/test_db.rs +++ b/crates/ra_assists/src/test_db.rs | |||
@@ -9,7 +9,6 @@ use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath | |||
9 | ra_db::SourceDatabaseStorage, | 9 | ra_db::SourceDatabaseStorage, |
10 | hir::db::InternDatabaseStorage, | 10 | hir::db::InternDatabaseStorage, |
11 | hir::db::AstDatabaseStorage, | 11 | hir::db::AstDatabaseStorage, |
12 | hir::db::DefDatabaseStorage, | ||
13 | hir::db::DefDatabase2Storage, | 12 | hir::db::DefDatabase2Storage, |
14 | hir::db::HirDatabaseStorage | 13 | hir::db::HirDatabaseStorage |
15 | )] | 14 | )] |
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..2dca0f637 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,23 +17,17 @@ 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 | DefDatabase2, DefDatabase2Storage, 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, | 30 | pub use DefDatabase2 as DefDatabase; |
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 | 31 | ||
39 | #[salsa::query_group(HirDatabaseStorage)] | 32 | #[salsa::query_group(HirDatabaseStorage)] |
40 | #[salsa::requires(salsa::Database)] | 33 | #[salsa::requires(salsa::Database)] |
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..c369a80d4 100644 --- a/crates/ra_hir/src/test_db.rs +++ b/crates/ra_hir/src/test_db.rs | |||
@@ -14,7 +14,6 @@ use crate::{db, debug::HirDebugHelper}; | |||
14 | ra_db::SourceDatabaseStorage, | 14 | ra_db::SourceDatabaseStorage, |
15 | db::InternDatabaseStorage, | 15 | db::InternDatabaseStorage, |
16 | db::AstDatabaseStorage, | 16 | db::AstDatabaseStorage, |
17 | db::DefDatabaseStorage, | ||
18 | db::DefDatabase2Storage, | 17 | db::DefDatabase2Storage, |
19 | db::HirDatabaseStorage | 18 | db::HirDatabaseStorage |
20 | )] | 19 | )] |
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index e87bd525a..1481868d0 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::{ |
@@ -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..1b5c85437 --- /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::DefDatabase2, 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 DefDatabase2, | ||
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/lib.rs b/crates/ra_hir_def/src/lib.rs index 899510be4..1ba7c7ee3 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 | ||
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index c96465b6a..7d35d2137 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs | |||
@@ -21,7 +21,6 @@ use crate::{ | |||
21 | symbol_index::SymbolsDatabaseStorage, | 21 | symbol_index::SymbolsDatabaseStorage, |
22 | hir::db::InternDatabaseStorage, | 22 | hir::db::InternDatabaseStorage, |
23 | hir::db::AstDatabaseStorage, | 23 | hir::db::AstDatabaseStorage, |
24 | hir::db::DefDatabaseStorage, | ||
25 | hir::db::DefDatabase2Storage, | 24 | hir::db::DefDatabase2Storage, |
26 | hir::db::HirDatabaseStorage | 25 | hir::db::HirDatabaseStorage |
27 | )] | 26 | )] |