diff options
author | Aleksey Kladov <[email protected]> | 2018-08-23 22:13:16 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-23 22:13:16 +0100 |
commit | f47f58ffe5fb494c883ec4fd120cdd63ad31cc68 (patch) | |
tree | 88ea9aebf54da8008a9adc359e0e613d6a160a61 | |
parent | 8ad586a44e2214a11c4e7d27e0d3c2d73e43f39f (diff) |
better join-lines
-rw-r--r-- | code/src/extension.ts | 1 | ||||
-rw-r--r-- | crates/libeditor/src/typing.rs | 4 | ||||
-rw-r--r-- | crates/libeditor/tests/test.rs | 8 |
3 files changed, 12 insertions, 1 deletions
diff --git a/code/src/extension.ts b/code/src/extension.ts index 134459f30..df2109f50 100644 --- a/code/src/extension.ts +++ b/code/src/extension.ts | |||
@@ -50,6 +50,7 @@ export function activate(context: vscode.ExtensionContext) { | |||
50 | let anchor = sel.isEmpty ? active : sel.anchor | 50 | let anchor = sel.isEmpty ? active : sel.anchor |
51 | return new vscode.Selection(anchor, active) | 51 | return new vscode.Selection(anchor, active) |
52 | }) | 52 | }) |
53 | editor.revealRange(editor.selection) | ||
53 | }) | 54 | }) |
54 | registerCommand('libsyntax-rust.joinLines', async () => { | 55 | registerCommand('libsyntax-rust.joinLines', async () => { |
55 | let editor = vscode.window.activeTextEditor | 56 | let editor = vscode.window.activeTextEditor |
diff --git a/crates/libeditor/src/typing.rs b/crates/libeditor/src/typing.rs index 918f2325c..04021d164 100644 --- a/crates/libeditor/src/typing.rs +++ b/crates/libeditor/src/typing.rs | |||
@@ -72,9 +72,11 @@ fn remove_newline( | |||
72 | if node.kind() == WHITESPACE && node_text.bytes().filter(|&b| b == b'\n').count() == 1 { | 72 | if node.kind() == WHITESPACE && node_text.bytes().filter(|&b| b == b'\n').count() == 1 { |
73 | match (node.prev_sibling(), node.next_sibling()) { | 73 | match (node.prev_sibling(), node.next_sibling()) { |
74 | (Some(prev), Some(next)) => { | 74 | (Some(prev), Some(next)) => { |
75 | let range = TextRange::from_to(prev.range().start(), node.range().end()); | ||
75 | if prev.kind() == COMMA && (next.kind() == R_PAREN || next.kind() == R_BRACK) { | 76 | if prev.kind() == COMMA && (next.kind() == R_PAREN || next.kind() == R_BRACK) { |
76 | let range = TextRange::from_to(prev.range().start(), node.range().end()); | ||
77 | edit.delete(range); | 77 | edit.delete(range); |
78 | } else if prev.kind() == COMMA && next.kind() == R_CURLY { | ||
79 | edit.replace(range, " ".to_string()); | ||
78 | } else { | 80 | } else { |
79 | edit.replace( | 81 | edit.replace( |
80 | node.range(), | 82 | node.range(), |
diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs index e5088ad27..858c6c4a6 100644 --- a/crates/libeditor/tests/test.rs +++ b/crates/libeditor/tests/test.rs | |||
@@ -224,6 +224,14 @@ fn foo() { | |||
224 | foo(1, 2, 3) | 224 | foo(1, 2, 3) |
225 | } | 225 | } |
226 | "); | 226 | "); |
227 | |||
228 | do_check(r" | ||
229 | struct Foo <|>{ | ||
230 | f: u32, | ||
231 | }<|> | ||
232 | ", r" | ||
233 | struct Foo { f: u32 } | ||
234 | "); | ||
227 | } | 235 | } |
228 | 236 | ||
229 | fn file(text: &str) -> ParsedFile { | 237 | fn file(text: &str) -> ParsedFile { |