Skip to content

Commit 29eaf4a

Browse files
committed
Remove additional VS Code restart ext host calls
For microsoft/vscode#266087 Missed a few of these in the first pass
1 parent 6277711 commit 29eaf4a

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

_extension/src/commands.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22
import { Client } from "./client";
3+
import { restartExtHostOnChangeIfNeeded } from "./util";
34

45
export function registerEnablementCommands(context: vscode.ExtensionContext): void {
56
context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.enable", () => {
@@ -46,11 +47,11 @@ async function updateUseTsgoSetting(enable: boolean): Promise<void> {
4647
if (useTsgo) {
4748
target = useTsgo.workspaceFolderValue !== undefined ? vscode.ConfigurationTarget.WorkspaceFolder :
4849
useTsgo.workspaceValue !== undefined ? vscode.ConfigurationTarget.Workspace :
49-
useTsgo.globalValue !== undefined ? vscode.ConfigurationTarget.Global : undefined;
50+
useTsgo.globalValue !== undefined ? vscode.ConfigurationTarget.Global : undefined;
5051
}
5152
// Update the setting and restart the extension host (needed to change the state of the built-in TS extension)
5253
await tsConfig.update("experimental.useTsgo", enable, target);
53-
await vscode.commands.executeCommand("workbench.action.restartExtensionHost");
54+
await restartExtHostOnChangeIfNeeded();
5455
}
5556

5657
/**

_extension/src/extension.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "./commands";
88
import { setupStatusBar } from "./statusBar";
99
import { setupVersionStatusItem } from "./versionStatusItem";
10+
import { needsExtHostRestartOnChange } from "./util";
1011

1112
export async function activate(context: vscode.ExtensionContext) {
1213
await vscode.commands.executeCommand("setContext", "typescript.native-preview.serverRunning", false);
@@ -15,14 +16,11 @@ export async function activate(context: vscode.ExtensionContext) {
1516
const traceOutput = vscode.window.createOutputChannel("typescript-native-preview (LSP)");
1617
context.subscriptions.push(output, traceOutput);
1718

18-
const majorVersion = parseInt(vscode.version.split(".")[0]);
19-
const minorVersion = parseInt(vscode.version.split(".")[1]);
20-
const needsExtHostRestartOnChange = majorVersion <= 1 && minorVersion < 105;
2119
let disposeLanguageFeatures: vscode.Disposable | undefined;
2220

2321
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(async event => {
2422
if (event.affectsConfiguration("typescript.experimental.useTsgo")) {
25-
if (needsExtHostRestartOnChange) {
23+
if (needsExtHostRestartOnChange()) {
2624
// Delay because the command to change the config setting will restart
2725
// the extension host, so no need to show a message
2826
setTimeout(async () => {

_extension/src/util.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,15 @@ export function getLanguageForUri(uri: vscode.Uri): string | undefined {
8989
return undefined;
9090
}
9191
}
92+
93+
export function needsExtHostRestartOnChange() {
94+
const majorVersion = parseInt(vscode.version.split(".")[0]);
95+
const minorVersion = parseInt(vscode.version.split(".")[1]);
96+
return majorVersion <= 1 && minorVersion < 105;
97+
}
98+
99+
export async function restartExtHostOnChangeIfNeeded(): Promise<void> {
100+
if (needsExtHostRestartOnChange()) {
101+
await vscode.commands.executeCommand("workbench.action.restartExtensionHost");
102+
}
103+
}

0 commit comments

Comments
 (0)