mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-26 12:44:05 +00:00
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:
committed by
Matt Bierner
parent
5c705ea7ee
commit
89e4d3eddc
@@ -685,6 +685,12 @@
|
||||
"default": true,
|
||||
"description": "%configuration.tsserver.useSeparateSyntaxServer%",
|
||||
"scope": "window"
|
||||
},
|
||||
"typescript.tsserver.maxTsServerMemory": {
|
||||
"type": "number",
|
||||
"default": 0,
|
||||
"description": "%configuration.tsserver.maxTsServerMemory%",
|
||||
"scope": "window"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
"typescript.problemMatchers.tscWatch.label": "TypeScript problems (watch mode)",
|
||||
"configuration.suggest.paths": "Enable/disable suggestions for paths in import statements and require calls.",
|
||||
"configuration.tsserver.useSeparateSyntaxServer": "Enable/disable spawning a separate TypeScript server that can more quickly respond to syntax related operations, such as calculating folding or computing document symbols. Requires using TypeScript 3.4.0 or newer in the workspace.",
|
||||
"configuration.tsserver.maxTsServerMemory": "Set the maximum amount of memory (in MB) to allocate to the TypeScript server process",
|
||||
"typescript.locale": "Sets the locale used to report JavaScript and TypeScript errors. Requires using TypeScript 2.6.0 or newer in the workspace. Default of `null` uses VS Code's locale.",
|
||||
"javascript.implicitProjectConfig.experimentalDecorators": "Enable/disable `experimentalDecorators` for JavaScript files that are not part of a project. Existing jsconfig.json or tsconfig.json files override this setting. Requires using TypeScript 2.3.1 or newer in the workspace.",
|
||||
"configuration.suggest.autoImports": "Enable/disable auto import suggestions. Requires using TypeScript 2.6.1 or newer in the workspace.",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user