-
Notifications
You must be signed in to change notification settings - Fork 39.5k
Add one time prompt to try ts 7.0 if you have ts nightly installed #311977
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,7 @@ import { PluginManager } from './tsServer/plugins'; | |||||||||
| import { ElectronServiceProcessFactory } from './tsServer/serverProcess.electron'; | ||||||||||
| import { DiskTypeScriptVersionProvider } from './tsServer/versionProvider.electron'; | ||||||||||
| import { ActiveJsTsEditorTracker } from './ui/activeJsTsEditorTracker'; | ||||||||||
| import { suggestNativePreview } from './ui/suggestNativePreview'; | ||||||||||
| import { onCaseInsensitiveFileSystem } from './utils/fs.electron'; | ||||||||||
| import { Lazy } from './utils/lazy'; | ||||||||||
| import { getPackageInfo } from './utils/packageInfo'; | ||||||||||
|
|
@@ -48,9 +49,8 @@ export function activate( | |||||||||
| experimentTelemetryReporter = new ExperimentationTelemetryReporter(vscTelemetryReporter); | ||||||||||
| context.subscriptions.push(experimentTelemetryReporter); | ||||||||||
|
|
||||||||||
| // Currently we have no experiments, but creating the service adds the appropriate | ||||||||||
| // shared properties to the ExperimentationTelemetryReporter we just created. | ||||||||||
| new ExperimentationService(experimentTelemetryReporter, id, version, context.globalState); | ||||||||||
| const experimentationService = new ExperimentationService(experimentTelemetryReporter, id, version, context.globalState); | ||||||||||
| suggestNativePreview(context, experimentationService); | ||||||||||
|
||||||||||
| suggestNativePreview(context, experimentationService); | |
| void suggestNativePreview(context, experimentationService).catch(() => { | |
| // Ignore errors from this non-blocking suggestion flow during activation. | |
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import * as vscode from 'vscode'; | ||
| import { tsNativeExtensionId } from '../commands/useTsgo'; | ||
| import { ExperimentationService } from '../experimentationService'; | ||
|
|
||
| const suggestNativePreviewStorageKey = 'typescript.suggestNativePreview.dismissed'; | ||
|
|
||
| export async function suggestNativePreview( | ||
| context: vscode.ExtensionContext, | ||
| experimentationService: ExperimentationService, | ||
| ): Promise<void> { | ||
| if (context.globalState.get<boolean>(suggestNativePreviewStorageKey)) { | ||
| return; | ||
| } | ||
|
|
||
| // Only show when the window is active | ||
| if (!vscode.window.state.active) { | ||
| return; | ||
| } | ||
|
|
||
| // Only show when the nightly extension is installed | ||
| if (!vscode.extensions.getExtension('ms-vscode.vscode-typescript-next')) { | ||
| return; | ||
| } | ||
|
|
||
| // Don't show if the native preview extension is already installed | ||
| if (vscode.extensions.getExtension(tsNativeExtensionId)) { | ||
| // Also don't prompt in the future | ||
| await context.globalState.update(suggestNativePreviewStorageKey, true); | ||
| return; | ||
| } | ||
|
|
||
| const inExperiment = await experimentationService.getTreatmentVariable('suggestNativePreview', false); | ||
| if (!inExperiment) { | ||
| return; | ||
| } | ||
|
|
||
| const install: vscode.MessageItem = { title: vscode.l10n.t("Install") }; | ||
| const learnMore: vscode.MessageItem = { title: vscode.l10n.t("Learn More") }; | ||
| const dismiss: vscode.MessageItem = { title: vscode.l10n.t("Don't Show Again") }; | ||
|
|
||
| const selection = await vscode.window.showInformationMessage( | ||
| vscode.l10n.t("Try TypeScript 7 Native Preview for significantly faster type checking and language features."), | ||
| {}, | ||
| install, | ||
| learnMore, | ||
| dismiss, | ||
| ); | ||
| // Don't show again | ||
| await context.globalState.update(suggestNativePreviewStorageKey, true); | ||
|
|
||
| if (selection === install) { | ||
| await vscode.commands.executeCommand('workbench.extensions.installExtension', tsNativeExtensionId); | ||
| } else if (selection === learnMore) { | ||
| await vscode.env.openExternal(vscode.Uri.parse('https://aka.ms/vscode-try-ts-7-learn-more')); | ||
| } | ||
| } |
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.
await experimentationService.getTreatmentVariableAsync(...) as ExperimentTypes[K]relies onawait/type-assertion precedence and is easy to misread as asserting the Promise rather than the resolved value. Consider restructuring to await first and then apply the type assertion (or otherwise avoid the combinedawait ... as ...form) to keep the typing accurate and the intent clear.