mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
31 lines
1004 B
TypeScript
31 lines
1004 B
TypeScript
import * as vscode from 'vscode';
|
|
import * as ra from "../rust-analyzer-api";
|
|
|
|
import { Ctx, Cmd } from '../ctx';
|
|
|
|
export function ssr(ctx: Ctx): Cmd {
|
|
return async () => {
|
|
const client = ctx.client;
|
|
if (!client) return;
|
|
|
|
const options: vscode.InputBoxOptions = {
|
|
value: "() ==>> ()",
|
|
prompt: "Enter request, for example 'Foo($a:expr) ==> Foo::new($a)' ",
|
|
validateInput: async (x: string) => {
|
|
try {
|
|
await client.sendRequest(ra.ssr, { query: x, parseOnly: true });
|
|
} catch (e) {
|
|
return e.toString();
|
|
}
|
|
return null;
|
|
}
|
|
};
|
|
const request = await vscode.window.showInputBox(options);
|
|
if (!request) return;
|
|
|
|
const edit = await client.sendRequest(ra.ssr, { query: request, parseOnly: false });
|
|
|
|
await vscode.workspace.applyEdit(client.protocol2CodeConverter.asWorkspaceEdit(edit));
|
|
};
|
|
}
|