Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions _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 @@ -46,11 +47,11 @@ async function updateUseTsgoSetting(enable: boolean): Promise<void> {
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();
}

/**
Expand Down
6 changes: 2 additions & 4 deletions _extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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");
}
}
Loading