From 8ccd26adf396b49c7ba9e3abe0a92869b1a4c728 Mon Sep 17 00:00:00 2001 From: "Jeremy A. Kolb" Date: Mon, 5 Nov 2018 16:37:27 -0500 Subject: Show documentation for hover requests --- crates/ra_editor/src/symbols.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'crates/ra_editor/src') 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; use ra_syntax::{ algo::visit::{visitor, Visitor}, - ast::{self, NameOwner}, + ast::{self, DocCommentsOwner, NameOwner}, AstNode, File, SmolStr, SyntaxKind, SyntaxNodeRef, WalkEvent, }; @@ -22,6 +22,30 @@ pub struct FileSymbol { pub kind: SyntaxKind, } +impl FileSymbol { + pub fn docs(&self, file: &File) -> Option { + file.syntax().descendants() + .filter(|node| node.kind() == self.kind && node.range() == self.node_range) + .filter_map(|node: SyntaxNodeRef| { + fn doc_comments<'a, N: DocCommentsOwner<'a>>(node: N) -> Option { + let comments = node.doc_comment_text(); + if comments.is_empty() { None } else { Some(comments) } + } + + visitor() + .visit(doc_comments::) + .visit(doc_comments::) + .visit(doc_comments::) + .visit(doc_comments::) + .visit(doc_comments::) + .visit(doc_comments::) + .visit(doc_comments::) + .visit(doc_comments::) + .accept(node)? + }).nth(0) + } +} + pub fn file_symbols(file: &File) -> Vec { file.syntax().descendants().filter_map(to_symbol).collect() } -- cgit v1.2.3