From a760bf201b856d30634c7fda54650f35fa2951aa Mon Sep 17 00:00:00 2001 From: tgodzik Date: Mon, 20 May 2024 21:49:32 +0200 Subject: [PATCH 1/2] bugfix: Add encoding to fix issue with non ASCII letter I will also need to check if that works on windows, but that can be easily checked on Windows --- packages/metals-languageclient/src/fetchMetals.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/metals-languageclient/src/fetchMetals.ts b/packages/metals-languageclient/src/fetchMetals.ts index 3af58932..f2823e86 100644 --- a/packages/metals-languageclient/src/fetchMetals.ts +++ b/packages/metals-languageclient/src/fetchMetals.ts @@ -60,7 +60,10 @@ export async function fetchMetals({ return { promise: spawn(javaPath, jarArgs) }; } else { return { - promise: spawn(coursier, coursierArgs), + promise: spawn( + coursier, + ["-J-Dfile.encoding=UTF-8"].concat(coursierArgs) + ), }; } } From 98df5859b902cb45550880efd671458c90a577c8 Mon Sep 17 00:00:00 2001 From: tgodzik Date: Thu, 23 May 2024 12:48:54 +0200 Subject: [PATCH 2/2] improvement: Restore adding properties and env when fetching metals --- .../metals-languageclient/src/fetchMetals.ts | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/packages/metals-languageclient/src/fetchMetals.ts b/packages/metals-languageclient/src/fetchMetals.ts index f2823e86..bee1ee98 100644 --- a/packages/metals-languageclient/src/fetchMetals.ts +++ b/packages/metals-languageclient/src/fetchMetals.ts @@ -21,7 +21,7 @@ interface PackedChildPromise { export async function fetchMetals({ serverVersion, serverProperties, - javaConfig: { coursier, javaPath }, + javaConfig: { javaOptions, coursier, extraEnv, javaPath }, outputChannel, }: FetchMetalsOptions): Promise { const serverDependency = calcServerDependency(serverVersion); @@ -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 = []; + + // 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), }; } }