From 71f08b373d9f875532c9ecb03fdbeeea2372590a Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Thu, 24 Feb 2022 17:20:46 +0100 Subject: [PATCH 1/2] Add mirror env variable when set by the user This can be found https://github.com/coursier/coursier/blob/master/modules/paths/src/main/java/coursier/paths/Mirror.java#L26 --- src/detectLaunchConfigurationChanges.ts | 1 + src/getJavaConfig.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/detectLaunchConfigurationChanges.ts b/src/detectLaunchConfigurationChanges.ts index 46184ec..b29b216 100644 --- a/src/detectLaunchConfigurationChanges.ts +++ b/src/detectLaunchConfigurationChanges.ts @@ -17,6 +17,7 @@ export function detectLaunchConfigurationChanges( "serverProperties", "javaHome", "customRepositories", + "coursierMirror", ...additionalRestartKeys, ]; const shouldPromptRestart = promptRestartKeys.some((key) => diff --git a/src/getJavaConfig.ts b/src/getJavaConfig.ts index 647140f..f35524a 100644 --- a/src/getJavaConfig.ts +++ b/src/getJavaConfig.ts @@ -5,6 +5,7 @@ export interface JavaConfig { javaOptions: string[]; javaPath: string; coursierPath: string; + coursierMirrorFilePath: string | undefined; extraEnv: { [k: string]: string | undefined; }; @@ -14,6 +15,7 @@ interface GetJavaConfigOptions { workspaceRoot: string | undefined; javaHome: string; extensionPath: string; + coursierMirrorFilePath: string | undefined; customRepositories: string[] | undefined; } @@ -21,6 +23,7 @@ export function getJavaConfig({ workspaceRoot, javaHome, extensionPath, + coursierMirrorFilePath, customRepositories = [], }: GetJavaConfigOptions): JavaConfig { const javaOptions = getJavaOptions(workspaceRoot); @@ -28,6 +31,7 @@ export function getJavaConfig({ const coursierPath = path.join(extensionPath, "./coursier"); const extraEnv = { COURSIER_REPOSITORIES: customRepositories.join("|"), + COURSIER_MIRRORS: coursierMirrorFilePath, JAVA_HOME: javaHome, }; @@ -35,6 +39,7 @@ export function getJavaConfig({ javaOptions, javaPath, coursierPath, + coursierMirrorFilePath, extraEnv, }; } From ce3e31d71d5deb411c646eb52b62d34638491f9f Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Thu, 24 Feb 2022 19:16:04 +0100 Subject: [PATCH 2/2] Add UserConfiguration object for common properties --- src/checkServerVersion.ts | 7 ++++--- src/detectLaunchConfigurationChanges.ts | 11 +++++----- src/interfaces/ClientCommands.ts | 2 +- src/interfaces/UserConfiguration.ts | 28 +++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 src/interfaces/UserConfiguration.ts diff --git a/src/checkServerVersion.ts b/src/checkServerVersion.ts index c0db262..b6a55a8 100644 --- a/src/checkServerVersion.ts +++ b/src/checkServerVersion.ts @@ -1,6 +1,7 @@ -import { WorkspaceConfiguration } from "./interfaces/WorkspaceConfiguration"; -import { ConfigurationTarget } from "./interfaces/ConfigurationTarget"; import * as semver from "semver"; +import { ConfigurationTarget } from "./interfaces/ConfigurationTarget"; +import { UserConfiguration } from "./interfaces/UserConfiguration"; +import { WorkspaceConfiguration } from "./interfaces/WorkspaceConfiguration"; interface OnOutdatedParams { message: string; @@ -16,7 +17,7 @@ interface UpdateConfigParams { configurationTarget: ConfigurationTarget; } -const configSection = "serverVersion"; +const configSection = UserConfiguration.ServerVersion; interface CheckServerVersionParams { config: WorkspaceConfiguration; diff --git a/src/detectLaunchConfigurationChanges.ts b/src/detectLaunchConfigurationChanges.ts index b29b216..4cd9dce 100644 --- a/src/detectLaunchConfigurationChanges.ts +++ b/src/detectLaunchConfigurationChanges.ts @@ -1,3 +1,4 @@ +import { UserConfiguration } from "./interfaces/UserConfiguration"; import { Workspace } from "./interfaces/Workspace"; interface PromptRestartParams { @@ -13,11 +14,11 @@ export function detectLaunchConfigurationChanges( ): void { workspace.onDidChangeConfiguration((e) => { const promptRestartKeys = [ - "serverVersion", - "serverProperties", - "javaHome", - "customRepositories", - "coursierMirror", + UserConfiguration.ServerVersion, + UserConfiguration.ServerProperties, + UserConfiguration.JavaHome, + UserConfiguration.CustomRepositories, + UserConfiguration.CoursierMirror, ...additionalRestartKeys, ]; const shouldPromptRestart = promptRestartKeys.some((key) => diff --git a/src/interfaces/ClientCommands.ts b/src/interfaces/ClientCommands.ts index 9ef854c..3e73e65 100644 --- a/src/interfaces/ClientCommands.ts +++ b/src/interfaces/ClientCommands.ts @@ -2,7 +2,7 @@ * These are all of the client commands that Metals supports. Note that not support * may vary based on the `InitializationSettings` the client sets. * - * - https://scalameta.org/metals/docs/editors/new-editor.html#metals-client-commands + * - https://scalameta.org/metals/docs/integrations/new-editor#metals-client-commands */ export const ClientCommands = { /** diff --git a/src/interfaces/UserConfiguration.ts b/src/interfaces/UserConfiguration.ts new file mode 100644 index 0000000..72c1b41 --- /dev/null +++ b/src/interfaces/UserConfiguration.ts @@ -0,0 +1,28 @@ +/** + * These are some of the common user configuration options used in Metals and needed for the editors. + * + * - https://scalameta.org/metals/docs/integrations/new-editor#metals-user-configuration + */ +export enum UserConfiguration { + /** + * Metals server version + */ + ServerVersion = "serverVersion", + /** + * Metals server Java properties + */ + ServerProperties = "serverProperties", + /** + * Directory containing the Java binary. + */ + JavaHome = "javaHome", + /** + * Additional repositories that can be used to download dependencies. + * https://get-coursier.io/docs/other-repositories + */ + CustomRepositories = "customRepositories", + /** + * Repository to use instead of maven central for example `https://jcenter.bintray.com` + */ + CoursierMirror = "coursierMirror", +}