aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-01-15 18:43:23 +0000
committerGitHub <[email protected]>2020-01-15 18:43:23 +0000
commitaa2e13b37f4508168fb064a79d0190fa705d8a47 (patch)
tree15d4b618885813c2c9efadd2ea0d25a7173807c8 /editors/code
parent01422cc31d1917aaef4b1f402eda05abfff1e75f (diff)
parent79b77403b65877e4d20bbbac6dd853a3beead445 (diff)
Merge #2716
2716: Allow assists with multiple selectable actions r=SomeoneToIgnore a=SomeoneToIgnore This PR prepares an infra for https://github.com/rust-analyzer/rust-analyzer/issues/2180 task by adding a possibility to specify multiple actions in one assist as multiple edit parameters to the `applySourceChange` command. When this is done, the command opens a selection dialog, allowing the user to pick the edit to be applied. I have no working example to test in this PR, but here's a demo of an auto import feature (a separate PR coming later for that one) using this functionality: ![out](https://user-images.githubusercontent.com/2690773/71633614-f8ea4d80-2c1d-11ea-9b15-0e13611a7aa4.gif) The PR is not that massive as it may seem: all the assist files' changes are very generic and similar. Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/src/commands/index.ts13
-rw-r--r--editors/code/src/main.ts1
2 files changed, 14 insertions, 0 deletions
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts
index 9a1697dcb..dc075aa82 100644
--- a/editors/code/src/commands/index.ts
+++ b/editors/code/src/commands/index.ts
@@ -39,6 +39,18 @@ function applySourceChange(ctx: Ctx): Cmd {
39 }; 39 };
40} 40}
41 41
42function selectAndApplySourceChange(ctx: Ctx): Cmd {
43 return async (changes: sourceChange.SourceChange[]) => {
44 if (changes.length === 1) {
45 await sourceChange.applySourceChange(ctx, changes[0]);
46 } else if (changes.length > 0) {
47 const selectedChange = await vscode.window.showQuickPick(changes);
48 if (!selectedChange) return;
49 await sourceChange.applySourceChange(ctx, selectedChange);
50 }
51 };
52}
53
42function reload(ctx: Ctx): Cmd { 54function reload(ctx: Ctx): Cmd {
43 return async () => { 55 return async () => {
44 vscode.window.showInformationMessage('Reloading rust-analyzer...'); 56 vscode.window.showInformationMessage('Reloading rust-analyzer...');
@@ -59,5 +71,6 @@ export {
59 runSingle, 71 runSingle,
60 showReferences, 72 showReferences,
61 applySourceChange, 73 applySourceChange,
74 selectAndApplySourceChange,
62 reload 75 reload
63}; 76};
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 430ad31b4..0494ccf63 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -26,6 +26,7 @@ export async function activate(context: vscode.ExtensionContext) {
26 ctx.registerCommand('runSingle', commands.runSingle); 26 ctx.registerCommand('runSingle', commands.runSingle);
27 ctx.registerCommand('showReferences', commands.showReferences); 27 ctx.registerCommand('showReferences', commands.showReferences);
28 ctx.registerCommand('applySourceChange', commands.applySourceChange); 28 ctx.registerCommand('applySourceChange', commands.applySourceChange);
29 ctx.registerCommand('selectAndApplySourceChange', commands.selectAndApplySourceChange);
29 30
30 if (ctx.config.enableEnhancedTyping) { 31 if (ctx.config.enableEnhancedTyping) {
31 ctx.overrideCommand('type', commands.onEnter); 32 ctx.overrideCommand('type', commands.onEnter);