Add way of getting docs from the code model and use for completion

This commit is contained in:
Jeremy A. Kolb 2019-01-23 16:22:10 -05:00
parent 6a6ce2bc95
commit 576625f0a1
5 changed files with 72 additions and 20 deletions

35
crates/ra_hir/src/docs.rs Normal file
View file

@ -0,0 +1,35 @@
use ra_syntax::ast;
use crate::HirDatabase;
#[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))
}
}