diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-31 19:41:24 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-31 19:41:24 +0000 |
commit | 55ebe6380aef233fff86b7e6cead361787bf1f65 (patch) | |
tree | 9ed060e4738a0504ddfd146649b9cf8a2f2fac40 /crates/ra_syntax/src/ast/mod.rs | |
parent | dfba29e4fb66457d101db295e3c356a932ac005e (diff) | |
parent | 74320945b664916005d263552194201cbe9a52bc (diff) |
Merge #167
167: Attempt to extract useful comments from function signatures r=matklad a=kjeremy
I'm trying to extract useful function comments for signature info. This will also be useful for hover. This is a WIP (and actually works pretty well!) but I don't think it's the right approach long term so some guidance would be appreciated so that we could also get comments for say types and variable instances etc.
Currently `test_fn_signature_with_simple_doc` fails due to a bug in `extend` but we probably shouldn't use this approach anyway. Maybe comments should be attached to nodes somehow? I'm also thinking that maybe the markdown bits should live in the language server.
Thoughts?
Co-authored-by: Jeremy A. Kolb <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast/mod.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/mod.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/mod.rs b/crates/ra_syntax/src/ast/mod.rs index c033263a1..3aa11b9dd 100644 --- a/crates/ra_syntax/src/ast/mod.rs +++ b/crates/ra_syntax/src/ast/mod.rs | |||
@@ -65,6 +65,24 @@ pub trait AttrsOwner<'a>: AstNode<'a> { | |||
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | pub trait DocCommentsOwner<'a>: AstNode<'a> { | ||
69 | fn doc_comments(self) -> AstChildren<'a, Comment<'a>> { children(self) } | ||
70 | |||
71 | /// Returns the textual content of a doc comment block as a single string. | ||
72 | /// That is, strips leading `///` and joins lines | ||
73 | fn doc_comment_text(self) -> String { | ||
74 | self.doc_comments() | ||
75 | .map(|comment| { | ||
76 | let prefix = comment.prefix(); | ||
77 | let trimmed = comment.text().as_str() | ||
78 | .trim() | ||
79 | .trim_start_matches(prefix) | ||
80 | .trim_start(); | ||
81 | trimmed.to_owned() | ||
82 | }).join("\n") | ||
83 | } | ||
84 | } | ||
85 | |||
68 | impl<'a> FnDef<'a> { | 86 | impl<'a> FnDef<'a> { |
69 | pub fn has_atom_attr(&self, atom: &str) -> bool { | 87 | pub fn has_atom_attr(&self, atom: &str) -> bool { |
70 | self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) | 88 | self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) |