From 78a21253b494e573885ac8336bff6e93b401046f Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 12 Jan 2020 00:40:36 +0200 Subject: Apply the api design suggestions --- editors/code/src/commands/index.ts | 17 +++++++++++++++-- editors/code/src/main.ts | 1 + editors/code/src/source_change.ts | 12 +----------- 3 files changed, 17 insertions(+), 13 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index 0ff708b1f..dc075aa82 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts @@ -34,8 +34,20 @@ function showReferences(ctx: Ctx): Cmd { } function applySourceChange(ctx: Ctx): Cmd { - return async (change: sourceChange.SourceChange, alternativeChanges: sourceChange.SourceChange[] | undefined) => { - sourceChange.applySourceChange(ctx, change, alternativeChanges); + return async (change: sourceChange.SourceChange) => { + sourceChange.applySourceChange(ctx, change); + }; +} + +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); + } }; } @@ -59,5 +71,6 @@ export { runSingle, showReferences, applySourceChange, + selectAndApplySourceChange, reload }; 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) { 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); diff --git a/editors/code/src/source_change.ts b/editors/code/src/source_change.ts index b19d325d5..a336269ba 100644 --- a/editors/code/src/source_change.ts +++ b/editors/code/src/source_change.ts @@ -9,7 +9,7 @@ export interface SourceChange { cursorPosition?: lc.TextDocumentPositionParams; } -async function applySelectedSourceChange(ctx: Ctx, change: SourceChange) { +export async function applySourceChange(ctx: Ctx, change: SourceChange) { const client = ctx.client; if (!client) return; @@ -55,13 +55,3 @@ async function applySelectedSourceChange(ctx: Ctx, change: SourceChange) { ); } } - -export async function applySourceChange(ctx: Ctx, change: SourceChange, alternativeChanges: SourceChange[] | undefined) { - if (alternativeChanges !== undefined && alternativeChanges.length > 0) { - const selectedChange = await vscode.window.showQuickPick([change, ...alternativeChanges]); - if (!selectedChange) return; - await applySelectedSourceChange(ctx, selectedChange); - } else { - await applySelectedSourceChange(ctx, change); - } -} -- cgit v1.2.3