mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Merge #424
424: remove non-doc comments from doc comments r=matklad a=csmoe Closes #357 Co-authored-by: csmoe <csmoe@msn.com>
This commit is contained in:
commit
821fa7a50a
5 changed files with 50 additions and 2 deletions
|
@ -394,7 +394,7 @@ impl Analysis {
|
||||||
pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> {
|
pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> {
|
||||||
self.db.doc_text_for(nav)
|
self.db.doc_text_for(nav)
|
||||||
}
|
}
|
||||||
/// Returns a `mod name;` declaration whihc created the current module.
|
/// Returns a `mod name;` declaration which created the current module.
|
||||||
pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> {
|
pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> {
|
||||||
self.db.parent_module(position)
|
self.db.parent_module(position)
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,7 +249,8 @@ fn bar() {
|
||||||
fn test_fn_signature_with_docs_simple() {
|
fn test_fn_signature_with_docs_simple() {
|
||||||
let (desc, param) = get_signature(
|
let (desc, param) = get_signature(
|
||||||
r#"
|
r#"
|
||||||
// test
|
/// test
|
||||||
|
// non-doc-comment
|
||||||
fn foo(j: u32) -> u32 {
|
fn foo(j: u32) -> u32 {
|
||||||
j
|
j
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,7 @@ pub trait DocCommentsOwner<'a>: AstNode<'a> {
|
||||||
/// That is, strips leading `///` and joins lines
|
/// That is, strips leading `///` and joins lines
|
||||||
fn doc_comment_text(self) -> RustString {
|
fn doc_comment_text(self) -> RustString {
|
||||||
self.doc_comments()
|
self.doc_comments()
|
||||||
|
.filter(|comment| comment.is_doc_comment())
|
||||||
.map(|comment| {
|
.map(|comment| {
|
||||||
let prefix = comment.prefix();
|
let prefix = comment.prefix();
|
||||||
let trimmed = comment
|
let trimmed = comment
|
||||||
|
@ -206,6 +207,10 @@ impl<'a> Comment<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_doc_comment(&self) -> bool {
|
||||||
|
self.flavor().is_doc_comment()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn prefix(&self) -> &'static str {
|
pub fn prefix(&self) -> &'static str {
|
||||||
self.flavor().prefix()
|
self.flavor().prefix()
|
||||||
}
|
}
|
||||||
|
@ -237,6 +242,13 @@ impl CommentFlavor {
|
||||||
Multiline => "/*",
|
Multiline => "/*",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_doc_comment(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
CommentFlavor::Doc | CommentFlavor::ModuleDoc => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Whitespace<'a> {
|
impl<'a> Whitespace<'a> {
|
||||||
|
@ -469,3 +481,16 @@ impl<'a> PrefixExpr<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_doc_comment_of_items() {
|
||||||
|
let file = SourceFileNode::parse(
|
||||||
|
r#"
|
||||||
|
//! doc
|
||||||
|
// non-doc
|
||||||
|
mod foo {}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
let module = file.syntax().descendants().find_map(Module::cast).unwrap();
|
||||||
|
assert_eq!("doc", module.doc_comment_text());
|
||||||
|
}
|
||||||
|
|
5
crates/ra_syntax/tests/data/parser/ok/0037_mod.rs
Normal file
5
crates/ra_syntax/tests/data/parser/ok/0037_mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
// https://github.com/rust-analyzer/rust-analyzer/issues/357
|
||||||
|
|
||||||
|
//! docs
|
||||||
|
// non-docs
|
||||||
|
mod foo {}
|
17
crates/ra_syntax/tests/data/parser/ok/0037_mod.txt
Normal file
17
crates/ra_syntax/tests/data/parser/ok/0037_mod.txt
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
SOURCE_FILE@[0; 93)
|
||||||
|
COMMENT@[0; 60)
|
||||||
|
WHITESPACE@[60; 62)
|
||||||
|
MODULE@[62; 93)
|
||||||
|
COMMENT@[62; 70)
|
||||||
|
WHITESPACE@[70; 71)
|
||||||
|
COMMENT@[71; 82)
|
||||||
|
WHITESPACE@[82; 83)
|
||||||
|
MOD_KW@[83; 86)
|
||||||
|
WHITESPACE@[86; 87)
|
||||||
|
NAME@[87; 90)
|
||||||
|
IDENT@[87; 90) "foo"
|
||||||
|
WHITESPACE@[90; 91)
|
||||||
|
ITEM_LIST@[91; 93)
|
||||||
|
L_CURLY@[91; 92)
|
||||||
|
R_CURLY@[92; 93)
|
||||||
|
|
Loading…
Reference in a new issue