better join-lines

This commit is contained in:
Aleksey Kladov 2018-08-24 00:13:16 +03:00
parent 8ad586a44e
commit f47f58ffe5
3 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -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(),

View File

@ -223,6 +223,14 @@ fn foo() {
fn foo() {
foo(1, 2, 3)
}
");
do_check(r"
struct Foo <|>{
f: u32,
}<|>
", r"
struct Foo { f: u32 }
");
}