-
Notifications
You must be signed in to change notification settings - Fork 1.3k
wip new jedi tryPylance banner #14697
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,6 @@ | |
| "**/.vscode-test/insider/**": true, | ||
| "**/.vscode-test/stable/**": true, | ||
| "**/out/**": true | ||
| } | ||
| }, | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { inject, injectable } from 'inversify'; | ||
| import { LanguageServerType } from '../activation/types'; | ||
| import { IApplicationEnvironment, IApplicationShell } from '../common/application/types'; | ||
| import { PYLANCE_EXTENSION_ID } from '../common/constants'; | ||
| import { TryPylance } from '../common/experiments/groups'; | ||
| import '../common/extensions'; | ||
| import { | ||
| IConfigurationService, | ||
| IExperimentService, | ||
| IExtensions, | ||
| IPersistentStateFactory, | ||
| // tslint:disable-next-line: prettier | ||
| IPythonExtensionBanner, | ||
| } from '../common/types'; | ||
| import { Common, Pylance } from '../common/utils/localize'; | ||
| import { sendTelemetryEvent } from '../telemetry'; | ||
| import { EventName } from '../telemetry/constants'; | ||
|
|
||
| export function getPylanceExtensionUri(appEnv: IApplicationEnvironment): string { | ||
| return `${appEnv.uriScheme}:extension/${PYLANCE_EXTENSION_ID}`; | ||
| } | ||
|
|
||
| // persistent state names, exported to make use of in testing | ||
| export enum ProposeLSStateKeys { | ||
| ShowBannerJedi = 'TryPylanceBannerJedi' | ||
| } | ||
|
|
||
| /* | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is basically the same as the previous tryPylance banner ProposePylanceBanner.ts just the data and some of the logic have changed |
||
| This class represents a popup that propose that the user try out a new | ||
| feature of the extension, and optionally enable that new feature if they | ||
| choose to do so. It is meant to be shown only to a subset of our users, | ||
| and will show as soon as it is instructed to do so, if a random sample | ||
| function enables the popup for this user. | ||
| */ | ||
| @injectable() | ||
| export class ProposePylanceBannerJedi implements IPythonExtensionBanner { | ||
| private disabledInCurrentSession = false; | ||
|
|
||
| constructor( | ||
| @inject(IApplicationShell) private appShell: IApplicationShell, | ||
| @inject(IApplicationEnvironment) private appEnv: IApplicationEnvironment, | ||
| @inject(IPersistentStateFactory) private persistentState: IPersistentStateFactory, | ||
| @inject(IConfigurationService) private configuration: IConfigurationService, | ||
| @inject(IExperimentService) private experiments: IExperimentService, | ||
| // eslint-disable-next-line comma-dangle | ||
| @inject(IExtensions) readonly extensions: IExtensions | ||
| ) {} | ||
|
|
||
| public get enabled(): boolean { | ||
| const lsType = this.configuration.getSettings().languageServer ?? LanguageServerType.Jedi; | ||
| if (lsType !== LanguageServerType.Jedi) { | ||
| return false; | ||
| } | ||
| return this.persistentState.createGlobalPersistentState<boolean>(ProposeLSStateKeys.ShowBannerJedi, true).value; | ||
| } | ||
|
|
||
| public async showBanner(): Promise<void> { | ||
| if (!this.enabled) { | ||
| return; | ||
| } | ||
|
|
||
| const show = await this.shouldShowBanner(); | ||
| if (!show) { | ||
| return; | ||
| } | ||
|
|
||
| let experimentName = ''; | ||
| let promptContent: string | undefined; | ||
| if (await this.experiments.inExperiment(TryPylance.jediPrompt1)) { | ||
| promptContent = await this.experiments.getExperimentValue<string>(TryPylance.jediPrompt1); | ||
| experimentName = TryPylance.jediPrompt1; | ||
| } else if (await this.experiments.inExperiment(TryPylance.jediPrompt2)) { | ||
| promptContent = await this.experiments.getExperimentValue<string>(TryPylance.jediPrompt2); | ||
| experimentName = TryPylance.jediPrompt2; | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new way to check if we're in an experiment and also get the banner string |
||
|
|
||
| if (promptContent === undefined) { | ||
| return; | ||
| } | ||
|
|
||
| const response = await this.appShell.showInformationMessage( | ||
| promptContent, | ||
| Pylance.tryItNow(), | ||
| Common.bannerLabelNo(), | ||
| Pylance.remindMeLater() | ||
| ); | ||
|
|
||
| let userAction: string; | ||
| if (response === Pylance.tryItNow()) { | ||
| this.appShell.openUrl(getPylanceExtensionUri(this.appEnv)); | ||
| userAction = 'yes'; | ||
| await this.disable(); | ||
| } else if (response === Common.bannerLabelNo()) { | ||
| await this.disable(); | ||
| userAction = 'no'; | ||
| } else { | ||
| this.disabledInCurrentSession = true; | ||
| userAction = 'later'; | ||
| } | ||
| sendTelemetryEvent(EventName.LANGUAGE_SERVER_TRY_PYLANCE, undefined, { userAction, experimentName }); | ||
| } | ||
|
|
||
| public async shouldShowBanner(): Promise<boolean> { | ||
| // Do not prompt if Pylance is already installed. | ||
| if (this.extensions.getExtension(PYLANCE_EXTENSION_ID)) { | ||
| return false; | ||
| } | ||
| return this.enabled && !this.disabledInCurrentSession; | ||
| } | ||
|
|
||
| public async disable(): Promise<void> { | ||
| await this.persistentState | ||
| .createGlobalPersistentState<boolean>(ProposeLSStateKeys.ShowBannerJedi, false) | ||
| .updateValue(false); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is named?