mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
Introduce plugin config provider
Follow up on #61756 Two fixes: - Avoid allowing the `_typescript.configurePlugin` to activate the ts extension non-lazily by instead using a `PluginConfigProvider` - Restrict configurePlugin to TS 3.1.4
This commit is contained in:
@@ -10,6 +10,7 @@ import { Command } from './utils/commandManager';
|
||||
import { Lazy } from './utils/lazy';
|
||||
import { isImplicitProjectConfigFile, openOrCreateConfigFile } from './utils/tsconfig';
|
||||
import { nulToken } from './utils/cancellation';
|
||||
import { PluginConfigProvider } from './typescriptServiceClient';
|
||||
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
@@ -109,11 +110,11 @@ export class ConfigurePluginCommand implements Command {
|
||||
public readonly id = '_typescript.configurePlugin';
|
||||
|
||||
public constructor(
|
||||
private readonly lazyClientHost: Lazy<TypeScriptServiceClientHost>,
|
||||
private readonly pluginConfigProvider: PluginConfigProvider,
|
||||
) { }
|
||||
|
||||
public execute(pluginName: string, configuration: any) {
|
||||
this.lazyClientHost.value.serviceClient.configurePlugin(pluginName, configuration, true /* reconfigureOnRestart */);
|
||||
public execute(pluginId: string, configuration: any) {
|
||||
this.pluginConfigProvider.set(pluginId, configuration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import ManagedFileContextManager from './utils/managedFileContext';
|
||||
import { getContributedTypeScriptServerPlugins, TypeScriptServerPlugin } from './utils/plugins';
|
||||
import * as ProjectStatus from './utils/projectStatus';
|
||||
import { Surveyor } from './utils/surveyor';
|
||||
import { PluginConfigProvider } from './typescriptServiceClient';
|
||||
|
||||
|
||||
export function activate(
|
||||
@@ -25,12 +26,14 @@ export function activate(
|
||||
): void {
|
||||
const plugins = getContributedTypeScriptServerPlugins();
|
||||
|
||||
const pluginConfigProvider = new PluginConfigProvider();
|
||||
|
||||
const commandManager = new CommandManager();
|
||||
context.subscriptions.push(commandManager);
|
||||
|
||||
const lazyClientHost = createLazyClientHost(context, plugins, commandManager);
|
||||
const lazyClientHost = createLazyClientHost(context, plugins, pluginConfigProvider, commandManager);
|
||||
|
||||
registerCommands(commandManager, lazyClientHost);
|
||||
registerCommands(commandManager, lazyClientHost, pluginConfigProvider);
|
||||
context.subscriptions.push(new TypeScriptTaskProviderManager(lazyClientHost.map(x => x.serviceClient)));
|
||||
context.subscriptions.push(new LanguageConfigurationManager());
|
||||
|
||||
@@ -67,6 +70,7 @@ export function activate(
|
||||
function createLazyClientHost(
|
||||
context: vscode.ExtensionContext,
|
||||
plugins: TypeScriptServerPlugin[],
|
||||
pluginConfigProvider: PluginConfigProvider,
|
||||
commandManager: CommandManager
|
||||
): Lazy<TypeScriptServiceClientHost> {
|
||||
return lazy(() => {
|
||||
@@ -76,6 +80,7 @@ function createLazyClientHost(
|
||||
standardLanguageDescriptions,
|
||||
context.workspaceState,
|
||||
plugins,
|
||||
pluginConfigProvider,
|
||||
commandManager,
|
||||
logDirectoryProvider);
|
||||
|
||||
@@ -99,7 +104,8 @@ function createLazyClientHost(
|
||||
|
||||
function registerCommands(
|
||||
commandManager: CommandManager,
|
||||
lazyClientHost: Lazy<TypeScriptServiceClientHost>
|
||||
lazyClientHost: Lazy<TypeScriptServiceClientHost>,
|
||||
pluginConfigProvider: PluginConfigProvider,
|
||||
) {
|
||||
commandManager.register(new commands.ReloadTypeScriptProjectsCommand(lazyClientHost));
|
||||
commandManager.register(new commands.ReloadJavaScriptProjectsCommand(lazyClientHost));
|
||||
@@ -108,7 +114,7 @@ function registerCommands(
|
||||
commandManager.register(new commands.RestartTsServerCommand(lazyClientHost));
|
||||
commandManager.register(new commands.TypeScriptGoToProjectConfigCommand(lazyClientHost));
|
||||
commandManager.register(new commands.JavaScriptGoToProjectConfigCommand(lazyClientHost));
|
||||
commandManager.register(new commands.ConfigurePluginCommand(lazyClientHost));
|
||||
commandManager.register(new commands.ConfigurePluginCommand(pluginConfigProvider));
|
||||
}
|
||||
|
||||
function isSupportedDocument(
|
||||
|
||||
@@ -14,7 +14,7 @@ import FileConfigurationManager from './features/fileConfigurationManager';
|
||||
import LanguageProvider from './languageProvider';
|
||||
import * as Proto from './protocol';
|
||||
import * as PConst from './protocol.const';
|
||||
import TypeScriptServiceClient from './typescriptServiceClient';
|
||||
import TypeScriptServiceClient, { PluginConfigProvider } from './typescriptServiceClient';
|
||||
import API from './utils/api';
|
||||
import { CommandManager } from './utils/commandManager';
|
||||
import { Disposable } from './utils/dispose';
|
||||
@@ -49,6 +49,7 @@ export default class TypeScriptServiceClientHost extends Disposable {
|
||||
descriptions: LanguageDescription[],
|
||||
workspaceState: vscode.Memento,
|
||||
plugins: TypeScriptServerPlugin[],
|
||||
pluginConfigProvider: PluginConfigProvider,
|
||||
private readonly commandManager: CommandManager,
|
||||
logDirectoryProvider: LogDirectoryProvider
|
||||
) {
|
||||
@@ -72,6 +73,7 @@ export default class TypeScriptServiceClientHost extends Disposable {
|
||||
workspaceState,
|
||||
version => this.versionStatus.onDidChangeTypeScriptVersion(version),
|
||||
plugins,
|
||||
pluginConfigProvider,
|
||||
logDirectoryProvider,
|
||||
allModeIds));
|
||||
|
||||
|
||||
@@ -29,6 +29,22 @@ import { TypeScriptVersion, TypeScriptVersionProvider } from './utils/versionPro
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
export class PluginConfigProvider extends Disposable {
|
||||
private readonly _config = new Map<string, any>();
|
||||
|
||||
private readonly _onDidUpdateConfig = this._register(new vscode.EventEmitter<{ pluginId: string, config: any }>());
|
||||
public readonly onDidUpdateConfig = this._onDidUpdateConfig.event;
|
||||
|
||||
public set(pluginId: string, config: any) {
|
||||
this._config.set(pluginId, config);
|
||||
this._onDidUpdateConfig.fire({ pluginId, config });
|
||||
}
|
||||
|
||||
public entries(): IterableIterator<[string, any]> {
|
||||
return this._config.entries();
|
||||
}
|
||||
}
|
||||
|
||||
export interface TsDiagnostics {
|
||||
readonly kind: DiagnosticKind;
|
||||
readonly resource: vscode.Uri;
|
||||
@@ -71,12 +87,11 @@ export default class TypeScriptServiceClient extends Disposable implements IType
|
||||
public readonly bufferSyncSupport: BufferSyncSupport;
|
||||
public readonly diagnosticsManager: DiagnosticsManager;
|
||||
|
||||
private pluginConfigurations: Map<string, any>;
|
||||
|
||||
constructor(
|
||||
private readonly workspaceState: vscode.Memento,
|
||||
private readonly onDidChangeTypeScriptVersion: (version: TypeScriptVersion) => void,
|
||||
public readonly plugins: TypeScriptServerPlugin[],
|
||||
private readonly pluginConfigProvider: PluginConfigProvider,
|
||||
private readonly logDirectoryProvider: LogDirectoryProvider,
|
||||
allModeIds: string[]
|
||||
) {
|
||||
@@ -134,7 +149,6 @@ export default class TypeScriptServiceClient extends Disposable implements IType
|
||||
this.telemetryReporter = this._register(new TelemetryReporter(() => this._tsserverVersion || this._apiVersion.versionString));
|
||||
|
||||
this.typescriptServerSpawner = new TypeScriptServerSpawner(this.versionProvider, this.logDirectoryProvider, this.pluginPathsProvider, this.logger, this.telemetryReporter, this.tracer);
|
||||
this.pluginConfigurations = new Map<string, any>();
|
||||
}
|
||||
|
||||
public get configuration() {
|
||||
@@ -411,9 +425,9 @@ export default class TypeScriptServiceClient extends Disposable implements IType
|
||||
}
|
||||
|
||||
// Reconfigure any plugins
|
||||
this.pluginConfigurations.forEach((config, pluginName) => {
|
||||
for (const [config, pluginName] of this.pluginConfigProvider.entries()) {
|
||||
this.configurePlugin(pluginName, config);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private setCompilerOptionsForInferredProjects(configuration: TypeScriptServiceConfiguration): void {
|
||||
@@ -728,12 +742,9 @@ export default class TypeScriptServiceClient extends Disposable implements IType
|
||||
this._tsserverVersion = undefined;
|
||||
}
|
||||
|
||||
public configurePlugin(pluginName: string, configuration: any, reconfigureOnRestart?: boolean): any {
|
||||
this.executeWithoutWaitingForResponse('configurePlugin', { pluginName, configuration });
|
||||
|
||||
if (reconfigureOnRestart) {
|
||||
// Remember the updated configuration so we can send the command again if TSServer restarts for any reason
|
||||
this.pluginConfigurations.set(pluginName, configuration);
|
||||
private configurePlugin(pluginName: string, configuration: any): any {
|
||||
if (this._apiVersion.gte(API.v314)) {
|
||||
this.executeWithoutWaitingForResponse('configurePlugin', { pluginName, configuration });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ export default class API {
|
||||
public static readonly v292 = API.fromSimpleString('2.9.2');
|
||||
public static readonly v300 = API.fromSimpleString('3.0.0');
|
||||
public static readonly v310 = API.fromSimpleString('3.1.0');
|
||||
public static readonly v314 = API.fromSimpleString('3.1.4');
|
||||
public static readonly v320 = API.fromSimpleString('3.2.0');
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user