Skip to content

Commit

Permalink
improvement: Restore adding properties and env when fetching metals
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed May 23, 2024
1 parent a760bf2 commit 98df585
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions packages/metals-languageclient/src/fetchMetals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface PackedChildPromise {
export async function fetchMetals({
serverVersion,
serverProperties,
javaConfig: { coursier, javaPath },
javaConfig: { javaOptions, coursier, extraEnv, javaPath },
outputChannel,
}: FetchMetalsOptions): Promise<PackedChildPromise> {
const serverDependency = calcServerDependency(serverVersion);
Expand Down Expand Up @@ -53,17 +53,35 @@ export async function fetchMetals({
"-p",
];

const environment = {
env: {
...process.env,
...extraEnv,
},
};

if (coursier.endsWith(".jar")) {
const jarArgs = ["-Dfile.encoding=UTF-8", "-jar", coursier].concat(
coursierArgs
);
return { promise: spawn(javaPath, jarArgs) };
const jarArgs = [
...javaOptions,
...fetchProperties,
"-Dfile.encoding=UTF-8",
"-jar",
coursier,
].concat(coursierArgs);
return { promise: spawn(javaPath, jarArgs, environment) };
} else {
// Convert Java properties to the "-J" argument form used by Coursier
var javaArgs: Array<string> = [];

// setting properties on windows native launcher doesn't work
if (process.platform != "win32")
javaArgs = javaOptions
.concat(["-Dfile.encoding=UTF-8"])
.concat(fetchProperties)
.map((p) => `-J${p}`);

return {
promise: spawn(
coursier,
["-J-Dfile.encoding=UTF-8"].concat(coursierArgs)
),
promise: spawn(coursier, javaArgs.concat(coursierArgs), environment),
};
}
}
Expand Down

0 comments on commit 98df585

Please sign in to comment.