Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion _extension/src/commands.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down Expand Up @@ -50,7 +51,7 @@ async function updateUseTsgoSetting(enable: boolean): Promise<void> {
}
// 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();
}

/**
Expand Down
6 changes: 2 additions & 4 deletions _extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 () => {
Expand Down
12 changes: 12 additions & 0 deletions _extension/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
if (needsExtHostRestartOnChange()) {
await vscode.commands.executeCommand("workbench.action.restartExtensionHost");
}
}