aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/docs.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2020-12-07 17:06:46 +0000
committerLukas Wirth <[email protected]>2020-12-07 18:58:17 +0000
commitb3652ef2886e01f772559aa90df4c45e7c7fb1fd (patch)
tree91f2a10f146d17fba626a4125d3a1fe1956e7f00 /crates/hir_def/src/docs.rs
parent03b886de53834168dd52b5e504a649292f129ae6 (diff)
Remove documentation query
Diffstat (limited to 'crates/hir_def/src/docs.rs')
-rw-r--r--crates/hir_def/src/docs.rs48
1 files changed, 3 insertions, 45 deletions
diff --git a/crates/hir_def/src/docs.rs b/crates/hir_def/src/docs.rs
index 3e59a8f47..6a27effef 100644
--- a/crates/hir_def/src/docs.rs
+++ b/crates/hir_def/src/docs.rs
@@ -5,16 +5,9 @@
5 5
6use std::sync::Arc; 6use std::sync::Arc;
7 7
8use either::Either;
9use itertools::Itertools; 8use itertools::Itertools;
10use syntax::{ast, SmolStr}; 9use syntax::{ast, SmolStr};
11 10
12use crate::{
13 db::DefDatabase,
14 src::{HasChildSource, HasSource},
15 AdtId, AttrDefId, Lookup,
16};
17
18/// Holds documentation 11/// Holds documentation
19#[derive(Debug, Clone, PartialEq, Eq)] 12#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct Documentation(Arc<str>); 13pub struct Documentation(Arc<str>);
@@ -26,7 +19,7 @@ impl Into<String> for Documentation {
26} 19}
27 20
28impl Documentation { 21impl Documentation {
29 fn new(s: &str) -> Documentation { 22 pub fn new(s: &str) -> Documentation {
30 Documentation(s.into()) 23 Documentation(s.into())
31 } 24 }
32 25
@@ -40,42 +33,6 @@ impl Documentation {
40 pub fn as_str(&self) -> &str { 33 pub fn as_str(&self) -> &str {
41 &*self.0 34 &*self.0
42 } 35 }
43
44 pub(crate) fn documentation_query(
45 db: &dyn DefDatabase,
46 def: AttrDefId,
47 ) -> Option<Documentation> {
48 match def {
49 AttrDefId::ModuleId(module) => {
50 let def_map = db.crate_def_map(module.krate);
51 let src = def_map[module.local_id].declaration_source(db)?;
52 docs_from_ast(&src.value)
53 }
54 AttrDefId::FieldId(it) => {
55 let src = it.parent.child_source(db);
56 match &src.value[it.local_id] {
57 Either::Left(_tuple) => None,
58 Either::Right(record) => docs_from_ast(record),
59 }
60 }
61 AttrDefId::AdtId(it) => match it {
62 AdtId::StructId(it) => docs_from_ast(&it.lookup(db).source(db).value),
63 AdtId::EnumId(it) => docs_from_ast(&it.lookup(db).source(db).value),
64 AdtId::UnionId(it) => docs_from_ast(&it.lookup(db).source(db).value),
65 },
66 AttrDefId::EnumVariantId(it) => {
67 let src = it.parent.child_source(db);
68 docs_from_ast(&src.value[it.local_id])
69 }
70 AttrDefId::TraitId(it) => docs_from_ast(&it.lookup(db).source(db).value),
71 AttrDefId::MacroDefId(it) => docs_from_ast(&it.ast_id?.to_node(db.upcast())),
72 AttrDefId::ConstId(it) => docs_from_ast(&it.lookup(db).source(db).value),
73 AttrDefId::StaticId(it) => docs_from_ast(&it.lookup(db).source(db).value),
74 AttrDefId::FunctionId(it) => docs_from_ast(&it.lookup(db).source(db).value),
75 AttrDefId::TypeAliasId(it) => docs_from_ast(&it.lookup(db).source(db).value),
76 AttrDefId::ImplId(_) => None,
77 }
78 }
79} 36}
80 37
81pub(crate) fn docs_from_ast<N>(node: &N) -> Option<Documentation> 38pub(crate) fn docs_from_ast<N>(node: &N) -> Option<Documentation>
@@ -94,7 +51,8 @@ fn merge_doc_comments_and_attrs(
94) -> Option<String> { 51) -> Option<String> {
95 match (doc_comment_text, doc_attr_text) { 52 match (doc_comment_text, doc_attr_text) {
96 (Some(mut comment_text), Some(attr_text)) => { 53 (Some(mut comment_text), Some(attr_text)) => {
97 comment_text.push_str("\n"); 54 comment_text.reserve(attr_text.len() + 1);
55 comment_text.push('\n');
98 comment_text.push_str(&attr_text); 56 comment_text.push_str(&attr_text);
99 Some(comment_text) 57 Some(comment_text)
100 } 58 }