From 29eaf4ab80931e1a4e78240b081a1a8c946e4f1a Mon Sep 17 00:00:00 2001 From: Matt Bierner <12821956+mjbvz@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:15:34 -0700 Subject: [PATCH 1/2] Remove additional VS Code restart ext host calls For https://github.com/microsoft/vscode/issues/266087 Missed a few of these in the first pass --- _extension/src/commands.ts | 5 +++-- _extension/src/extension.ts | 6 ++---- _extension/src/util.ts | 12 ++++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/_extension/src/commands.ts b/_extension/src/commands.ts index ef44a12b76..04a0f68424 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", () => { @@ -46,11 +47,11 @@ async function updateUseTsgoSetting(enable: boolean): Promise { if (useTsgo) { target = useTsgo.workspaceFolderValue !== undefined ? vscode.ConfigurationTarget.WorkspaceFolder : useTsgo.workspaceValue !== undefined ? vscode.ConfigurationTarget.Workspace : - useTsgo.globalValue !== undefined ? vscode.ConfigurationTarget.Global : undefined; + useTsgo.globalValue !== undefined ? vscode.ConfigurationTarget.Global : undefined; } // 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..20644813d8 100644 --- a/_extension/src/extension.ts +++ b/_extension/src/extension.ts @@ -7,6 +7,7 @@ import { } from "./commands"; import { setupStatusBar } from "./statusBar"; import { setupVersionStatusItem } from "./versionStatusItem"; +import { needsExtHostRestartOnChange } from "./util"; export async function activate(context: vscode.ExtensionContext) { await vscode.commands.executeCommand("setContext", "typescript.native-preview.serverRunning", false); @@ -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..d34999b52c 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"); + } +} \ No newline at end of file From 449184fd853e8d8d79b81a646d9f9abab6f7c547 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 1 Oct 2025 16:49:05 -0700 Subject: [PATCH 2/2] Format --- _extension/src/commands.ts | 2 +- _extension/src/extension.ts | 2 +- _extension/src/util.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/_extension/src/commands.ts b/_extension/src/commands.ts index 04a0f68424..d60192ff8e 100644 --- a/_extension/src/commands.ts +++ b/_extension/src/commands.ts @@ -47,7 +47,7 @@ async function updateUseTsgoSetting(enable: boolean): Promise { if (useTsgo) { target = useTsgo.workspaceFolderValue !== undefined ? vscode.ConfigurationTarget.WorkspaceFolder : useTsgo.workspaceValue !== undefined ? vscode.ConfigurationTarget.Workspace : - useTsgo.globalValue !== undefined ? vscode.ConfigurationTarget.Global : undefined; + useTsgo.globalValue !== undefined ? vscode.ConfigurationTarget.Global : undefined; } // 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); diff --git a/_extension/src/extension.ts b/_extension/src/extension.ts index 20644813d8..d1fe6036eb 100644 --- a/_extension/src/extension.ts +++ b/_extension/src/extension.ts @@ -6,8 +6,8 @@ import { registerLanguageCommands, } from "./commands"; import { setupStatusBar } from "./statusBar"; -import { setupVersionStatusItem } from "./versionStatusItem"; import { needsExtHostRestartOnChange } from "./util"; +import { setupVersionStatusItem } from "./versionStatusItem"; export async function activate(context: vscode.ExtensionContext) { await vscode.commands.executeCommand("setContext", "typescript.native-preview.serverRunning", false); diff --git a/_extension/src/util.ts b/_extension/src/util.ts index d34999b52c..e5397d9b1c 100644 --- a/_extension/src/util.ts +++ b/_extension/src/util.ts @@ -100,4 +100,4 @@ export async function restartExtHostOnChangeIfNeeded(): Promise { if (needsExtHostRestartOnChange()) { await vscode.commands.executeCommand("workbench.action.restartExtensionHost"); } -} \ No newline at end of file +}