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