Skip to content

Commit

Permalink
Merge #2716
Browse files Browse the repository at this point in the history
2716: Allow assists with multiple selectable actions r=SomeoneToIgnore a=SomeoneToIgnore

This PR prepares an infra for rust-lang/rust-analyzer#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 <mail4score@gmail.com>
  • Loading branch information
bors[bot] and SomeoneToIgnore committed Jan 15, 2020
2 parents 223a49d + 5a451da commit b3cd7a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rust-analyzer/editors/code/src/commands/index.ts
Expand Up @@ -39,6 +39,18 @@ function applySourceChange(ctx: Ctx): Cmd {
};
}

function selectAndApplySourceChange(ctx: Ctx): Cmd {
return async (changes: sourceChange.SourceChange[]) => {
if (changes.length === 1) {
await sourceChange.applySourceChange(ctx, changes[0]);
} else if (changes.length > 0) {
const selectedChange = await vscode.window.showQuickPick(changes);
if (!selectedChange) return;
await sourceChange.applySourceChange(ctx, selectedChange);
}
};
}

function reload(ctx: Ctx): Cmd {
return async () => {
vscode.window.showInformationMessage('Reloading rust-analyzer...');
Expand All @@ -59,5 +71,6 @@ export {
runSingle,
showReferences,
applySourceChange,
selectAndApplySourceChange,
reload
};
1 change: 1 addition & 0 deletions rust-analyzer/editors/code/src/main.ts
Expand Up @@ -26,6 +26,7 @@ export async function activate(context: vscode.ExtensionContext) {
ctx.registerCommand('runSingle', commands.runSingle);
ctx.registerCommand('showReferences', commands.showReferences);
ctx.registerCommand('applySourceChange', commands.applySourceChange);
ctx.registerCommand('selectAndApplySourceChange', commands.selectAndApplySourceChange);

if (ctx.config.enableEnhancedTyping) {
ctx.overrideCommand('type', commands.onEnter);
Expand Down

0 comments on commit b3cd7a2

Please sign in to comment.