mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 14:03:35 +00:00
Continue multiline non-doc comment blocks
This commit is contained in:
parent
90fe534f03
commit
85c30b1915
1 changed files with 35 additions and 3 deletions
|
@ -32,8 +32,8 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continuing non-doc line comments (like this one :) ) is annoying
|
// Continuing single-line non-doc comments (like this one :) ) is annoying
|
||||||
if prefix == "//" && comment_range.end() == position.offset {
|
if prefix == "//" && comment_range.end() == position.offset && !followed_by_comment(&comment) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,17 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn followed_by_comment(comment: &ast::Comment) -> bool {
|
||||||
|
let ws = match comment.syntax().next_token().and_then(ast::Whitespace::cast) {
|
||||||
|
Some(it) => it,
|
||||||
|
None => return false,
|
||||||
|
};
|
||||||
|
if ws.spans_multiple_lines() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ws.syntax().next_token().and_then(ast::Comment::cast).is_some()
|
||||||
|
}
|
||||||
|
|
||||||
fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option<SmolStr> {
|
fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option<SmolStr> {
|
||||||
let ws = match file.syntax().token_at_offset(token.text_range().start()) {
|
let ws = match file.syntax().token_at_offset(token.text_range().start()) {
|
||||||
TokenAtOffset::Between(l, r) => {
|
TokenAtOffset::Between(l, r) => {
|
||||||
|
@ -152,7 +163,7 @@ fn foo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn continues_code_comment_in_the_middle() {
|
fn continues_code_comment_in_the_middle_of_line() {
|
||||||
do_check(
|
do_check(
|
||||||
r"
|
r"
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -170,6 +181,27 @@ fn main() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn continues_code_comment_in_the_middle_several_lines() {
|
||||||
|
do_check(
|
||||||
|
r"
|
||||||
|
fn main() {
|
||||||
|
// Fix<|>
|
||||||
|
// me
|
||||||
|
let x = 1 + 1;
|
||||||
|
}
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
fn main() {
|
||||||
|
// Fix
|
||||||
|
// <|>
|
||||||
|
// me
|
||||||
|
let x = 1 + 1;
|
||||||
|
}
|
||||||
|
",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn does_not_continue_end_of_code_comment() {
|
fn does_not_continue_end_of_code_comment() {
|
||||||
do_check_noop(
|
do_check_noop(
|
||||||
|
|
Loading…
Reference in a new issue