Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 4 additions & 11 deletions src/client/common/application/commandManager.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { inject, injectable } from 'inversify';
import { injectable } from 'inversify';
import { commands, Disposable, TextEditor, TextEditorEdit } from 'vscode';
import { ICommandNameArgumentTypeMapping } from './commands';
import { ICommandManager, IJupyterExtensionDependencyManager } from './types';
import { ICommandManager } from './types';

@injectable()
export class CommandManager implements ICommandManager {
constructor(
@inject(IJupyterExtensionDependencyManager)
private jupyterExtensionDependencyManager: IJupyterExtensionDependencyManager,
) {}
constructor() {}

/**
* Registers a command that can be invoked via a keyboard shortcut,
Expand Down Expand Up @@ -73,11 +70,7 @@ export class CommandManager implements ICommandManager {
E extends keyof ICommandNameArgumentTypeMapping,
U extends ICommandNameArgumentTypeMapping[E]
>(command: E, ...rest: U): Thenable<T | undefined> {
if (command.includes('jupyter') && !this.jupyterExtensionDependencyManager.isJupyterExtensionInstalled) {
return this.jupyterExtensionDependencyManager.installJupyterExtension(this);
Comment thread
karrtikr marked this conversation as resolved.
} else {
return commands.executeCommand<T>(command, ...rest);
}
return commands.executeCommand<T>(command, ...rest);
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/client/common/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ export interface ICommandManager {
export const IJupyterExtensionDependencyManager = Symbol('IJupyterExtensionDependencyManager');
export interface IJupyterExtensionDependencyManager {
readonly isJupyterExtensionInstalled: boolean;
installJupyterExtension(commandManager: ICommandManager): Promise<undefined>;
}

export const IDocumentManager = Symbol('IDocumentManager');
Expand Down
5 changes: 0 additions & 5 deletions src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ export namespace Pylance {
}

export namespace Jupyter {
export const jupyterExtensionRequired = localize(
'Jupyter.extensionRequired',
'The Jupyter extension is required to perform that task. Click Yes to open the Jupyter extension installation page.',
);

export const jupyterExtensionNotInstalled = localize(
'Jupyter.extensionNotInstalled',
"This feature is available in the Jupyter extension, which isn't currently installed.",
Expand Down
18 changes: 2 additions & 16 deletions src/client/jupyter/jupyterExtensionDependencyManager.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
import { inject, injectable } from 'inversify';
import { IApplicationShell, ICommandManager, IJupyterExtensionDependencyManager } from '../common/application/types';
import { IJupyterExtensionDependencyManager } from '../common/application/types';
import { JUPYTER_EXTENSION_ID } from '../common/constants';
import { IExtensions } from '../common/types';
import { Common, Jupyter } from '../common/utils/localize';

@injectable()
export class JupyterExtensionDependencyManager implements IJupyterExtensionDependencyManager {
constructor(
@inject(IExtensions) private extensions: IExtensions,
@inject(IApplicationShell) private appShell: IApplicationShell,
) {}
constructor(@inject(IExtensions) private extensions: IExtensions) {}

public get isJupyterExtensionInstalled(): boolean {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isJupyterExtensionInstalled still lives here instead of being moved to JupyterNotInstalledNotificationHelper because the latter has one single purpose and it's the notification, while a public-facing way of checking whether the Jupyter extension is installed is a separate responsibility.

return this.extensions.getExtension(JUPYTER_EXTENSION_ID) !== undefined;
}

public async installJupyterExtension(commandManager: ICommandManager): Promise<undefined> {
const yes = Common.bannerLabelYes();
const no = Common.bannerLabelNo();
const answer = await this.appShell.showErrorMessage(Jupyter.jupyterExtensionRequired(), yes, no);
if (answer === yes) {
commandManager.executeCommand('extension.open', JUPYTER_EXTENSION_ID);
}
return undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class JupyterNotInstalledNotificationHelper implements IJupyterNotInstall
return !isInstalled;
}

public async jupyterNotInstalledPrompt(entrypoint: JupyterNotInstalledOrigin): Promise<void> {
public async showJupyterNotInstalledPrompt(entrypoint: JupyterNotInstalledOrigin): Promise<void> {
sendTelemetryEvent(EventName.JUPYTER_NOT_INSTALLED_NOTIFICATION_DISPLAYED, undefined, { entrypoint });

const prompts = [Common.doNotShowAgain()];
Expand Down
2 changes: 1 addition & 1 deletion src/client/jupyter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ export enum JupyterNotInstalledOrigin {
export const IJupyterNotInstalledNotificationHelper = Symbol('IJupyterNotInstalledNotificationHelper');
export interface IJupyterNotInstalledNotificationHelper {
shouldShowJupypterExtensionNotInstalledPrompt(): boolean;
jupyterNotInstalledPrompt(entrypoint: JupyterNotInstalledOrigin): Promise<void>;
showJupyterNotInstalledPrompt(entrypoint: JupyterNotInstalledOrigin): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ suite('Jupyter not installed notification helper', () => {
({ createGlobalPersistentState: createGlobalPersistentStateStub } as unknown) as IPersistentStateFactory,
{} as IJupyterExtensionDependencyManager,
);
await notificationHelper.jupyterNotInstalledPrompt(JupyterNotInstalledOrigin.StartPageCreateBlankNotebook);
await notificationHelper.showJupyterNotInstalledPrompt(JupyterNotInstalledOrigin.StartPageCreateBlankNotebook);

sinon.assert.calledOnce(createGlobalPersistentStateStub);
sinon.assert.calledOnce(showInformationMessageStub);
Expand Down Expand Up @@ -142,7 +142,7 @@ suite('Jupyter not installed notification helper', () => {
({ createGlobalPersistentState: createGlobalPersistentStateStub } as unknown) as IPersistentStateFactory,
{} as IJupyterExtensionDependencyManager,
);
await notificationHelper.jupyterNotInstalledPrompt(JupyterNotInstalledOrigin.StartPageCreateBlankNotebook);
await notificationHelper.showJupyterNotInstalledPrompt(JupyterNotInstalledOrigin.StartPageCreateBlankNotebook);

const result = notificationHelper.shouldShowJupypterExtensionNotInstalledPrompt();

Expand Down