Skip to content

Commit 18766de

Browse files
committed
If the user specifies an unusable Java, let them know that the binary will be used
Provides a popup that explains what happened and has buttons to: - Set "prefer binary" to true so they don't see the popup again - Provide the download link for Java so they can update Java if necessary This popup doesn't appear if the user doesn't have Java installed, and this popup doesn't block the language server startup (i.e. we go ahead and launch the binary server before the user clicks anything on the popup).
1 parent 53f04ba commit 18766de

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/extension.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import * as fs from 'fs-extra';
14-
import { ExtensionContext, Uri, commands, extensions, languages } from "vscode";
14+
import { ConfigurationTarget, ExtensionContext, Uri, commands, extensions, languages, window, workspace } from "vscode";
1515
import { Executable, LanguageClient } from 'vscode-languageclient/node';
1616
import { XMLExtensionApi } from './api/xmlExtensionApi';
1717
import { getXmlExtensionApiImplementation } from './api/xmlExtensionApiImplementation';
@@ -46,6 +46,17 @@ export async function activate(context: ExtensionContext): Promise<XMLExtensionA
4646
try {
4747
requirementsData = await requirements.resolveRequirements(context);
4848
} catch (error) {
49+
if (!workspace.getConfiguration('xml').get('server.preferBinary') && error.message !== requirements.NO_JAVA_FOUND) {
50+
const USE_BINARY = 'Always use binary server';
51+
void window.showWarningMessage(error.message + ' The binary server will be used instead. Please consider downloading and installing a recent Java runtime, or configuring vscode-xml to always use the binary server.', USE_BINARY, error.label) //
52+
.then(button => {
53+
if (button === error.label) {
54+
commands.executeCommand('vscode.open', error.openUrl);
55+
} else if (button === USE_BINARY) {
56+
workspace.getConfiguration('xml').update('server.preferBinary', true, ConfigurationTarget.Global);
57+
}
58+
});
59+
}
4960
requirementsData = {} as requirements.RequirementsData;
5061
}
5162

src/server/requirements.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import * as expandHomeDir from 'expand-home-dir';
1111
const isWindows = process.platform.indexOf('win') === 0;
1212
const JAVA_FILENAME = 'java' + (isWindows ? '.exe' : '');
1313

14+
export const NO_JAVA_FOUND = "Java runtime could not be located.";
15+
1416
export interface RequirementsData {
1517
java_home: string;
1618
java_version: number;
@@ -50,7 +52,7 @@ async function checkJavaRuntime(context: ExtensionContext): Promise<string> {
5052
if (javaHome) {
5153
javaHome = expandHomeDir(javaHome);
5254
if (!pathExists.sync(javaHome)) {
53-
throw openJDKDownload(source + ' points to a missing folder');
55+
throw openJDKDownload(source + ' points to a missing folder.');
5456
} else if (!pathExists.sync(path.resolve(javaHome, 'bin', JAVA_FILENAME))) {
5557
throw openJDKDownload(source + ' does not point to a Java runtime.');
5658
}
@@ -62,7 +64,7 @@ async function checkJavaRuntime(context: ExtensionContext): Promise<string> {
6264
sortJdksBySource(javaRuntimes);
6365
javaHome = javaRuntimes[0].homedir;
6466
} else {
65-
throw openJDKDownload("Java runtime could not be located. Please download and install Java or use the binary server.");
67+
throw openJDKDownload(NO_JAVA_FOUND);
6668
}
6769
return javaHome;
6870
}
@@ -153,7 +155,7 @@ function checkJavaVersion(java_home: string): Promise<number> {
153155
cp.execFile(java_home + '/bin/java', ['-version'], {}, (error, stdout, stderr) => {
154156
const javaVersion = parseMajorVersion(stderr);
155157
if (javaVersion < 11) {
156-
reject(openJDKDownload('Java 11 or more recent is required to run. Please download and install a recent Java runtime.'));
158+
reject(openJDKDownload('The Java version specified is older than Java 11.'));
157159
}
158160
else {
159161
resolve(javaVersion);

0 commit comments

Comments
 (0)