Merge #4184
4184: Treat comments beginning with four slashes as regular line comments r=kjeremy a=adamrk Addresses https://github.com/rust-analyzer/rust-analyzer/issues/4040 Co-authored-by: adamrk <ark.email@gmail.com>
This commit is contained in:
commit
2096db90b4
@ -242,6 +242,21 @@ fn test_comments_preserve_trailing_whitespace() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_four_slash_line_comment() {
|
||||
let file = SourceFile::parse(
|
||||
r#"
|
||||
//// too many slashes to be a doc comment
|
||||
/// doc comment
|
||||
mod foo {}
|
||||
"#,
|
||||
)
|
||||
.ok()
|
||||
.unwrap();
|
||||
let module = file.syntax().descendants().find_map(Module::cast).unwrap();
|
||||
assert_eq!("doc comment", module.doc_comment_text().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_where_predicates() {
|
||||
fn assert_bound(text: &str, bound: Option<TypeBound>) {
|
||||
|
@ -13,7 +13,12 @@ impl Comment {
|
||||
}
|
||||
|
||||
pub fn prefix(&self) -> &'static str {
|
||||
prefix_by_kind(self.kind())
|
||||
for (prefix, k) in COMMENT_PREFIX_TO_KIND.iter() {
|
||||
if *k == self.kind() && self.text().starts_with(prefix) {
|
||||
return prefix;
|
||||
}
|
||||
}
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,6 +53,7 @@ pub enum CommentPlacement {
|
||||
const COMMENT_PREFIX_TO_KIND: &[(&str, CommentKind)] = {
|
||||
use {CommentPlacement::*, CommentShape::*};
|
||||
&[
|
||||
("////", CommentKind { shape: Line, doc: None }),
|
||||
("///", CommentKind { shape: Line, doc: Some(Outer) }),
|
||||
("//!", CommentKind { shape: Line, doc: Some(Inner) }),
|
||||
("/**", CommentKind { shape: Block, doc: Some(Outer) }),
|
||||
@ -69,15 +75,6 @@ fn kind_by_prefix(text: &str) -> CommentKind {
|
||||
panic!("bad comment text: {:?}", text)
|
||||
}
|
||||
|
||||
fn prefix_by_kind(kind: CommentKind) -> &'static str {
|
||||
for (prefix, k) in COMMENT_PREFIX_TO_KIND.iter() {
|
||||
if *k == kind {
|
||||
return prefix;
|
||||
}
|
||||
}
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
impl Whitespace {
|
||||
pub fn spans_multiple_lines(&self) -> bool {
|
||||
let text = self.text();
|
||||
|
Loading…
x
Reference in New Issue
Block a user