Skip to content

Commit

Permalink
use properties and environment when fetching metals
Browse files Browse the repository at this point in the history
  • Loading branch information
mliarakos committed May 11, 2024
1 parent 12a8ba7 commit c595d3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/metals-languageclient/src/fetchMetals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { JavaConfig } from "./getJavaConfig";

interface FetchMetalsOptions {
serverVersion: string;
serverProperties: string[];
javaConfig: JavaConfig;
}

Expand All @@ -17,15 +18,19 @@ interface PackedChildPromise {

export async function fetchMetals({
serverVersion,
javaConfig: { coursier },
serverProperties,
javaConfig: { javaOptions, coursier, extraEnv },
}: FetchMetalsOptions): Promise<PackedChildPromise> {
const serverDependency = calcServerDependency(serverVersion);

const fetchProperties = serverProperties.filter((p) => !p.startsWith("-agentlib"));
const javaArgs = javaOptions.concat(fetchProperties).map((p) => `-J${p}`);

const coursierArgs = [
"fetch",
"-p",
"--ttl",
// Use infinite ttl to avoid redunant "Checking..." logs when using SNAPSHOT
// Use infinite ttl to avoid redundant "Checking..." logs when using SNAPSHOT
// versions. Metals SNAPSHOT releases are effectively immutable since we
// never publish the same version twice.
"Inf",
Expand All @@ -39,7 +44,14 @@ export async function fetchMetals({
"-p",
];

return { promise: spawn(coursier, coursierArgs) };
const environment = {
env: {
...process.env,
...extraEnv
}
};

return { promise: spawn(coursier, javaArgs.concat(coursierArgs), environment) };
}

export function calcServerDependency(serverVersion: string): string {
Expand Down
1 change: 1 addition & 0 deletions packages/metals-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ async function fetchAndLaunchMetals(

const fetchProcess = fetchMetals({
serverVersion,
serverProperties,
javaConfig,
});

Expand Down

0 comments on commit c595d3d

Please sign in to comment.