aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src/symbols.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_editor/src/symbols.rs')
-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}