mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Init implementation of structural search replace
This commit is contained in:
parent
6fb36dfdcb
commit
f8f454ab5c
10 changed files with 399 additions and 1 deletions
|
@ -12,6 +12,7 @@ export * from './parent_module';
|
|||
export * from './syntax_tree';
|
||||
export * from './expand_macro';
|
||||
export * from './runnables';
|
||||
export * from './ssr';
|
||||
|
||||
export function collectGarbage(ctx: Ctx): Cmd {
|
||||
return async () => {
|
||||
|
|
36
editors/code/src/commands/ssr.ts
Normal file
36
editors/code/src/commands/ssr.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { Ctx, Cmd } from '../ctx';
|
||||
import { applySourceChange, SourceChange } from '../source_change';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export function ssr(ctx: Ctx): Cmd {
|
||||
return async () => {
|
||||
const client = ctx.client;
|
||||
if (!client) return;
|
||||
|
||||
const options: vscode.InputBoxOptions = {
|
||||
placeHolder: "foo($a:expr, $b:expr) ==>> bar($a, foo($b))",
|
||||
prompt: "Enter request",
|
||||
validateInput: (x: string) => {
|
||||
if (x.includes('==>>')) {
|
||||
return null;
|
||||
}
|
||||
return "Enter request: pattern ==>> template"
|
||||
}
|
||||
}
|
||||
const request = await vscode.window.showInputBox(options);
|
||||
|
||||
if (!request) return;
|
||||
|
||||
const ssrRequest: SsrRequest = { arg: request };
|
||||
const change = await client.sendRequest<SourceChange>(
|
||||
'rust-analyzer/ssr',
|
||||
ssrRequest,
|
||||
);
|
||||
|
||||
await applySourceChange(ctx, change);
|
||||
};
|
||||
}
|
||||
|
||||
interface SsrRequest {
|
||||
arg: string;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue