From f47f58ffe5fb494c883ec4fd120cdd63ad31cc68 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 24 Aug 2018 00:13:16 +0300 Subject: [PATCH] better join-lines --- code/src/extension.ts | 1 + crates/libeditor/src/typing.rs | 4 +++- crates/libeditor/tests/test.rs | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/code/src/extension.ts b/code/src/extension.ts index 134459f3047..df2109f507d 100644 --- a/code/src/extension.ts +++ b/code/src/extension.ts @@ -50,6 +50,7 @@ export function activate(context: vscode.ExtensionContext) { let anchor = sel.isEmpty ? active : sel.anchor return new vscode.Selection(anchor, active) }) + editor.revealRange(editor.selection) }) registerCommand('libsyntax-rust.joinLines', async () => { let editor = vscode.window.activeTextEditor diff --git a/crates/libeditor/src/typing.rs b/crates/libeditor/src/typing.rs index 918f2325c00..04021d1640e 100644 --- a/crates/libeditor/src/typing.rs +++ b/crates/libeditor/src/typing.rs @@ -72,9 +72,11 @@ fn remove_newline( if node.kind() == WHITESPACE && node_text.bytes().filter(|&b| b == b'\n').count() == 1 { match (node.prev_sibling(), node.next_sibling()) { (Some(prev), Some(next)) => { + let range = TextRange::from_to(prev.range().start(), node.range().end()); if prev.kind() == COMMA && (next.kind() == R_PAREN || next.kind() == R_BRACK) { - let range = TextRange::from_to(prev.range().start(), node.range().end()); edit.delete(range); + } else if prev.kind() == COMMA && next.kind() == R_CURLY { + edit.replace(range, " ".to_string()); } else { edit.replace( node.range(), diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs index e5088ad2749..858c6c4a649 100644 --- a/crates/libeditor/tests/test.rs +++ b/crates/libeditor/tests/test.rs @@ -223,6 +223,14 @@ fn foo() { fn foo() { foo(1, 2, 3) } +"); + + do_check(r" +struct Foo <|>{ + f: u32, +}<|> +", r" +struct Foo { f: u32 } "); }