Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/client/common/application/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: true },
];
['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' }];
Expand Down
6 changes: 5 additions & 1 deletion src/client/common/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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<T>(command: string, ...rest: any[]): Thenable<T | undefined>;
executeCommand<T, E extends keyof ICommandNameArgumentTypeMapping, U extends ICommandNameArgumentTypeMapping[E]>(
command: E,
...rest: U
): Thenable<T | undefined>;

/**
* Retrieve the list of all available commands. Commands starting an underscore are
Expand Down
8 changes: 6 additions & 2 deletions src/client/common/installer/extensionBuildInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
21 changes: 13 additions & 8 deletions src/test/common/installer/extensionBuildInstaller.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

Expand Down Expand Up @@ -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();
Expand All @@ -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();
});
});