diff options
Diffstat (limited to 'crates/ra_hir/src/docs.rs')
-rw-r--r-- | crates/ra_hir/src/docs.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs new file mode 100644 index 000000000..b1b47af9e --- /dev/null +++ b/crates/ra_hir/src/docs.rs | |||
@@ -0,0 +1,36 @@ | |||
1 | use ra_syntax::ast; | ||
2 | |||
3 | use crate::HirDatabase; | ||
4 | |||
5 | /// Holds documentation | ||
6 | #[derive(Debug, Clone)] | ||
7 | pub struct Documentation(String); | ||
8 | |||
9 | impl Documentation { | ||
10 | pub fn new(s: &str) -> Self { | ||
11 | Self(s.into()) | ||
12 | } | ||
13 | |||
14 | pub fn contents(&self) -> &str { | ||
15 | &self.0 | ||
16 | } | ||
17 | } | ||
18 | |||
19 | impl Into<String> for Documentation { | ||
20 | fn into(self) -> String { | ||
21 | self.contents().into() | ||
22 | } | ||
23 | } | ||
24 | |||
25 | pub trait Docs { | ||
26 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation>; | ||
27 | } | ||
28 | |||
29 | pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option<Documentation> { | ||
30 | let comments = node.doc_comment_text(); | ||
31 | if comments.is_empty() { | ||
32 | None | ||
33 | } else { | ||
34 | Some(Documentation::new(&comments)) | ||
35 | } | ||
36 | } | ||