From 85c30b1915314487515f69f32dfe5e1a7301ab95 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 11 Mar 2020 12:56:12 +0100 Subject: Continue multiline non-doc comment blocks --- crates/ra_ide/src/typing/on_enter.rs | 38 +++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs index 7c979694d..6bcf2d72b 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 foo() { } #[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( -- cgit v1.2.3