diff --git a/Readme.md b/Readme.md index f056203..4ad08a9 100644 --- a/Readme.md +++ b/Readme.md @@ -79,6 +79,7 @@ Checkout [using the configuration file](https://github.com/neoclide/coc.nvim/wik - `tsserver.typingsCacheLocation`:Folder path for cache typings, default: `""` - `tsserver.formatOnType`:Run format on type special characters., default: `true` - `tsserver.enableJavascript`:Use tsserver for javascript files, default: `true` +- `tsserver.maxTsServerMemory`:Set the maximum amount of memory to allocate to the TypeScript server process - `tsserver.tsdk`:Directory contains tsserver.js,, default: `""` - `tsserver.npm`:Executable path of npm for download typings, default: `""` - `tsserver.log`:Log level of tsserver, default: `"off"` diff --git a/package.json b/package.json index 4dbcca9..4e6d48f 100644 --- a/package.json +++ b/package.json @@ -134,6 +134,11 @@ "default": false, "description": "Always use tsserver module from tsserver.tsdk or tsserver extension." }, + "tsserver.maxTsServerMemory": { + "type": "number", + "default": 0, + "description": "Set the maximum amount of memory to allocate to the TypeScript server process" + }, "tsserver.tsdk": { "type": "string", "default": "", diff --git a/src/server/typescriptServiceClient.ts b/src/server/typescriptServiceClient.ts index fa7a6b1..83cc089 100644 --- a/src/server/typescriptServiceClient.ts +++ b/src/server/typescriptServiceClient.ts @@ -278,8 +278,12 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient this.lastError = null const tsServerForkArgs = await this.getTsServerArgs() const debugPort = this._configuration.debugPort + const maxTsServerMemory = this._configuration.maxTsServerMemory const options = { - execArgv: debugPort ? [`--inspect=${debugPort}`] : [], // [`--debug-brk=5859`] + execArgv: [ + ...(debugPort ? [`--inspect=${debugPort}`] : []), // [`--debug-brk=5859`] + ...(maxTsServerMemory ? [`--max-old-space-size=${maxTsServerMemory}`] : []), + ], cwd: workspace.root } this.servicePromise = this.startProcess(currentVersion, tsServerForkArgs, options, resendModels) diff --git a/src/server/utils/configuration.ts b/src/server/utils/configuration.ts index cba937c..1c187db 100644 --- a/src/server/utils/configuration.ts +++ b/src/server/utils/configuration.ts @@ -88,6 +88,10 @@ export class TypeScriptServiceConfiguration { return this._configuration.get('formatOnType', false) } + public get maxTsServerMemory(): number { + return this._configuration.get('maxTsServerMemory', 0) + } + public get debugPort(): number | null { return this._configuration.get('debugPort', parseInt(process.env['TSS_DEBUG'], 10)) }