]> git.lizzy.rs Git - rust.git/blob - crates/ra_hir/src/docs.rs
Add a comment
[rust.git] / crates / ra_hir / src / docs.rs
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 }