Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use properties and environment when fetching metals #1498

Merged
merged 4 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 30 additions & 3 deletions packages/metals-languageclient/src/fetchMetals.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import * as semver from "semver";
import { ChildProcessPromise, spawn } from "promisify-child-process";
import { JavaConfig } from "./getJavaConfig";
import { OutputChannel } from "./interfaces/OutputChannel";

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

/**
Expand All @@ -17,15 +20,30 @@ interface PackedChildPromise {

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

const fetchProperties = serverProperties.filter(
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just warn here, since we do debug metals sometimes and that requires setting debug settings.

Alternatively we could check if it's set to quiet=y.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I restored that filter call from v1.29.0, but I'm not familiar with why it was there to being with.

To make sure I understand, are you asking to emit a warning message if -agentlib is present indicating that it isn't being passed to Coursier?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ach right, my bad. I forgot it was just for coursier, I assumed too much 😓 It's fine as it is, thanks!

(p) => !p.startsWith("-agentlib")
);
if (fetchProperties.length != serverProperties.length) {
outputChannel.appendLine(
'Ignoring "-agentlib" option when fetching Metals with Coursier'
);
}

// Convert Java properties to the "-J" argument form used by Coursier
const javaArgs = javaOptions.concat(fetchProperties).map((p) => `-J${p}`);

const coursierArgs = [
...javaArgs,
"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 +57,16 @@ export async function fetchMetals({
"-p",
];

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

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

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

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

const title = `Downloading Metals v${serverVersion}`;
Expand Down