forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Direct users to the Jupyter extension when using Run in Interactive w…
…indow (microsoft#21072) Closes microsoft#20576
- Loading branch information
1 parent
a1f5041
commit 3217420
Showing
13 changed files
with
163 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { inject, injectable } from 'inversify'; | ||
import { IExtensionSingleActivationService } from '../activation/types'; | ||
import { IApplicationShell, ICommandManager } from '../common/application/types'; | ||
import { Common, Interpreters } from '../common/utils/localize'; | ||
import { Commands, JUPYTER_EXTENSION_ID } from '../common/constants'; | ||
import { IDisposable, IDisposableRegistry } from '../common/types'; | ||
import { sendTelemetryEvent } from '../telemetry'; | ||
import { EventName } from '../telemetry/constants'; | ||
|
||
@injectable() | ||
export class RequireJupyterPrompt implements IExtensionSingleActivationService { | ||
public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: true }; | ||
|
||
constructor( | ||
@inject(IApplicationShell) private readonly appShell: IApplicationShell, | ||
@inject(ICommandManager) private readonly commandManager: ICommandManager, | ||
@inject(IDisposableRegistry) private readonly disposables: IDisposable[], | ||
) {} | ||
|
||
public async activate(): Promise<void> { | ||
this.disposables.push(this.commandManager.registerCommand(Commands.InstallJupyter, () => this._showPrompt())); | ||
} | ||
|
||
public async _showPrompt(): Promise<void> { | ||
const prompts = [Common.bannerLabelYes, Common.bannerLabelNo]; | ||
const telemetrySelections: ['Yes', 'No'] = ['Yes', 'No']; | ||
const selection = await this.appShell.showInformationMessage(Interpreters.requireJupyter, ...prompts); | ||
sendTelemetryEvent(EventName.REQUIRE_JUPYTER_PROMPT, undefined, { | ||
selection: selection ? telemetrySelections[prompts.indexOf(selection)] : undefined, | ||
}); | ||
if (!selection) { | ||
return; | ||
} | ||
if (selection === prompts[0]) { | ||
await this.commandManager.executeCommand( | ||
'workbench.extensions.installExtension', | ||
JUPYTER_EXTENSION_ID, | ||
undefined, | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { mock, instance, verify, anything, when } from 'ts-mockito'; | ||
import { IApplicationShell, ICommandManager } from '../../client/common/application/types'; | ||
import { Commands, JUPYTER_EXTENSION_ID } from '../../client/common/constants'; | ||
import { IDisposableRegistry } from '../../client/common/types'; | ||
import { Common, Interpreters } from '../../client/common/utils/localize'; | ||
import { RequireJupyterPrompt } from '../../client/jupyter/requireJupyterPrompt'; | ||
|
||
suite('RequireJupyterPrompt Unit Tests', () => { | ||
let requireJupyterPrompt: RequireJupyterPrompt; | ||
let appShell: IApplicationShell; | ||
let commandManager: ICommandManager; | ||
let disposables: IDisposableRegistry; | ||
|
||
setup(() => { | ||
appShell = mock<IApplicationShell>(); | ||
commandManager = mock<ICommandManager>(); | ||
disposables = mock<IDisposableRegistry>(); | ||
|
||
requireJupyterPrompt = new RequireJupyterPrompt( | ||
instance(appShell), | ||
instance(commandManager), | ||
instance(disposables), | ||
); | ||
}); | ||
|
||
test('Activation registers command', async () => { | ||
await requireJupyterPrompt.activate(); | ||
|
||
verify(commandManager.registerCommand(Commands.InstallJupyter, anything())).once(); | ||
}); | ||
|
||
test('Show prompt with Yes selection installs Jupyter extension', async () => { | ||
when( | ||
appShell.showInformationMessage(Interpreters.requireJupyter, Common.bannerLabelYes, Common.bannerLabelNo), | ||
).thenReturn(Promise.resolve(Common.bannerLabelYes)); | ||
|
||
await requireJupyterPrompt.activate(); | ||
await requireJupyterPrompt._showPrompt(); | ||
|
||
verify( | ||
commandManager.executeCommand('workbench.extensions.installExtension', JUPYTER_EXTENSION_ID, undefined), | ||
).once(); | ||
}); | ||
|
||
test('Show prompt with No selection does not install Jupyter extension', async () => { | ||
when( | ||
appShell.showInformationMessage(Interpreters.requireJupyter, Common.bannerLabelYes, Common.bannerLabelNo), | ||
).thenReturn(Promise.resolve(Common.bannerLabelNo)); | ||
|
||
await requireJupyterPrompt.activate(); | ||
await requireJupyterPrompt._showPrompt(); | ||
|
||
verify( | ||
commandManager.executeCommand('workbench.extensions.installExtension', JUPYTER_EXTENSION_ID, undefined), | ||
).never(); | ||
}); | ||
}); |