mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Show documentation for hover requests
This commit is contained in:
parent
6df71da81f
commit
8ccd26adf3
6 changed files with 71 additions and 4 deletions
|
@ -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<String> {
|
||||
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<String> {
|
||||
let comments = node.doc_comment_text();
|
||||
if comments.is_empty() { None } else { Some(comments) }
|
||||
}
|
||||
|
||||
visitor()
|
||||
.visit(doc_comments::<ast::FnDef>)
|
||||
.visit(doc_comments::<ast::StructDef>)
|
||||
.visit(doc_comments::<ast::EnumDef>)
|
||||
.visit(doc_comments::<ast::TraitDef>)
|
||||
.visit(doc_comments::<ast::Module>)
|
||||
.visit(doc_comments::<ast::TypeDef>)
|
||||
.visit(doc_comments::<ast::ConstDef>)
|
||||
.visit(doc_comments::<ast::StaticDef>)
|
||||
.accept(node)?
|
||||
}).nth(0)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file_symbols(file: &File) -> Vec<FileSymbol> {
|
||||
file.syntax().descendants().filter_map(to_symbol).collect()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue