mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
ast::DocCommentsOwner
which represents a documentation comment owner
This commit is contained in:
parent
64ce895ef0
commit
d2bcd1a386
3 changed files with 20 additions and 0 deletions
|
@ -864,6 +864,7 @@ impl<'a> AstNode<'a> for FnDef<'a> {
|
||||||
impl<'a> ast::NameOwner<'a> for FnDef<'a> {}
|
impl<'a> ast::NameOwner<'a> for FnDef<'a> {}
|
||||||
impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {}
|
impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {}
|
||||||
impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {}
|
impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {}
|
||||||
|
impl<'a> ast::DocCommentsOwner<'a> for FnDef<'a> {}
|
||||||
impl<'a> FnDef<'a> {
|
impl<'a> FnDef<'a> {
|
||||||
pub fn param_list(self) -> Option<ParamList<'a>> {
|
pub fn param_list(self) -> Option<ParamList<'a>> {
|
||||||
super::child_opt(self)
|
super::child_opt(self)
|
||||||
|
|
|
@ -65,6 +65,24 @@ pub trait AttrsOwner<'a>: AstNode<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait DocCommentsOwner<'a>: AstNode<'a> {
|
||||||
|
fn doc_comments(self) -> AstChildren<'a, Comment<'a>> { children(self) }
|
||||||
|
|
||||||
|
/// Returns the textual content of a doc comment block as a single string.
|
||||||
|
/// That is, strips leading `///` and joins lines
|
||||||
|
fn doc_comment_text(self) -> String {
|
||||||
|
self.doc_comments()
|
||||||
|
.map(|comment| {
|
||||||
|
let prefix = comment.prefix();
|
||||||
|
let trimmed = comment.text().as_str()
|
||||||
|
.trim()
|
||||||
|
.trim_start_matches(prefix)
|
||||||
|
.trim_start();
|
||||||
|
trimmed.to_owned()
|
||||||
|
}).join("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> FnDef<'a> {
|
impl<'a> FnDef<'a> {
|
||||||
pub fn has_atom_attr(&self, atom: &str) -> bool {
|
pub fn has_atom_attr(&self, atom: &str) -> bool {
|
||||||
self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom)
|
self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom)
|
||||||
|
|
|
@ -251,6 +251,7 @@ Grammar(
|
||||||
"NameOwner",
|
"NameOwner",
|
||||||
"TypeParamsOwner",
|
"TypeParamsOwner",
|
||||||
"AttrsOwner",
|
"AttrsOwner",
|
||||||
|
"DocCommentsOwner"
|
||||||
],
|
],
|
||||||
options: [ "ParamList", ["body", "Block"], "RetType" ],
|
options: [ "ParamList", ["body", "Block"], "RetType" ],
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue