Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask for prerelease switch #8657

Merged
merged 2 commits into from
Jan 14, 2022
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
6 changes: 5 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -555,5 +555,9 @@
"DataScience.importingIpynb": "Importing notebook file.",
"DataScience.exportingToFormat": "Exporting to {0}.",
"DataScience.matplotlibWidgetInsteadOfOther": "'%matplotlib widget' or '%matplotlib inline' works best in VS code notebooks.",
"DataScience.matplotlibWidgetCodeActionTitle": "More information"
"DataScience.matplotlibWidgetCodeActionTitle": "More information",
"DataScience.usingNonPrereleaseYes": "Yes",
"DataScience.usingNonPrereleaseNo": "No",
"DataScience.usingNonPrereleaseNoAndDontAskAgain": "Don't ask again",
"DataScience.usingNonPrerelease": "The 'prerelease' version of the Jupyter extension is recommended when running on VS code insiders. Would you like to switch?"
}
12 changes: 12 additions & 0 deletions src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,18 @@ export namespace DataScience {
'DataScience.activatingEnvironment',
"Activating Python Environment '{0}'"
);

export const usingNonPrereleaseYes = localize('DataScience.usingNonPrereleaseYes', 'Yes');
export const usingNonPrereleaseNo = localize('DataScience.usingNonPrereleaseNo', 'No');
export const usingNonPrereleaseNoAndDontAskAgain = localize(
'DataScience.usingNonPrereleaseNoAndDontAskAgain',
`Don't Ask Again`
);

export const usingNonPrerelease = localize(
'DataScience.usingNonPrerelease',
`The 'prerelease' version of the Jupyter extension is recommended when running on VS code insiders. Would you like to switch?`
);
}

// Skip using vscode-nls and instead just compute our strings based on key values. Key values
Expand Down
49 changes: 49 additions & 0 deletions src/client/datascience/prereleaseChecker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import '../common/extensions';
import { inject, injectable, named } from 'inversify';
import { IExtensionSingleActivationService } from '../activation/types';
import { IApplicationEnvironment, IApplicationShell } from '../common/application/types';
import { GLOBAL_MEMENTO, IMemento } from '../common/types';
import * as localize from '../common/utils/localize';
import { JVSC_EXTENSION_ID } from '../common/constants';
import * as vscode from 'vscode';

const PRERELEASE_DONT_ASK_FLAG = 'dontAskForPrereleaseUpgrade';

@injectable()
export class PreReleaseChecker implements IExtensionSingleActivationService {
constructor(
@inject(IApplicationEnvironment) private readonly appEnv: IApplicationEnvironment,
@inject(IApplicationShell) private readonly appShell: IApplicationShell,
@inject(IMemento) @named(GLOBAL_MEMENTO) private globalState: vscode.Memento
) {}
public async activate(): Promise<void> {
// Ask user if the version is not prerelease
const isPreRelease = this.appEnv.packageJson.__metadata?.preRelease == true;
const dontAsk = this.globalState.get(PRERELEASE_DONT_ASK_FLAG, false);
if (!isPreRelease && this.appEnv.channel === 'insiders' && !dontAsk) {
const yes = localize.DataScience.usingNonPrereleaseYes();
const no = localize.DataScience.usingNonPrereleaseNo();
const dontAskAgain = localize.DataScience.usingNonPrereleaseNoAndDontAskAgain();
void this.appShell
.showWarningMessage(localize.DataScience.usingNonPrerelease(), yes, no, dontAskAgain)
.then((answer) => {
if (answer === yes) {
return vscode.commands.executeCommand(
'workbench.extensions.installExtension',
JVSC_EXTENSION_ID,
{
installPreReleaseVersion: true
}
);
} else if (answer == dontAskAgain) {
return this.globalState.update(PRERELEASE_DONT_ASK_FLAG, true);
}
});
}
}
}
2 changes: 2 additions & 0 deletions src/client/datascience/serviceRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ import { CellHashProviderFactory } from './editor-integration/cellHashProviderFa
import { ExportToPythonPlain } from './export/exportToPythonPlain';
import { ErrorRendererCommunicationHandler } from './errors/errorRendererComms';
import { KernelProgressReporter } from './progress/kernelProgressReporter';
import { PreReleaseChecker } from './prereleaseChecker';

// README: Did you make sure "dataScienceIocContainer.ts" has also been updated appropriately?

Expand Down Expand Up @@ -295,6 +296,7 @@ export function registerTypes(serviceManager: IServiceManager, inNotebookApiExpe
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, ErrorRendererCommunicationHandler);
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, KernelProgressReporter);
serviceManager.addSingleton<IDebuggingManager>(IDebuggingManager, DebuggingManager, undefined, [IExtensionSingleActivationService]);
serviceManager.addSingleton<IExtensionSingleActivationService>(IExtensionSingleActivationService, PreReleaseChecker);

registerNotebookTypes(serviceManager);
registerContextTypes(serviceManager);
Expand Down