diff --git a/_extension/src/commands.ts b/_extension/src/commands.ts index ef44a12b76..d60192ff8e 100644 --- a/_extension/src/commands.ts +++ b/_extension/src/commands.ts @@ -1,5 +1,6 @@ import * as vscode from "vscode"; import { Client } from "./client"; +import { restartExtHostOnChangeIfNeeded } from "./util"; export function registerEnablementCommands(context: vscode.ExtensionContext): void { context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.enable", () => { @@ -50,7 +51,7 @@ async function updateUseTsgoSetting(enable: boolean): Promise { } // Update the setting and restart the extension host (needed to change the state of the built-in TS extension) await tsConfig.update("experimental.useTsgo", enable, target); - await vscode.commands.executeCommand("workbench.action.restartExtensionHost"); + await restartExtHostOnChangeIfNeeded(); } /** diff --git a/_extension/src/extension.ts b/_extension/src/extension.ts index 7830134623..d1fe6036eb 100644 --- a/_extension/src/extension.ts +++ b/_extension/src/extension.ts @@ -6,6 +6,7 @@ import { registerLanguageCommands, } from "./commands"; import { setupStatusBar } from "./statusBar"; +import { needsExtHostRestartOnChange } from "./util"; import { setupVersionStatusItem } from "./versionStatusItem"; export async function activate(context: vscode.ExtensionContext) { @@ -15,14 +16,11 @@ export async function activate(context: vscode.ExtensionContext) { const traceOutput = vscode.window.createOutputChannel("typescript-native-preview (LSP)"); context.subscriptions.push(output, traceOutput); - const majorVersion = parseInt(vscode.version.split(".")[0]); - const minorVersion = parseInt(vscode.version.split(".")[1]); - const needsExtHostRestartOnChange = majorVersion <= 1 && minorVersion < 105; let disposeLanguageFeatures: vscode.Disposable | undefined; context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(async event => { if (event.affectsConfiguration("typescript.experimental.useTsgo")) { - if (needsExtHostRestartOnChange) { + if (needsExtHostRestartOnChange()) { // Delay because the command to change the config setting will restart // the extension host, so no need to show a message setTimeout(async () => { diff --git a/_extension/src/util.ts b/_extension/src/util.ts index b3be8beaf6..e5397d9b1c 100644 --- a/_extension/src/util.ts +++ b/_extension/src/util.ts @@ -89,3 +89,15 @@ export function getLanguageForUri(uri: vscode.Uri): string | undefined { return undefined; } } + +export function needsExtHostRestartOnChange() { + const majorVersion = parseInt(vscode.version.split(".")[0]); + const minorVersion = parseInt(vscode.version.split(".")[1]); + return majorVersion <= 1 && minorVersion < 105; +} + +export async function restartExtHostOnChangeIfNeeded(): Promise { + if (needsExtHostRestartOnChange()) { + await vscode.commands.executeCommand("workbench.action.restartExtensionHost"); + } +}