Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ export function getJavaEncoding(): string {
return javaEncoding;
}

function resolveRuntimePathByName(nameOrPath: string | undefined): string | undefined {
if (!nameOrPath) {
return nameOrPath;
}
const runtimes = workspace.getConfiguration('java').get<Array<{ name: string; path: string }>>('configuration.runtimes');
if (Array.isArray(runtimes)) {
const matched = runtimes.find(r => r && r.name === nameOrPath);
if (matched && matched.path) {
return matched.path;
}
}
return nameOrPath;
}

export async function checkJavaPreferences(context: ExtensionContext): Promise<{javaHome?: string; preference: string}> {
const allow = 'Allow';
const disallow = 'Disallow';
Expand All @@ -173,6 +187,7 @@ export async function checkJavaPreferences(context: ExtensionContext): Promise<{
if (isVerified) {
javaHome = getJavaConfiguration().get('jdt.ls.java.home');
}
javaHome = resolveRuntimePathByName(javaHome);
const key = getKey(IS_WORKSPACE_JLS_JDK_ALLOWED, context.storagePath, javaHome);
const globalState = context.globalState;
if (!isVerified) {
Expand All @@ -189,7 +204,7 @@ export async function checkJavaPreferences(context: ExtensionContext): Promise<{
isVerified = globalState.get(key);
}
if (!isVerified) { // java.jdt.ls.java.home from workspace settings is disallowed.
javaHome = workspace.getConfiguration().inspect<string>('java.jdt.ls.java.home').globalValue;
javaHome = resolveRuntimePathByName(workspace.getConfiguration().inspect<string>('java.jdt.ls.java.home').globalValue);
}
}

Expand Down
Loading