From f8f454ab5c19c6e7d91b3a4e6bb63fb9bf5f2673 Mon Sep 17 00:00:00 2001 From: Mikhail Modin Date: Mon, 10 Feb 2020 22:45:38 +0000 Subject: Init implementation of structural search replace --- editors/code/src/commands/index.ts | 1 + editors/code/src/commands/ssr.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 editors/code/src/commands/ssr.ts (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index aee969432..b5ebec117 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts @@ -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 () => { diff --git a/editors/code/src/commands/ssr.ts b/editors/code/src/commands/ssr.ts new file mode 100644 index 000000000..6287bf47b --- /dev/null +++ b/editors/code/src/commands/ssr.ts @@ -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( + 'rust-analyzer/ssr', + ssrRequest, + ); + + await applySourceChange(ctx, change); + }; +} + +interface SsrRequest { + arg: string; +} -- cgit v1.2.3