mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Item up and down movers
This commit is contained in:
parent
d704750ba9
commit
7d60458495
11 changed files with 536 additions and 1 deletions
|
@ -134,6 +134,34 @@ export function joinLines(ctx: Ctx): Cmd {
|
|||
};
|
||||
}
|
||||
|
||||
export function moveItemUp(ctx: Ctx): Cmd {
|
||||
return moveItem(ctx, ra.Direction.Up);
|
||||
}
|
||||
|
||||
export function moveItemDown(ctx: Ctx): Cmd {
|
||||
return moveItem(ctx, ra.Direction.Down);
|
||||
}
|
||||
|
||||
export function moveItem(ctx: Ctx, direction: ra.Direction): Cmd {
|
||||
return async () => {
|
||||
const editor = ctx.activeRustEditor;
|
||||
const client = ctx.client;
|
||||
if (!editor || !client) return;
|
||||
|
||||
const edit: lc.TextDocumentEdit = await client.sendRequest(ra.moveItem, {
|
||||
range: client.code2ProtocolConverter.asRange(editor.selection),
|
||||
textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
|
||||
direction
|
||||
});
|
||||
|
||||
await editor.edit((builder) => {
|
||||
client.protocol2CodeConverter.asTextEdits(edit.edits).forEach((edit: any) => {
|
||||
builder.replace(edit.range, edit.newText);
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function onEnter(ctx: Ctx): Cmd {
|
||||
async function handleKeypress() {
|
||||
const editor = ctx.activeRustEditor;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue