mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-23 19:59:37 +00:00
Allow disabling built-in TS/JS extension in favor of tsgo
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { Command } from './commandManager';
|
||||
|
||||
/**
|
||||
* Command that enables TypeScript Go by modifying the configuration setting
|
||||
* and prompting the user to reload VS Code.
|
||||
*/
|
||||
export class EnableTsgoCommand implements Command {
|
||||
public readonly id = 'typescript.enableTsgo';
|
||||
|
||||
public async execute(): Promise<void> {
|
||||
await updateTsgoSetting(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Command that disables TypeScript Go by modifying the configuration setting
|
||||
* and prompting the user to reload VS Code.
|
||||
*/
|
||||
export class DisableTsgoCommand implements Command {
|
||||
public readonly id = 'typescript.disableTsgo';
|
||||
|
||||
public async execute(): Promise<void> {
|
||||
await updateTsgoSetting(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the TypeScript Go setting and prompts for reload.
|
||||
*
|
||||
* @param enable Whether to enable or disable TypeScript Go
|
||||
*/
|
||||
async function updateTsgoSetting(enable: boolean): Promise<void> {
|
||||
const tsgoExtension = vscode.extensions.getExtension('typescript.typescript-lsp');
|
||||
// Error if the TypeScript Go extension is not installed with a button to open the GitHub repo
|
||||
if (!tsgoExtension) {
|
||||
return vscode.window.showErrorMessage(
|
||||
'The TypeScript Go extension is not installed.',
|
||||
{
|
||||
title: 'Open on GitHub',
|
||||
isCloseAffordance: true,
|
||||
}
|
||||
).then(async (selection) => {
|
||||
if (selection) {
|
||||
await vscode.env.openExternal(vscode.Uri.parse('https://github.com/microsoft/typescript-go'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const tsConfig = vscode.workspace.getConfiguration('typescript');
|
||||
const currentValue = tsConfig.get<boolean>('useTsgo', false);
|
||||
if (currentValue === enable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine the target scope for the configuration update
|
||||
let target = vscode.ConfigurationTarget.Global;
|
||||
const inspect = tsConfig.inspect<boolean>('useTsgo');
|
||||
if (inspect?.workspaceValue !== undefined) {
|
||||
target = vscode.ConfigurationTarget.Workspace;
|
||||
} else if (inspect?.workspaceFolderValue !== undefined) {
|
||||
target = vscode.ConfigurationTarget.WorkspaceFolder;
|
||||
} else {
|
||||
// If setting is not defined yet, use the same scope as typescript-go.executablePath
|
||||
const tsgoConfig = vscode.workspace.getConfiguration('typescript-go');
|
||||
const tsgoInspect = tsgoConfig.inspect<string>('executablePath');
|
||||
|
||||
if (tsgoInspect?.workspaceValue !== undefined) {
|
||||
target = vscode.ConfigurationTarget.Workspace;
|
||||
} else if (tsgoInspect?.workspaceFolderValue !== undefined) {
|
||||
target = vscode.ConfigurationTarget.WorkspaceFolder;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the setting, restart the extension host, and enable the TypeScript Go extension
|
||||
await tsConfig.update('useTsgo', enable, target);
|
||||
await vscode.commands.executeCommand('workbench.action.restartExtensionHost');
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { ActiveJsTsEditorTracker } from '../ui/activeJsTsEditorTracker';
|
||||
import { Lazy } from '../utils/lazy';
|
||||
import { CommandManager } from './commandManager';
|
||||
import { ConfigurePluginCommand } from './configurePlugin';
|
||||
import { EnableTsgoCommand, DisableTsgoCommand } from './disableExtension';
|
||||
import { JavaScriptGoToProjectConfigCommand, TypeScriptGoToProjectConfigCommand } from './goToProjectConfiguration';
|
||||
import { LearnMoreAboutRefactoringsCommand } from './learnMoreAboutRefactorings';
|
||||
import { OpenJsDocLinkCommand } from './openJsDocLink';
|
||||
@@ -35,4 +36,6 @@ export function registerBaseCommands(
|
||||
commandManager.register(new LearnMoreAboutRefactoringsCommand());
|
||||
commandManager.register(new TSServerRequestCommand(lazyClientHost));
|
||||
commandManager.register(new OpenJsDocLinkCommand());
|
||||
commandManager.register(new EnableTsgoCommand());
|
||||
commandManager.register(new DisableTsgoCommand());
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import * as fs from 'fs';
|
||||
import * as vscode from 'vscode';
|
||||
import { Api, getExtensionApi } from './api';
|
||||
import { CommandManager } from './commands/commandManager';
|
||||
import { DisableTsgoCommand } from './commands/disableExtension';
|
||||
import { registerBaseCommands } from './commands/index';
|
||||
import { ElectronServiceConfigurationProvider } from './configuration/configuration.electron';
|
||||
import { ExperimentationTelemetryReporter, IExperimentationTelemetryReporter } from './experimentTelemetryReporter';
|
||||
@@ -28,12 +29,26 @@ import * as temp from './utils/temp.electron';
|
||||
export function activate(
|
||||
context: vscode.ExtensionContext
|
||||
): Api {
|
||||
const pluginManager = new PluginManager();
|
||||
context.subscriptions.push(pluginManager);
|
||||
|
||||
const commandManager = new CommandManager();
|
||||
context.subscriptions.push(commandManager);
|
||||
|
||||
// Disable extension if using the experimental TypeScript Go extension
|
||||
const config = vscode.workspace.getConfiguration('typescript');
|
||||
const useTsgo = config.get<boolean>('unstable.useTsgo', false);
|
||||
|
||||
if (useTsgo) {
|
||||
commandManager.register(new DisableTsgoCommand());
|
||||
// Return a no-op API when disabled
|
||||
return {
|
||||
getAPI() {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const pluginManager = new PluginManager();
|
||||
context.subscriptions.push(pluginManager);
|
||||
|
||||
const onCompletionAccepted = new vscode.EventEmitter<vscode.CompletionItem>();
|
||||
context.subscriptions.push(onCompletionAccepted);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user