2019-01-23 16:22:10 -05:00
|
|
|
use ra_syntax::ast;
|
|
|
|
|
|
|
|
use crate::HirDatabase;
|
|
|
|
|
2019-01-23 20:13:36 -05:00
|
|
|
/// Holds documentation
|
2019-01-23 16:22:10 -05:00
|
|
|
#[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> {
|
2019-01-26 10:35:23 -05:00
|
|
|
node.doc_comment_text().map(|it| Documentation::new(&it))
|
2019-01-23 16:22:10 -05:00
|
|
|
}
|