aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src
diff options
context:
space:
mode:
authorJeremy A. Kolb <[email protected]>2018-11-05 21:37:27 +0000
committerAleksey Kladov <[email protected]>2018-11-07 15:24:55 +0000
commit8ccd26adf396b49c7ba9e3abe0a92869b1a4c728 (patch)
tree2c234f6095e8299f5b4606fe7c4a92d4373f7a5c /crates/ra_editor/src
parent6df71da81f9260890ac42ed992946543d697e57c (diff)
Show documentation for hover requests
Diffstat (limited to 'crates/ra_editor/src')
-rw-r--r--crates/ra_editor/src/symbols.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/crates/ra_editor/src/symbols.rs b/crates/ra_editor/src/symbols.rs
index 4e602d0e3..bf3ac6ff2 100644
--- a/crates/ra_editor/src/symbols.rs
+++ b/crates/ra_editor/src/symbols.rs
@@ -2,7 +2,7 @@ use crate::TextRange;
2 2
3use ra_syntax::{ 3use ra_syntax::{
4 algo::visit::{visitor, Visitor}, 4 algo::visit::{visitor, Visitor},
5 ast::{self, NameOwner}, 5 ast::{self, DocCommentsOwner, NameOwner},
6 AstNode, File, SmolStr, SyntaxKind, SyntaxNodeRef, WalkEvent, 6 AstNode, File, SmolStr, SyntaxKind, SyntaxNodeRef, WalkEvent,
7}; 7};
8 8
@@ -22,6 +22,30 @@ pub struct FileSymbol {
22 pub kind: SyntaxKind, 22 pub kind: SyntaxKind,
23} 23}
24 24
25impl FileSymbol {
26 pub fn docs(&self, file: &File) -> Option<String> {
27 file.syntax().descendants()
28 .filter(|node| node.kind() == self.kind && node.range() == self.node_range)
29 .filter_map(|node: SyntaxNodeRef| {
30 fn doc_comments<'a, N: DocCommentsOwner<'a>>(node: N) -> Option<String> {
31 let comments = node.doc_comment_text();
32 if comments.is_empty() { None } else { Some(comments) }
33 }
34
35 visitor()
36 .visit(doc_comments::<ast::FnDef>)
37 .visit(doc_comments::<ast::StructDef>)
38 .visit(doc_comments::<ast::EnumDef>)
39 .visit(doc_comments::<ast::TraitDef>)
40 .visit(doc_comments::<ast::Module>)
41 .visit(doc_comments::<ast::TypeDef>)
42 .visit(doc_comments::<ast::ConstDef>)
43 .visit(doc_comments::<ast::StaticDef>)
44 .accept(node)?
45 }).nth(0)
46 }
47}
48
25pub fn file_symbols(file: &File) -> Vec<FileSymbol> { 49pub fn file_symbols(file: &File) -> Vec<FileSymbol> {
26 file.syntax().descendants().filter_map(to_symbol).collect() 50 file.syntax().descendants().filter_map(to_symbol).collect()
27} 51}