Skip to content

Commit 3d33f0e

Browse files
mjbvzandrewbranch
andauthored
Remove additional VS Code restart ext host calls (#1788)
Co-authored-by: Andrew Branch <[email protected]>
1 parent b8983f4 commit 3d33f0e

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

_extension/src/commands.ts

Lines changed: 2 additions & 1 deletion
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", () => {
@@ -50,7 +51,7 @@ async function updateUseTsgoSetting(enable: boolean): Promise<void> {
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
@@ -6,6 +6,7 @@ import {
66
registerLanguageCommands,
77
} from "./commands";
88
import { setupStatusBar } from "./statusBar";
9+
import { needsExtHostRestartOnChange } from "./util";
910
import { setupVersionStatusItem } from "./versionStatusItem";
1011

1112
export async function activate(context: vscode.ExtensionContext) {
@@ -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)