From 7f45727f8ab1015a7b70cf3b609d35d9d0f108c4 Mon Sep 17 00:00:00 2001 From: Max schwenk Date: Fri, 3 Oct 2025 15:18:34 -0400 Subject: [PATCH 1/7] Different approach --- _extension/package.json | 5 +++++ _extension/src/client.ts | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/_extension/package.json b/_extension/package.json index 8aca1f4c3d..454dc60f96 100644 --- a/_extension/package.json +++ b/_extension/package.json @@ -51,6 +51,11 @@ "type": "string", "description": "Path to the @typescript/native-preview package or tsgo binary directory. If not specified, the extension will look for it in the default location.", "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.", + "tags": ["experimental"] } } } diff --git a/_extension/src/client.ts b/_extension/src/client.ts index b759501e97..fc0f4096f0 100644 --- a/_extension/src/client.ts +++ b/_extension/src/client.ts @@ -95,16 +95,25 @@ export class Client { const pprofDir = config.get("pprofDir"); const pprofArgs = pprofDir ? ["--pprofDir", pprofDir] : []; + // Get goMemLimit + const goMemLimit = config.get("goMemLimit"); + const env = goMemLimit ? { ...process.env, GOMEMLIMIT: goMemLimit } : process.env; + if (goMemLimit) { + this.outputChannel.appendLine(`Setting GOMEMLIMIT=${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 }, }, }; From 72e645262e83b1919ad1d890776d096d819a2c72 Mon Sep 17 00:00:00 2001 From: Max schwenk Date: Fri, 12 Dec 2025 17:05:01 -0500 Subject: [PATCH 2/7] Add pattern --- _extension/package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/_extension/package.json b/_extension/package.json index 3f7447b51b..e18958164e 100644 --- a/_extension/package.json +++ b/_extension/package.json @@ -61,6 +61,8 @@ "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]iB$", + "patternErrorMessage": "Must be a valid memory limit (e.g., '2048MiB', '4GiB').", "tags": [ "experimental" ] From 5d58a9071fa37e7a758bf617d9deac418fb19ea1 Mon Sep 17 00:00:00 2001 From: Max schwenk Date: Fri, 12 Dec 2025 18:32:52 -0500 Subject: [PATCH 3/7] Grr a hallucination --- _extension/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_extension/package.json b/_extension/package.json index e18958164e..3f2ec43b77 100644 --- a/_extension/package.json +++ b/_extension/package.json @@ -61,7 +61,7 @@ "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]iB$", + "pattern": "^[0-9]+(([KMGT]i)?B)?$", "patternErrorMessage": "Must be a valid memory limit (e.g., '2048MiB', '4GiB').", "tags": [ "experimental" From 697ec8633bc70498761433bb08120d2d64b3c05e Mon Sep 17 00:00:00 2001 From: Max schwenk Date: Fri, 12 Dec 2025 18:37:43 -0500 Subject: [PATCH 4/7] Retest the pattern in the code as well --- _extension/src/client.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/_extension/src/client.ts b/_extension/src/client.ts index 8abd6b74cd..503a1b189b 100644 --- a/_extension/src/client.ts +++ b/_extension/src/client.ts @@ -103,12 +103,16 @@ export class Client { const pprofDir = config.get("pprofDir"); const pprofArgs = pprofDir ? ["--pprofDir", pprofDir] : []; - // Get goMemLimit const goMemLimit = config.get("goMemLimit"); - const env = goMemLimit ? { ...process.env, GOMEMLIMIT: goMemLimit } : process.env; if (goMemLimit) { + // Keep this regex aligned with the pattern in package.json. + if (!/^[0-9]+(([KMGT]i)?B)?$/.test(goMemLimit)) { + throw new Error("Invalid goMemLimit. Must be a valid memory limit (e.g., '2048MiB', '4GiB')."); + } this.outputChannel.appendLine(`Setting GOMEMLIMIT=${goMemLimit}`); } + const env = goMemLimit ? { ...process.env, GOMEMLIMIT: goMemLimit } : process.env; + const serverOptions: ServerOptions = { run: { From e0f1bb756c9cea364b88fd2f14ac25f26cc86707 Mon Sep 17 00:00:00 2001 From: Max schwenk Date: Fri, 12 Dec 2025 19:15:09 -0500 Subject: [PATCH 5/7] Don't throw, just lg error and ignore --- _extension/src/client.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_extension/src/client.ts b/_extension/src/client.ts index 503a1b189b..860da9e7dd 100644 --- a/_extension/src/client.ts +++ b/_extension/src/client.ts @@ -107,13 +107,13 @@ export class Client { if (goMemLimit) { // Keep this regex aligned with the pattern in package.json. if (!/^[0-9]+(([KMGT]i)?B)?$/.test(goMemLimit)) { - throw new Error("Invalid goMemLimit. Must be a valid memory limit (e.g., '2048MiB', '4GiB')."); + this.outputChannel.error(`Invalid goMemLimit: ${goMemLimit}. Must be a valid memory limit (e.g., '2048MiB', '4GiB'). Not overriding GOMEMLIMIT.`); + } else { + this.outputChannel.appendLine(`Setting GOMEMLIMIT=${goMemLimit}`); } - this.outputChannel.appendLine(`Setting GOMEMLIMIT=${goMemLimit}`); } const env = goMemLimit ? { ...process.env, GOMEMLIMIT: goMemLimit } : process.env; - const serverOptions: ServerOptions = { run: { command: this.exe.path, From d62cbcddda9c4f95941a5f66e964685aff145479 Mon Sep 17 00:00:00 2001 From: Max schwenk Date: Fri, 12 Dec 2025 19:57:45 -0500 Subject: [PATCH 6/7] Little helper method to generate env so I don't have to have weird conditionals --- _extension/src/client.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/_extension/src/client.ts b/_extension/src/client.ts index 860da9e7dd..8268e5b493 100644 --- a/_extension/src/client.ts +++ b/_extension/src/client.ts @@ -94,6 +94,19 @@ export class Client { return this.start(context, exe); } + generateGoMemLimitEnv(goMemLimit: string | undefined): Record { + if (!goMemLimit) { + return {}; + } + // Keep this regex aligned with the pattern in package.json. + if (!/^[0-9]+(([KMGT]i)?B)?$/.test(goMemLimit)) { + this.outputChannel.error(`Invalid goMemLimit: ${goMemLimit}. Must be a valid memory limit (e.g., '2048MiB', '4GiB'). Not overriding GOMEMLIMIT.`); + return {}; + } + this.outputChannel.appendLine(`Setting GOMEMLIMIT=${goMemLimit}`); + return { GOMEMLIMIT: goMemLimit }; + } + async start(context: vscode.ExtensionContext, exe: { path: string; version: string; }): Promise { this.exe = exe; this.outputChannel.appendLine(`Resolved to ${this.exe.path}`); @@ -104,15 +117,7 @@ export class Client { const pprofArgs = pprofDir ? ["--pprofDir", pprofDir] : []; const goMemLimit = config.get("goMemLimit"); - if (goMemLimit) { - // Keep this regex aligned with the pattern in package.json. - if (!/^[0-9]+(([KMGT]i)?B)?$/.test(goMemLimit)) { - this.outputChannel.error(`Invalid goMemLimit: ${goMemLimit}. Must be a valid memory limit (e.g., '2048MiB', '4GiB'). Not overriding GOMEMLIMIT.`); - } else { - this.outputChannel.appendLine(`Setting GOMEMLIMIT=${goMemLimit}`); - } - } - const env = goMemLimit ? { ...process.env, GOMEMLIMIT: goMemLimit } : process.env; + const env = { ...process.env, ...this.generateGoMemLimitEnv(goMemLimit) }; const serverOptions: ServerOptions = { run: { From fcac93b07c1d09b08a01bfa6bf1df42b85718be2 Mon Sep 17 00:00:00 2001 From: Max schwenk Date: Sat, 13 Dec 2025 12:45:32 -0500 Subject: [PATCH 7/7] Un-abstract --- _extension/src/client.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/_extension/src/client.ts b/_extension/src/client.ts index 8268e5b493..6239282442 100644 --- a/_extension/src/client.ts +++ b/_extension/src/client.ts @@ -94,19 +94,6 @@ export class Client { return this.start(context, exe); } - generateGoMemLimitEnv(goMemLimit: string | undefined): Record { - if (!goMemLimit) { - return {}; - } - // Keep this regex aligned with the pattern in package.json. - if (!/^[0-9]+(([KMGT]i)?B)?$/.test(goMemLimit)) { - this.outputChannel.error(`Invalid goMemLimit: ${goMemLimit}. Must be a valid memory limit (e.g., '2048MiB', '4GiB'). Not overriding GOMEMLIMIT.`); - return {}; - } - this.outputChannel.appendLine(`Setting GOMEMLIMIT=${goMemLimit}`); - return { GOMEMLIMIT: goMemLimit }; - } - async start(context: vscode.ExtensionContext, exe: { path: string; version: string; }): Promise { this.exe = exe; this.outputChannel.appendLine(`Resolved to ${this.exe.path}`); @@ -117,7 +104,17 @@ export class Client { const pprofArgs = pprofDir ? ["--pprofDir", pprofDir] : []; const goMemLimit = config.get("goMemLimit"); - const env = { ...process.env, ...this.generateGoMemLimitEnv(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: {