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
|
let anchor = sel.isEmpty ? active : sel.anchor
|
||||||
return new vscode.Selection(anchor, active)
|
return new vscode.Selection(anchor, active)
|
||||||
})
|
})
|
||||||
|
editor.revealRange(editor.selection)
|
||||||
})
|
})
|
||||||
registerCommand('libsyntax-rust.joinLines', async () => {
|
registerCommand('libsyntax-rust.joinLines', async () => {
|
||||||
let editor = vscode.window.activeTextEditor
|
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 {
|
if node.kind() == WHITESPACE && node_text.bytes().filter(|&b| b == b'\n').count() == 1 {
|
||||||
match (node.prev_sibling(), node.next_sibling()) {
|
match (node.prev_sibling(), node.next_sibling()) {
|
||||||
(Some(prev), Some(next)) => {
|
(Some(prev), Some(next)) => {
|
||||||
if prev.kind() == COMMA && (next.kind() == R_PAREN || next.kind() == R_BRACK) {
|
|
||||||
let range = TextRange::from_to(prev.range().start(), node.range().end());
|
let range = TextRange::from_to(prev.range().start(), node.range().end());
|
||||||
|
if prev.kind() == COMMA && (next.kind() == R_PAREN || next.kind() == R_BRACK) {
|
||||||
edit.delete(range);
|
edit.delete(range);
|
||||||
|
} else if prev.kind() == COMMA && next.kind() == R_CURLY {
|
||||||
|
edit.replace(range, " ".to_string());
|
||||||
} else {
|
} else {
|
||||||
edit.replace(
|
edit.replace(
|
||||||
node.range(),
|
node.range(),
|
||||||
|
@ -223,6 +223,14 @@ fn foo() {
|
|||||||
fn foo() {
|
fn foo() {
|
||||||
foo(1, 2, 3)
|
foo(1, 2, 3)
|
||||||
}
|
}
|
||||||
|
");
|
||||||
|
|
||||||
|
do_check(r"
|
||||||
|
struct Foo <|>{
|
||||||
|
f: u32,
|
||||||
|
}<|>
|
||||||
|
", r"
|
||||||
|
struct Foo { f: u32 }
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user