diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-17 10:02:54 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-17 10:02:54 +0000 |
commit | 93d28fb50c8496d00bfb457a42fb5ee66f83d7b5 (patch) | |
tree | 47a1d15302d542932af992d5243640fff88aa0a4 /editors | |
parent | 429fa445b7aa4dcea8c2456aeb07321fe22c000a (diff) | |
parent | f8f454ab5c19c6e7d91b3a4e6bb63fb9bf5f2673 (diff) |
Merge #3099
3099: Init implementation of structural search replace r=matklad a=mikhail-m1
next steps:
* ignore space and other minor difference
* add support to ra_cli
* call rust parser to check pattern
* documentation
original issue #2267
Co-authored-by: Mikhail Modin <[email protected]>
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/package.json | 5 | ||||
-rw-r--r-- | editors/code/src/commands/index.ts | 1 | ||||
-rw-r--r-- | editors/code/src/commands/ssr.ts | 36 | ||||
-rw-r--r-- | editors/code/src/main.ts | 1 |
4 files changed, 43 insertions, 0 deletions
diff --git a/editors/code/package.json b/editors/code/package.json index 46acbfe76..774fed21d 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -124,6 +124,11 @@ | |||
124 | "command": "rust-analyzer.onEnter", | 124 | "command": "rust-analyzer.onEnter", |
125 | "title": "Enhanced enter key", | 125 | "title": "Enhanced enter key", |
126 | "category": "Rust Analyzer" | 126 | "category": "Rust Analyzer" |
127 | }, | ||
128 | { | ||
129 | "command": "rust-analyzer.ssr", | ||
130 | "title": "Structural Search Replace", | ||
131 | "category": "Rust Analyzer" | ||
127 | } | 132 | } |
128 | ], | 133 | ], |
129 | "keybindings": [ | 134 | "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'; | |||
12 | export * from './syntax_tree'; | 12 | export * from './syntax_tree'; |
13 | export * from './expand_macro'; | 13 | export * from './expand_macro'; |
14 | export * from './runnables'; | 14 | export * from './runnables'; |
15 | export * from './ssr'; | ||
15 | 16 | ||
16 | export function collectGarbage(ctx: Ctx): Cmd { | 17 | export function collectGarbage(ctx: Ctx): Cmd { |
17 | return async () => { | 18 | 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 @@ | |||
1 | import { Ctx, Cmd } from '../ctx'; | ||
2 | import { applySourceChange, SourceChange } from '../source_change'; | ||
3 | import * as vscode from 'vscode'; | ||
4 | |||
5 | export function ssr(ctx: Ctx): Cmd { | ||
6 | return async () => { | ||
7 | const client = ctx.client; | ||
8 | if (!client) return; | ||
9 | |||
10 | const options: vscode.InputBoxOptions = { | ||
11 | placeHolder: "foo($a:expr, $b:expr) ==>> bar($a, foo($b))", | ||
12 | prompt: "Enter request", | ||
13 | validateInput: (x: string) => { | ||
14 | if (x.includes('==>>')) { | ||
15 | return null; | ||
16 | } | ||
17 | return "Enter request: pattern ==>> template" | ||
18 | } | ||
19 | } | ||
20 | const request = await vscode.window.showInputBox(options); | ||
21 | |||
22 | if (!request) return; | ||
23 | |||
24 | const ssrRequest: SsrRequest = { arg: request }; | ||
25 | const change = await client.sendRequest<SourceChange>( | ||
26 | 'rust-analyzer/ssr', | ||
27 | ssrRequest, | ||
28 | ); | ||
29 | |||
30 | await applySourceChange(ctx, change); | ||
31 | }; | ||
32 | } | ||
33 | |||
34 | interface SsrRequest { | ||
35 | arg: string; | ||
36 | } | ||
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) { | |||
22 | ctx.registerCommand('run', commands.run); | 22 | ctx.registerCommand('run', commands.run); |
23 | ctx.registerCommand('reload', commands.reload); | 23 | ctx.registerCommand('reload', commands.reload); |
24 | ctx.registerCommand('onEnter', commands.onEnter); | 24 | ctx.registerCommand('onEnter', commands.onEnter); |
25 | ctx.registerCommand('ssr', commands.ssr) | ||
25 | 26 | ||
26 | // Internal commands which are invoked by the server. | 27 | // Internal commands which are invoked by the server. |
27 | ctx.registerCommand('runSingle', commands.runSingle); | 28 | ctx.registerCommand('runSingle', commands.runSingle); |