Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions _extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions _extension/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,29 @@ export class Client {
const pprofDir = config.get<string>("pprofDir");
const pprofArgs = pprofDir ? ["--pprofDir", pprofDir] : [];

const goMemLimit = config.get<string>("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.`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't unset goMemLimit

Copy link
Contributor Author

@maschwenk maschwenk Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d62cbcd

pulled out into a little helper to avoid having to do a bunch of weird nested conditional stuff and then don't need to "unset" anything, just set it once it's validated.

also figure at some point there might other env mutations that need to go on for other Go env vars, and might be easier to reason about if all that env configuration is done in one method

} else {
this.outputChannel.appendLine(`Setting GOMEMLIMIT=${goMemLimit}`);
}
}
const env = goMemLimit ? { ...process.env, GOMEMLIMIT: goMemLimit } : process.env;

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 },
},
};

Expand Down
Loading