mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Add way of getting docs from the code model and use for completion
This commit is contained in:
parent
6a6ce2bc95
commit
576625f0a1
5 changed files with 72 additions and 20 deletions
35
crates/ra_hir/src/docs.rs
Normal file
35
crates/ra_hir/src/docs.rs
Normal 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))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue