diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs index 7c979694de39..6bcf2d72b627 100644 --- a/crates/ra_ide/src/typing/on_enter.rs +++ b/crates/ra_ide/src/typing/on_enter.rs @@ -32,8 +32,8 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option Option 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 { let ws = match file.syntax().token_at_offset(token.text_range().start()) { TokenAtOffset::Between(l, r) => { @@ -152,7 +163,7 @@ fn does_not_continue_before_doc_comment() { } #[test] - fn continues_code_comment_in_the_middle() { + fn continues_code_comment_in_the_middle_of_line() { do_check( r" 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] fn does_not_continue_end_of_code_comment() { do_check_noop(