feature: Try and resolve java home if it's a symlink - #479
Conversation
| if (fs.existsSync(configuredJavaHome)) { | ||
| const stat = fs.lstatSync(configuredJavaHome); | ||
| const realpath = fs.realpathSync(configuredJavaHome); | ||
| if (stat.isSymbolicLink() && realpath.endsWith(`bin${path.sep}java`)) { | ||
| const javaHome = path.dirname(path.dirname(realpath)); | ||
| return TE.right(javaHome); | ||
| } | ||
| } |
There was a problem hiding this comment.
Is it more readable? I find flat ifs and early return more readable than nesting it
const cleanJavaHome = configuredJavaHome?.trim();
if (cleanJavaHome == null) return TE.left({});
if (cleanJavaHome.length === 0) return TE.left({});
if (fs.existsSync(cleanJavaHome)) {
const stat = fs.lstatSync(cleanJavaHome);
const realpath = fs.realpathSync(cleanJavaHome);
if (stat.isSymbolicLink() && realpath.endsWith(`bin${path.sep}java`)) {
const javaHome = path.dirname(path.dirname(realpath));
return TE.right(javaHome);
}
}
return TE.right(cleanJavaHome);
dos65
left a comment
There was a problem hiding this comment.
I took a look over conversations about that and I can't that I was convinced that it should work in this way 😸
What about adding an additional fallback function that tries to infer java Home from java in $PATH. Then it should work in the same way but without a setting.
I mean here -
metals-languageclient/src/getJavaHome.ts
Line 31 in 3f88cf1
Maybe it's finally time for metals to download own Java? Problems with java home seem to be never ending 😢 |
tanishiking
left a comment
There was a problem hiding this comment.
What about adding an additional fallback function that tries to infer java Home from java in $PATH. Then it should work in the same way but without a setting.
I agree with @dos65
Adding another inference rule based on java on $PATH (the rule should be the same with this PR, resolve symlink and grandparent dir should be its java home).
This inference rule should have the lowest priority, next to the locate-java-home.
By the way, maybe we should replace locate-java-home with find-java-home looks like it has the inference rule for the grandparent dir of javac).
Och, I didn't think this would be controvertial 😅
Looks like it does the same thing as this PR, so might be good to use that instead. Let's check it after the next release. |
Resolves scalameta/metals-vscode#1094