Skip to content

Commit 2046634

Browse files
authored
Add option for overriding GOMEMLIMIT (#1808)
1 parent 92c21db commit 2046634

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

_extension/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@
5757
"tags": [
5858
"experimental"
5959
]
60+
},
61+
"typescript.native-preview.goMemLimit": {
62+
"type": "string",
63+
"description": "Set GOMEMLIMIT for the language server (e.g., '2048MiB', '4GiB'). See https://pkg.go.dev/runtime#hdr-Environment_Variables for more information.",
64+
"pattern": "^[0-9]+(([KMGT]i)?B)?$",
65+
"patternErrorMessage": "Must be a valid memory limit (e.g., '2048MiB', '4GiB').",
66+
"tags": [
67+
"experimental"
68+
]
6069
}
6170
}
6271
}

_extension/src/client.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,31 @@ export class Client {
103103
const pprofDir = config.get<string>("pprofDir");
104104
const pprofArgs = pprofDir ? ["--pprofDir", pprofDir] : [];
105105

106+
const goMemLimit = config.get<string>("goMemLimit");
107+
const env = { ...process.env };
108+
if (goMemLimit) {
109+
// Keep this regex aligned with the pattern in package.json.
110+
if (/^[0-9]+(([KMGT]i)?B)?$/.test(goMemLimit)) {
111+
this.outputChannel.appendLine(`Setting GOMEMLIMIT=${goMemLimit}`);
112+
env.GOMEMLIMIT = goMemLimit;
113+
}
114+
else {
115+
this.outputChannel.error(`Invalid goMemLimit: ${goMemLimit}. Must be a valid memory limit (e.g., '2048MiB', '4GiB'). Not overriding GOMEMLIMIT.`);
116+
}
117+
}
118+
106119
const serverOptions: ServerOptions = {
107120
run: {
108121
command: this.exe.path,
109122
args: ["--lsp", ...pprofArgs],
110123
transport: TransportKind.stdio,
124+
options: { env },
111125
},
112126
debug: {
113127
command: this.exe.path,
114128
args: ["--lsp", ...pprofArgs],
115129
transport: TransportKind.stdio,
130+
options: { env },
116131
},
117132
};
118133

0 commit comments

Comments
 (0)