From 980f42554ec62f47863dcc9ad683cc12e93bf175 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 2 Jun 2021 18:12:23 -0700 Subject: [PATCH 1/4] Add new option to insiders installExtenion command --- src/client/common/application/commands.ts | 6 +++++- src/client/common/application/types.ts | 6 +++++- .../installer/extensionBuildInstaller.ts | 8 +++++-- .../commands/reportIssueCommand.unit.test.ts | 7 +++---- .../extensionBuildInstaller.unit.test.ts | 21 ++++++++++++------- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/client/common/application/commands.ts b/src/client/common/application/commands.ts index 31ad3eba7e47..b5b46b84c670 100644 --- a/src/client/common/application/commands.ts +++ b/src/client/common/application/commands.ts @@ -62,9 +62,13 @@ interface ICommandNameWithoutArgumentTypeMapping { export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgumentTypeMapping { ['vscode.openWith']: [Uri, string]; ['workbench.action.quickOpen']: [string]; - ['workbench.extensions.installExtension']: [Uri | 'ms-python.python']; + ['workbench.extensions.installExtension']: [ + Uri | 'ms-python.python', + { installOnlyNewlyAddedFromExtensionPackVSIX?: boolean } | undefined, + ]; ['workbench.action.files.openFolder']: []; ['workbench.action.openWorkspace']: []; + ['workbench.action.openIssueReporter']: [{ extensionId: string; issueBody: string }]; ['setContext']: [string, boolean] | ['python.vscode.channel', Channel]; ['python.reloadVSCode']: [string]; ['revealLine']: [{ lineNumber: number; at: 'top' | 'center' | 'bottom' }]; diff --git a/src/client/common/application/types.ts b/src/client/common/application/types.ts index 01df5613bd90..ea4263479824 100644 --- a/src/client/common/application/types.ts +++ b/src/client/common/application/types.ts @@ -61,6 +61,7 @@ import { import type { NotebookConcatTextDocument, NotebookDocument } from 'vscode-proposed'; import { IAsyncDisposable, Resource } from '../types'; +import { ICommandNameArgumentTypeMapping } from './commands'; export enum CommandSource { auto = 'auto', @@ -473,7 +474,10 @@ export interface ICommandManager { * @return A thenable that resolves to the returned value of the given command. `undefined` when * the command handler function doesn't return anything. */ - executeCommand(command: string, ...rest: any[]): Thenable; + executeCommand( + command: E, + ...rest: U + ): Thenable; /** * Retrieve the list of all available commands. Commands starting an underscore are diff --git a/src/client/common/installer/extensionBuildInstaller.ts b/src/client/common/installer/extensionBuildInstaller.ts index 984578e1bc4d..cd93040877fb 100644 --- a/src/client/common/installer/extensionBuildInstaller.ts +++ b/src/client/common/installer/extensionBuildInstaller.ts @@ -29,7 +29,9 @@ export class StableBuildInstaller implements IExtensionBuildInstaller { this.output.append(ExtensionChannels.installingStableMessage()); await this.appShell.withProgressCustomIcon(Octicons.Installing, async (progress) => { progress.report({ message: ExtensionChannels.installingStableMessage() }); - return this.cmdManager.executeCommand('workbench.extensions.installExtension', PVSC_EXTENSION_ID); + return this.cmdManager.executeCommand('workbench.extensions.installExtension', PVSC_EXTENSION_ID, { + installOnlyNewlyAddedFromExtensionPackVSIX: true, + }); }); this.output.appendLine(ExtensionChannels.installationCompleteMessage()); } @@ -51,7 +53,9 @@ export class InsidersBuildInstaller implements IExtensionBuildInstaller { this.output.append(ExtensionChannels.installingInsidersMessage()); await this.appShell.withProgressCustomIcon(Octicons.Installing, async (progress) => { progress.report({ message: ExtensionChannels.installingInsidersMessage() }); - return this.cmdManager.executeCommand('workbench.extensions.installExtension', Uri.file(vsixFilePath)); + return this.cmdManager.executeCommand('workbench.extensions.installExtension', Uri.file(vsixFilePath), { + installOnlyNewlyAddedFromExtensionPackVSIX: true, + }); }); this.output.appendLine(ExtensionChannels.installationCompleteMessage()); await this.fs.deleteFile(vsixFilePath); diff --git a/src/test/common/application/commands/reportIssueCommand.unit.test.ts b/src/test/common/application/commands/reportIssueCommand.unit.test.ts index f58c1aaa766d..a4f2761d7e87 100644 --- a/src/test/common/application/commands/reportIssueCommand.unit.test.ts +++ b/src/test/common/application/commands/reportIssueCommand.unit.test.ts @@ -80,10 +80,9 @@ suite('Report Issue Command', () => { ); const expectedIssueBody = fs.readFileSync(templatePath, 'utf8'); - const args: [string, { extensionId: string; issueBody: string }] = capture< - string, - { extensionId: string; issueBody: string } - >(cmdManager.executeCommand).last(); + const args = capture<'workbench.action.openIssueReporter', { extensionId: string; issueBody: string }>( + cmdManager.executeCommand, + ).last(); verify(cmdManager.registerCommand('python.reportIssue', anything(), anything())).once(); verify(cmdManager.executeCommand('workbench.action.openIssueReporter', anything())).once(); diff --git a/src/test/common/installer/extensionBuildInstaller.unit.test.ts b/src/test/common/installer/extensionBuildInstaller.unit.test.ts index 56a8d86d91ef..c69ea5fefaff 100644 --- a/src/test/common/installer/extensionBuildInstaller.unit.test.ts +++ b/src/test/common/installer/extensionBuildInstaller.unit.test.ts @@ -45,16 +45,18 @@ suite('Extension build installer - Stable build installer', async () => { test('Installing stable build logs progress and installs stable', async () => { when(output.append(ExtensionChannels.installingStableMessage())).thenReturn(); when(output.appendLine(ExtensionChannels.installationCompleteMessage())).thenReturn(); - when(cmdManager.executeCommand('workbench.extensions.installExtension', PVSC_EXTENSION_ID)).thenResolve( - undefined, - ); + when( + cmdManager.executeCommand('workbench.extensions.installExtension', PVSC_EXTENSION_ID, anything()), + ).thenResolve(undefined); when(appShell.withProgressCustomIcon(anything(), anything())).thenCall((_, cb) => cb(progressReporter)); await stableBuildInstaller.install(); verify(output.append(ExtensionChannels.installingStableMessage())).once(); verify(output.appendLine(ExtensionChannels.installationCompleteMessage())).once(); verify(appShell.withProgressCustomIcon(anything(), anything())); expect(progressReportStub.callCount).to.equal(1); - verify(cmdManager.executeCommand('workbench.extensions.installExtension', PVSC_EXTENSION_ID)).once(); + verify( + cmdManager.executeCommand('workbench.extensions.installExtension', PVSC_EXTENSION_ID, anything()), + ).once(); }); }); @@ -102,9 +104,12 @@ suite('Extension build installer - Insiders build installer', async () => { }, ); when(appShell.withProgressCustomIcon(anything(), anything())).thenCall((_, cb) => cb(progressReporter)); - when(cmdManager.executeCommand('workbench.extensions.installExtension', anything())).thenCall((_, cb) => { - assert.deepEqual(cb, Uri.file(vsixFilePath), 'Wrong VSIX installed'); - }); + when(cmdManager.executeCommand('workbench.extensions.installExtension', anything(), anything())).thenCall( + (_, uri, options) => { + assert.deepStrictEqual(uri, Uri.file(vsixFilePath), 'Wrong VSIX installed'); + assert.deepStrictEqual(options, { installOnlyNewlyAddedFromExtensionPackVSIX: true }); + }, + ); when(fs.deleteFile(vsixFilePath)).thenResolve(); await insidersBuildInstaller.install(); @@ -115,7 +120,7 @@ suite('Extension build installer - Insiders build installer', async () => { verify(output.appendLine(ExtensionChannels.installationCompleteMessage())).once(); verify(appShell.withProgressCustomIcon(anything(), anything())); expect(progressReportStub.callCount).to.equal(1); - verify(cmdManager.executeCommand('workbench.extensions.installExtension', anything())).once(); + verify(cmdManager.executeCommand('workbench.extensions.installExtension', anything(), anything())).once(); verify(fs.deleteFile(vsixFilePath)).once(); }); }); From 8144eb4fa0b58604c0ffd3447c27b76e5d23a512 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 2 Jun 2021 18:17:32 -0700 Subject: [PATCH 2/4] More strongly enforce call signature --- src/client/common/application/commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/common/application/commands.ts b/src/client/common/application/commands.ts index b5b46b84c670..0f51125de502 100644 --- a/src/client/common/application/commands.ts +++ b/src/client/common/application/commands.ts @@ -64,7 +64,7 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu ['workbench.action.quickOpen']: [string]; ['workbench.extensions.installExtension']: [ Uri | 'ms-python.python', - { installOnlyNewlyAddedFromExtensionPackVSIX?: boolean } | undefined, + { installOnlyNewlyAddedFromExtensionPackVSIX: true }, ]; ['workbench.action.files.openFolder']: []; ['workbench.action.openWorkspace']: []; From 87d930b45ab2dbc257b7cad5eca73c4b14dbc356 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 3 Jun 2021 09:45:03 -0700 Subject: [PATCH 3/4] Revert "More strongly enforce call signature" This reverts commit 8144eb4fa0b58604c0ffd3447c27b76e5d23a512. --- src/client/common/application/commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/common/application/commands.ts b/src/client/common/application/commands.ts index 0f51125de502..b5b46b84c670 100644 --- a/src/client/common/application/commands.ts +++ b/src/client/common/application/commands.ts @@ -64,7 +64,7 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu ['workbench.action.quickOpen']: [string]; ['workbench.extensions.installExtension']: [ Uri | 'ms-python.python', - { installOnlyNewlyAddedFromExtensionPackVSIX: true }, + { installOnlyNewlyAddedFromExtensionPackVSIX?: boolean } | undefined, ]; ['workbench.action.files.openFolder']: []; ['workbench.action.openWorkspace']: []; From 71ee9683ea36f481ae2a785d3e6776cfec515692 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 3 Jun 2021 10:49:08 -0700 Subject: [PATCH 4/4] Revert changes to commands --- src/client/common/application/commands.ts | 1 - src/client/common/application/types.ts | 6 +----- .../application/commands/reportIssueCommand.unit.test.ts | 7 ++++--- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/client/common/application/commands.ts b/src/client/common/application/commands.ts index b5b46b84c670..14585f36dfb4 100644 --- a/src/client/common/application/commands.ts +++ b/src/client/common/application/commands.ts @@ -68,7 +68,6 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu ]; ['workbench.action.files.openFolder']: []; ['workbench.action.openWorkspace']: []; - ['workbench.action.openIssueReporter']: [{ extensionId: string; issueBody: string }]; ['setContext']: [string, boolean] | ['python.vscode.channel', Channel]; ['python.reloadVSCode']: [string]; ['revealLine']: [{ lineNumber: number; at: 'top' | 'center' | 'bottom' }]; diff --git a/src/client/common/application/types.ts b/src/client/common/application/types.ts index ea4263479824..01df5613bd90 100644 --- a/src/client/common/application/types.ts +++ b/src/client/common/application/types.ts @@ -61,7 +61,6 @@ import { import type { NotebookConcatTextDocument, NotebookDocument } from 'vscode-proposed'; import { IAsyncDisposable, Resource } from '../types'; -import { ICommandNameArgumentTypeMapping } from './commands'; export enum CommandSource { auto = 'auto', @@ -474,10 +473,7 @@ export interface ICommandManager { * @return A thenable that resolves to the returned value of the given command. `undefined` when * the command handler function doesn't return anything. */ - executeCommand( - command: E, - ...rest: U - ): Thenable; + executeCommand(command: string, ...rest: any[]): Thenable; /** * Retrieve the list of all available commands. Commands starting an underscore are diff --git a/src/test/common/application/commands/reportIssueCommand.unit.test.ts b/src/test/common/application/commands/reportIssueCommand.unit.test.ts index a4f2761d7e87..f58c1aaa766d 100644 --- a/src/test/common/application/commands/reportIssueCommand.unit.test.ts +++ b/src/test/common/application/commands/reportIssueCommand.unit.test.ts @@ -80,9 +80,10 @@ suite('Report Issue Command', () => { ); const expectedIssueBody = fs.readFileSync(templatePath, 'utf8'); - const args = capture<'workbench.action.openIssueReporter', { extensionId: string; issueBody: string }>( - cmdManager.executeCommand, - ).last(); + const args: [string, { extensionId: string; issueBody: string }] = capture< + string, + { extensionId: string; issueBody: string } + >(cmdManager.executeCommand).last(); verify(cmdManager.registerCommand('python.reportIssue', anything(), anything())).once(); verify(cmdManager.executeCommand('workbench.action.openIssueReporter', anything())).once();