diff --git a/_extension/package.json b/_extension/package.json index 8705bb6cef..3f2ec43b77 100644 --- a/_extension/package.json +++ b/_extension/package.json @@ -57,6 +57,15 @@ "tags": [ "experimental" ] + }, + "typescript.native-preview.goMemLimit": { + "type": "string", + "description": "Set GOMEMLIMIT for the language server (e.g., '2048MiB', '4GiB'). See https://pkg.go.dev/runtime#hdr-Environment_Variables for more information.", + "pattern": "^[0-9]+(([KMGT]i)?B)?$", + "patternErrorMessage": "Must be a valid memory limit (e.g., '2048MiB', '4GiB').", + "tags": [ + "experimental" + ] } } } diff --git a/_extension/src/client.ts b/_extension/src/client.ts index d8cb37f315..6239282442 100644 --- a/_extension/src/client.ts +++ b/_extension/src/client.ts @@ -103,16 +103,31 @@ export class Client { const pprofDir = config.get("pprofDir"); const pprofArgs = pprofDir ? ["--pprofDir", pprofDir] : []; + const goMemLimit = config.get("goMemLimit"); + const env = { ...process.env }; + if (goMemLimit) { + // Keep this regex aligned with the pattern in package.json. + if (/^[0-9]+(([KMGT]i)?B)?$/.test(goMemLimit)) { + this.outputChannel.appendLine(`Setting GOMEMLIMIT=${goMemLimit}`); + env.GOMEMLIMIT = goMemLimit; + } + else { + this.outputChannel.error(`Invalid goMemLimit: ${goMemLimit}. Must be a valid memory limit (e.g., '2048MiB', '4GiB'). Not overriding GOMEMLIMIT.`); + } + } + const serverOptions: ServerOptions = { run: { command: this.exe.path, args: ["--lsp", ...pprofArgs], transport: TransportKind.stdio, + options: { env }, }, debug: { command: this.exe.path, args: ["--lsp", ...pprofArgs], transport: TransportKind.stdio, + options: { env }, }, };