parent
b7e633aae1
commit
41807b889d
|
@ -14,7 +14,7 @@ import { ITypeScriptVersionProvider, TypeScriptVersion, TypeScriptVersionSource
|
|||
import { WorkerServerProcess } from './tsServer/serverProcess.browser';
|
||||
import API from './utils/api';
|
||||
import { CommandManager } from './commands/commandManager';
|
||||
import { TypeScriptServiceConfiguration } from './utils/configuration';
|
||||
import { StandardServiceConfigurationProvider, TypeScriptServiceConfiguration } from './utils/configuration';
|
||||
import { PluginManager } from './utils/plugins';
|
||||
import { ActiveJsTsEditorTracker } from './utils/activeJsTsEditorTracker';
|
||||
|
||||
|
@ -66,7 +66,8 @@ export function activate(
|
|||
cancellerFactory: noopRequestCancellerFactory,
|
||||
versionProvider,
|
||||
processFactory: WorkerServerProcess,
|
||||
activeJsTsEditorTracker
|
||||
activeJsTsEditorTracker,
|
||||
serviceConfigurationProvider: new StandardServiceConfigurationProvider(),
|
||||
}, item => {
|
||||
onCompletionAccepted.fire(item);
|
||||
});
|
||||
|
|
|
@ -15,6 +15,7 @@ import { NodeLogDirectoryProvider } from './tsServer/logDirectoryProvider.electr
|
|||
import { ChildServerProcess } from './tsServer/serverProcess.electron';
|
||||
import { DiskTypeScriptVersionProvider } from './tsServer/versionProvider.electron';
|
||||
import { ActiveJsTsEditorTracker } from './utils/activeJsTsEditorTracker';
|
||||
import { StandardServiceConfigurationProvider } from './utils/configuration';
|
||||
import { onCaseInsenitiveFileSystem } from './utils/fileSystem.electron';
|
||||
import { PluginManager } from './utils/plugins';
|
||||
import * as temp from './utils/temp.electron';
|
||||
|
@ -47,6 +48,7 @@ export function activate(
|
|||
versionProvider,
|
||||
processFactory: ChildServerProcess,
|
||||
activeJsTsEditorTracker,
|
||||
serviceConfigurationProvider: new StandardServiceConfigurationProvider(),
|
||||
}, item => {
|
||||
onCompletionAccepted.fire(item);
|
||||
});
|
||||
|
|
|
@ -12,6 +12,7 @@ import { ITypeScriptVersionProvider } from './tsServer/versionProvider';
|
|||
import TypeScriptServiceClientHost from './typeScriptServiceClientHost';
|
||||
import { ActiveJsTsEditorTracker } from './utils/activeJsTsEditorTracker';
|
||||
import { flatten } from './utils/arrays';
|
||||
import { ServiceConfigurationProvider } from './utils/configuration';
|
||||
import * as fileSchemes from './utils/fileSchemes';
|
||||
import { standardLanguageDescriptions } from './utils/languageDescription';
|
||||
import { lazy, Lazy } from './utils/lazy';
|
||||
|
@ -29,6 +30,7 @@ export function createLazyClientHost(
|
|||
versionProvider: ITypeScriptVersionProvider,
|
||||
processFactory: TsServerProcessFactory,
|
||||
activeJsTsEditorTracker: ActiveJsTsEditorTracker,
|
||||
serviceConfigurationProvider: ServiceConfigurationProvider,
|
||||
},
|
||||
onCompletionAccepted: (item: vscode.CompletionItem) => void,
|
||||
): Lazy<TypeScriptServiceClientHost> {
|
||||
|
|
|
@ -31,6 +31,7 @@ import TypingsStatus, { AtaProgressReporter } from './utils/typingsStatus';
|
|||
import * as ProjectStatus from './utils/largeProjectStatus';
|
||||
import { ActiveJsTsEditorTracker } from './utils/activeJsTsEditorTracker';
|
||||
import { LogLevelMonitor } from './utils/logLevelMonitor';
|
||||
import { ServiceConfigurationProvider } from './utils/configuration';
|
||||
|
||||
// Style check diagnostics that can be reported as warnings
|
||||
const styleCheckDiagnostics = new Set([
|
||||
|
@ -69,6 +70,7 @@ export default class TypeScriptServiceClientHost extends Disposable {
|
|||
versionProvider: ITypeScriptVersionProvider,
|
||||
processFactory: TsServerProcessFactory,
|
||||
activeJsTsEditorTracker: ActiveJsTsEditorTracker,
|
||||
serviceConfigurationProvider: ServiceConfigurationProvider,
|
||||
},
|
||||
onCompletionAccepted: (item: vscode.CompletionItem) => void,
|
||||
) {
|
||||
|
|
|
@ -19,7 +19,7 @@ import { TypeScriptVersionManager } from './tsServer/versionManager';
|
|||
import { ITypeScriptVersionProvider, TypeScriptVersion } from './tsServer/versionProvider';
|
||||
import { ClientCapabilities, ClientCapability, ExecConfig, ITypeScriptServiceClient, ServerResponse, TypeScriptRequests } from './typescriptService';
|
||||
import API from './utils/api';
|
||||
import { areServiceConfigurationsEqual, loadServiceConfigurationFromWorkspace, SeparateSyntaxServerConfiguration, TsServerLogLevel, TypeScriptServiceConfiguration } from './utils/configuration';
|
||||
import { areServiceConfigurationsEqual, ServiceConfigurationProvider, SeparateSyntaxServerConfiguration, TsServerLogLevel, TypeScriptServiceConfiguration } from './utils/configuration';
|
||||
import { Disposable } from './utils/dispose';
|
||||
import * as fileSchemes from './utils/fileSchemes';
|
||||
import { Logger } from './utils/logger';
|
||||
|
@ -135,6 +135,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
|
|||
cancellerFactory: OngoingRequestCancellerFactory,
|
||||
versionProvider: ITypeScriptVersionProvider,
|
||||
processFactory: TsServerProcessFactory,
|
||||
serviceConfigurationProvider: ServiceConfigurationProvider,
|
||||
},
|
||||
allModeIds: readonly string[]
|
||||
) {
|
||||
|
@ -161,7 +162,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
|
|||
|
||||
this.numberRestarts = 0;
|
||||
|
||||
this._configuration = loadServiceConfigurationFromWorkspace();
|
||||
this._configuration = services.serviceConfigurationProvider.loadFromWorkspace();
|
||||
this.versionProvider.updateConfiguration(this._configuration);
|
||||
|
||||
this.pluginPathsProvider = new TypeScriptPluginPathsProvider(this._configuration);
|
||||
|
@ -185,7 +186,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
|
|||
|
||||
vscode.workspace.onDidChangeConfiguration(() => {
|
||||
const oldConfiguration = this._configuration;
|
||||
this._configuration = loadServiceConfigurationFromWorkspace();
|
||||
this._configuration = services.serviceConfigurationProvider.loadFromWorkspace();
|
||||
|
||||
this.versionProvider.updateConfiguration(this._configuration);
|
||||
this._versionManager.updateConfiguration(this._configuration);
|
||||
|
|
|
@ -111,111 +111,119 @@ export function areServiceConfigurationsEqual(a: TypeScriptServiceConfiguration,
|
|||
return objects.equals(a, b);
|
||||
}
|
||||
|
||||
export function loadServiceConfigurationFromWorkspace(): TypeScriptServiceConfiguration {
|
||||
const configuration = vscode.workspace.getConfiguration();
|
||||
return {
|
||||
locale: extractLocale(configuration),
|
||||
globalTsdk: extractGlobalTsdk(configuration),
|
||||
localTsdk: extractLocalTsdk(configuration),
|
||||
npmLocation: readNpmLocation(configuration),
|
||||
tsServerLogLevel: readTsServerLogLevel(configuration),
|
||||
tsServerPluginPaths: readTsServerPluginPaths(configuration),
|
||||
implicitProjectConfiguration: new ImplicitProjectConfiguration(configuration),
|
||||
disableAutomaticTypeAcquisition: readDisableAutomaticTypeAcquisition(configuration),
|
||||
separateSyntaxServer: readUseSeparateSyntaxServer(configuration),
|
||||
enableProjectDiagnostics: readEnableProjectDiagnostics(configuration),
|
||||
maxTsServerMemory: readMaxTsServerMemory(configuration),
|
||||
enablePromptUseWorkspaceTsdk: readEnablePromptUseWorkspaceTsdk(configuration),
|
||||
watchOptions: readWatchOptions(configuration),
|
||||
includePackageJsonAutoImports: readIncludePackageJsonAutoImports(configuration),
|
||||
enableTsServerTracing: readEnableTsServerTracing(configuration),
|
||||
};
|
||||
export interface ServiceConfigurationProvider {
|
||||
loadFromWorkspace(): TypeScriptServiceConfiguration;
|
||||
}
|
||||
|
||||
function fixPathPrefixes(inspectValue: string): string {
|
||||
const pathPrefixes = ['~' + path.sep];
|
||||
for (const pathPrefix of pathPrefixes) {
|
||||
if (inspectValue.startsWith(pathPrefix)) {
|
||||
return path.join(os.homedir(), inspectValue.slice(pathPrefix.length));
|
||||
export class StandardServiceConfigurationProvider implements ServiceConfigurationProvider {
|
||||
|
||||
public loadFromWorkspace(): TypeScriptServiceConfiguration {
|
||||
const configuration = vscode.workspace.getConfiguration();
|
||||
return {
|
||||
locale: this.extractLocale(configuration),
|
||||
globalTsdk: this.extractGlobalTsdk(configuration),
|
||||
localTsdk: this.extractLocalTsdk(configuration),
|
||||
npmLocation: this.readNpmLocation(configuration),
|
||||
tsServerLogLevel: this.readTsServerLogLevel(configuration),
|
||||
tsServerPluginPaths: this.readTsServerPluginPaths(configuration),
|
||||
implicitProjectConfiguration: new ImplicitProjectConfiguration(configuration),
|
||||
disableAutomaticTypeAcquisition: this.readDisableAutomaticTypeAcquisition(configuration),
|
||||
separateSyntaxServer: this.readUseSeparateSyntaxServer(configuration),
|
||||
enableProjectDiagnostics: this.readEnableProjectDiagnostics(configuration),
|
||||
maxTsServerMemory: this.readMaxTsServerMemory(configuration),
|
||||
enablePromptUseWorkspaceTsdk: this.readEnablePromptUseWorkspaceTsdk(configuration),
|
||||
watchOptions: this.readWatchOptions(configuration),
|
||||
includePackageJsonAutoImports: this.readIncludePackageJsonAutoImports(configuration),
|
||||
enableTsServerTracing: this.readEnableTsServerTracing(configuration),
|
||||
};
|
||||
}
|
||||
|
||||
protected fixPathPrefixes(inspectValue: string): string {
|
||||
const pathPrefixes = ['~' + path.sep];
|
||||
for (const pathPrefix of pathPrefixes) {
|
||||
if (inspectValue.startsWith(pathPrefix)) {
|
||||
return path.join(os.homedir(), inspectValue.slice(pathPrefix.length));
|
||||
}
|
||||
}
|
||||
return inspectValue;
|
||||
}
|
||||
return inspectValue;
|
||||
}
|
||||
|
||||
function extractGlobalTsdk(configuration: vscode.WorkspaceConfiguration): string | null {
|
||||
const inspect = configuration.inspect('typescript.tsdk');
|
||||
if (inspect && typeof inspect.globalValue === 'string') {
|
||||
return fixPathPrefixes(inspect.globalValue);
|
||||
protected extractGlobalTsdk(configuration: vscode.WorkspaceConfiguration): string | null {
|
||||
const inspect = configuration.inspect('typescript.tsdk');
|
||||
if (inspect && typeof inspect.globalValue === 'string') {
|
||||
return this.fixPathPrefixes(inspect.globalValue);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function extractLocalTsdk(configuration: vscode.WorkspaceConfiguration): string | null {
|
||||
const inspect = configuration.inspect('typescript.tsdk');
|
||||
if (inspect && typeof inspect.workspaceValue === 'string') {
|
||||
return fixPathPrefixes(inspect.workspaceValue);
|
||||
protected extractLocalTsdk(configuration: vscode.WorkspaceConfiguration): string | null {
|
||||
const inspect = configuration.inspect('typescript.tsdk');
|
||||
if (inspect && typeof inspect.workspaceValue === 'string') {
|
||||
return this.fixPathPrefixes(inspect.workspaceValue);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function readTsServerLogLevel(configuration: vscode.WorkspaceConfiguration): TsServerLogLevel {
|
||||
const setting = configuration.get<string>('typescript.tsserver.log', 'off');
|
||||
return TsServerLogLevel.fromString(setting);
|
||||
}
|
||||
|
||||
function readTsServerPluginPaths(configuration: vscode.WorkspaceConfiguration): string[] {
|
||||
return configuration.get<string[]>('typescript.tsserver.pluginPaths', []);
|
||||
}
|
||||
|
||||
function readNpmLocation(configuration: vscode.WorkspaceConfiguration): string | null {
|
||||
return configuration.get<string | null>('typescript.npm', null);
|
||||
}
|
||||
|
||||
function readDisableAutomaticTypeAcquisition(configuration: vscode.WorkspaceConfiguration): boolean {
|
||||
return configuration.get<boolean>('typescript.disableAutomaticTypeAcquisition', false);
|
||||
}
|
||||
|
||||
function extractLocale(configuration: vscode.WorkspaceConfiguration): string | null {
|
||||
return configuration.get<string | null>('typescript.locale', null);
|
||||
}
|
||||
|
||||
function readUseSeparateSyntaxServer(configuration: vscode.WorkspaceConfiguration): SeparateSyntaxServerConfiguration {
|
||||
const value = configuration.get<boolean | string>('typescript.tsserver.useSeparateSyntaxServer', true);
|
||||
if (value === 'forAllRequests') {
|
||||
return SeparateSyntaxServerConfiguration.ForAllRequests;
|
||||
protected readTsServerLogLevel(configuration: vscode.WorkspaceConfiguration): TsServerLogLevel {
|
||||
const setting = configuration.get<string>('typescript.tsserver.log', 'off');
|
||||
return TsServerLogLevel.fromString(setting);
|
||||
}
|
||||
if (value === true) {
|
||||
return SeparateSyntaxServerConfiguration.Enabled;
|
||||
|
||||
protected readTsServerPluginPaths(configuration: vscode.WorkspaceConfiguration): string[] {
|
||||
return configuration.get<string[]>('typescript.tsserver.pluginPaths', []);
|
||||
}
|
||||
return SeparateSyntaxServerConfiguration.Disabled;
|
||||
}
|
||||
|
||||
function readEnableProjectDiagnostics(configuration: vscode.WorkspaceConfiguration): boolean {
|
||||
return configuration.get<boolean>('typescript.tsserver.experimental.enableProjectDiagnostics', false);
|
||||
}
|
||||
|
||||
function readWatchOptions(configuration: vscode.WorkspaceConfiguration): protocol.WatchOptions | undefined {
|
||||
return configuration.get<protocol.WatchOptions>('typescript.tsserver.watchOptions');
|
||||
}
|
||||
|
||||
function readIncludePackageJsonAutoImports(configuration: vscode.WorkspaceConfiguration): 'auto' | 'on' | 'off' | undefined {
|
||||
return configuration.get<'auto' | 'on' | 'off'>('typescript.preferences.includePackageJsonAutoImports');
|
||||
}
|
||||
|
||||
function readMaxTsServerMemory(configuration: vscode.WorkspaceConfiguration): number {
|
||||
const defaultMaxMemory = 3072;
|
||||
const minimumMaxMemory = 128;
|
||||
const memoryInMB = configuration.get<number>('typescript.tsserver.maxTsServerMemory', defaultMaxMemory);
|
||||
if (!Number.isSafeInteger(memoryInMB)) {
|
||||
return defaultMaxMemory;
|
||||
protected readNpmLocation(configuration: vscode.WorkspaceConfiguration): string | null {
|
||||
return configuration.get<string | null>('typescript.npm', null);
|
||||
}
|
||||
return Math.max(memoryInMB, minimumMaxMemory);
|
||||
}
|
||||
|
||||
function readEnablePromptUseWorkspaceTsdk(configuration: vscode.WorkspaceConfiguration): boolean {
|
||||
return configuration.get<boolean>('typescript.enablePromptUseWorkspaceTsdk', false);
|
||||
}
|
||||
protected readDisableAutomaticTypeAcquisition(configuration: vscode.WorkspaceConfiguration): boolean {
|
||||
return configuration.get<boolean>('typescript.disableAutomaticTypeAcquisition', false);
|
||||
}
|
||||
|
||||
protected extractLocale(configuration: vscode.WorkspaceConfiguration): string | null {
|
||||
return configuration.get<string | null>('typescript.locale', null);
|
||||
}
|
||||
|
||||
protected readUseSeparateSyntaxServer(configuration: vscode.WorkspaceConfiguration): SeparateSyntaxServerConfiguration {
|
||||
const value = configuration.get<boolean | string>('typescript.tsserver.useSeparateSyntaxServer', true);
|
||||
if (value === 'forAllRequests') {
|
||||
return SeparateSyntaxServerConfiguration.ForAllRequests;
|
||||
}
|
||||
if (value === true) {
|
||||
return SeparateSyntaxServerConfiguration.Enabled;
|
||||
}
|
||||
return SeparateSyntaxServerConfiguration.Disabled;
|
||||
}
|
||||
|
||||
protected readEnableProjectDiagnostics(configuration: vscode.WorkspaceConfiguration): boolean {
|
||||
return configuration.get<boolean>('typescript.tsserver.experimental.enableProjectDiagnostics', false);
|
||||
}
|
||||
|
||||
protected readWatchOptions(configuration: vscode.WorkspaceConfiguration): protocol.WatchOptions | undefined {
|
||||
return configuration.get<protocol.WatchOptions>('typescript.tsserver.watchOptions');
|
||||
}
|
||||
|
||||
protected readIncludePackageJsonAutoImports(configuration: vscode.WorkspaceConfiguration): 'auto' | 'on' | 'off' | undefined {
|
||||
return configuration.get<'auto' | 'on' | 'off'>('typescript.preferences.includePackageJsonAutoImports');
|
||||
}
|
||||
|
||||
protected readMaxTsServerMemory(configuration: vscode.WorkspaceConfiguration): number {
|
||||
const defaultMaxMemory = 3072;
|
||||
const minimumMaxMemory = 128;
|
||||
const memoryInMB = configuration.get<number>('typescript.tsserver.maxTsServerMemory', defaultMaxMemory);
|
||||
if (!Number.isSafeInteger(memoryInMB)) {
|
||||
return defaultMaxMemory;
|
||||
}
|
||||
return Math.max(memoryInMB, minimumMaxMemory);
|
||||
}
|
||||
|
||||
protected readEnablePromptUseWorkspaceTsdk(configuration: vscode.WorkspaceConfiguration): boolean {
|
||||
return configuration.get<boolean>('typescript.enablePromptUseWorkspaceTsdk', false);
|
||||
}
|
||||
|
||||
protected readEnableTsServerTracing(configuration: vscode.WorkspaceConfiguration): boolean {
|
||||
return configuration.get<boolean>('typescript.tsserver.enableTracing', false);
|
||||
}
|
||||
|
||||
function readEnableTsServerTracing(configuration: vscode.WorkspaceConfiguration): boolean {
|
||||
return configuration.get<boolean>('typescript.tsserver.enableTracing', false);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue