Add setting to configure the max memory for tsserver (#82630)

* Add setting to configure the max memory for tsserver

* Fix silly tpo from fixing formatting

* Add "MB" to setting description string

* Add validation to configuration value

* Add 128MB as a lower bound
This commit is contained in:
Michael Loughry
2019-10-15 13:45:11 -07:00
committed by Matt Bierner
parent 5c705ea7ee
commit 89e4d3eddc
4 changed files with 25 additions and 4 deletions

View File

@@ -72,7 +72,7 @@ export class TypeScriptServerSpawner {
}
this._logger.info(`<${kind}> Forking...`);
const childProcess = electron.fork(version.tsServerPath, args, this.getForkOptions(kind));
const childProcess = electron.fork(version.tsServerPath, args, this.getForkOptions(kind, configuration));
this._logger.info(`<${kind}> Starting...`);
return new ProcessBasedTsServer(
@@ -85,10 +85,13 @@ export class TypeScriptServerSpawner {
this._tracer);
}
private getForkOptions(kind: ServerKind) {
private getForkOptions(kind: ServerKind, configuration: TypeScriptServiceConfiguration) {
const debugPort = TypeScriptServerSpawner.getDebugPort(kind);
const tsServerForkOptions: electron.ForkOptions = {
execArgv: debugPort ? [`--inspect=${debugPort}`] : [],
execArgv: [
...(debugPort ? [`--inspect=${debugPort}`] : []),
...(configuration.maxTsServerMemory ? [`--max-old-space-size=${configuration.maxTsServerMemory}`] : [])
]
};
return tsServerForkOptions;
}

View File

@@ -55,6 +55,7 @@ export class TypeScriptServiceConfiguration {
public readonly experimentalDecorators: boolean;
public readonly disableAutomaticTypeAcquisition: boolean;
public readonly useSeparateSyntaxServer: boolean;
public readonly maxTsServerMemory: number;
public static loadFromWorkspace(): TypeScriptServiceConfiguration {
return new TypeScriptServiceConfiguration();
@@ -73,6 +74,7 @@ export class TypeScriptServiceConfiguration {
this.experimentalDecorators = TypeScriptServiceConfiguration.readExperimentalDecorators(configuration);
this.disableAutomaticTypeAcquisition = TypeScriptServiceConfiguration.readDisableAutomaticTypeAcquisition(configuration);
this.useSeparateSyntaxServer = TypeScriptServiceConfiguration.readUseSeparateSyntaxServer(configuration);
this.maxTsServerMemory = TypeScriptServiceConfiguration.readMaxTsServerMemory(configuration);
}
public isEqualTo(other: TypeScriptServiceConfiguration): boolean {
@@ -85,7 +87,8 @@ export class TypeScriptServiceConfiguration {
&& this.experimentalDecorators === other.experimentalDecorators
&& this.disableAutomaticTypeAcquisition === other.disableAutomaticTypeAcquisition
&& arrays.equals(this.tsServerPluginPaths, other.tsServerPluginPaths)
&& this.useSeparateSyntaxServer === other.useSeparateSyntaxServer;
&& this.useSeparateSyntaxServer === other.useSeparateSyntaxServer
&& this.maxTsServerMemory === other.maxTsServerMemory;
}
private static fixPathPrefixes(inspectValue: string): string {
@@ -146,4 +149,12 @@ export class TypeScriptServiceConfiguration {
private static readUseSeparateSyntaxServer(configuration: vscode.WorkspaceConfiguration): boolean {
return configuration.get<boolean>('typescript.tsserver.useSeparateSyntaxServer', true);
}
private static readMaxTsServerMemory(configuration: vscode.WorkspaceConfiguration): number {
const memoryInMB = configuration.get<number>('typescript.tsserver.maxTsServerMemory', 0);
if (!Number.isSafeInteger(memoryInMB) || memoryInMB < 128) {
return 0;
}
return memoryInMB;
}
}