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/package.json | 5 +++++ editors/code/src/commands/index.ts | 1 + editors/code/src/commands/ssr.ts | 36 ++++++++++++++++++++++++++++++++++++ editors/code/src/main.ts | 1 + 4 files changed, 43 insertions(+) create mode 100644 editors/code/src/commands/ssr.ts (limited to 'editors/code') diff --git a/editors/code/package.json b/editors/code/package.json index db1fe5189..e1a70f05c 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -124,6 +124,11 @@ "command": "rust-analyzer.onEnter", "title": "Enhanced enter key", "category": "Rust Analyzer" + }, + { + "command": "rust-analyzer.ssr", + "title": "Structural Search Replace", + "category": "Rust Analyzer" } ], "keybindings": [ 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; +} diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 5efce41f4..5a99e96f0 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -22,6 +22,7 @@ export async function activate(context: vscode.ExtensionContext) { ctx.registerCommand('run', commands.run); ctx.registerCommand('reload', commands.reload); ctx.registerCommand('onEnter', commands.onEnter); + ctx.registerCommand('ssr', commands.ssr) // Internal commands which are invoked by the server. ctx.registerCommand('runSingle', commands.runSingle); -- cgit v1.2.3