diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-24 01:22:29 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-24 01:22:29 +0000 |
commit | 6a0a4a564accb12b48e703245655e3e3a0637445 (patch) | |
tree | 248097d8ceaded63601e3d663ef795e3bae55bfe /crates/ra_hir/src/docs.rs | |
parent | bf9cd6ee30b3044b61e99e24e82fad56d3965417 (diff) | |
parent | f87ce73579759fdb623f1d8d82880c0d6306746e (diff) |
Merge #621
621: Completion docs for code model r=kjeremy a=kjeremy
Adds a way to access documentation through the code model and exposes it to completions. Also allows us to document enum variants.
Co-authored-by: Jeremy A. Kolb <[email protected]>
Co-authored-by: Jeremy Kolb <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/docs.rs')
-rw-r--r-- | crates/ra_hir/src/docs.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs new file mode 100644 index 000000000..b1b47af9e --- /dev/null +++ b/crates/ra_hir/src/docs.rs | |||
@@ -0,0 +1,36 @@ | |||
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 | } | ||