mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
better join-lines
This commit is contained in:
parent
8ad586a44e
commit
f47f58ffe5
@ -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
|
||||
|
@ -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(),
|
||||
|
@ -223,6 +223,14 @@ fn foo() {
|
||||
fn foo() {
|
||||
foo(1, 2, 3)
|
||||
}
|
||||
");
|
||||
|
||||
do_check(r"
|
||||
struct Foo <|>{
|
||||
f: u32,
|
||||
}<|>
|
||||
", r"
|
||||
struct Foo { f: u32 }
|
||||
");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user