blob: b1b47af9e63476e42e04eae14a9f9298f386c1bd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
use ra_syntax::ast;
use crate::HirDatabase;
/// Holds documentation
#[derive(Debug, Clone)]
pub struct Documentation(String);
impl Documentation {
pub fn new(s: &str) -> Self {
Self(s.into())
}
pub fn contents(&self) -> &str {
&self.0
}
}
impl Into<String> for Documentation {
fn into(self) -> String {
self.contents().into()
}
}
pub trait Docs {
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation>;
}
pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option<Documentation> {
let comments = node.doc_comment_text();
if comments.is_empty() {
None
} else {
Some(Documentation::new(&comments))
}
}
|