Skip to content

Commit

Permalink
If the user specifies an unusable Java, let them know that the binary…
Browse files Browse the repository at this point in the history
… 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).
  • Loading branch information
datho7561 committed Jan 13, 2025
1 parent 53f04ba commit 18766de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import * as fs from 'fs-extra';
import { ExtensionContext, Uri, commands, extensions, languages } from "vscode";
import { ConfigurationTarget, ExtensionContext, Uri, commands, extensions, languages, window, workspace } from "vscode";
import { Executable, LanguageClient } from 'vscode-languageclient/node';
import { XMLExtensionApi } from './api/xmlExtensionApi';
import { getXmlExtensionApiImplementation } from './api/xmlExtensionApiImplementation';
Expand Down Expand Up @@ -46,6 +46,17 @@ export async function activate(context: ExtensionContext): Promise<XMLExtensionA
try {
requirementsData = await requirements.resolveRequirements(context);
} catch (error) {
if (!workspace.getConfiguration('xml').get('server.preferBinary') && error.message !== requirements.NO_JAVA_FOUND) {
const USE_BINARY = 'Always use binary server';
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) //
.then(button => {
if (button === error.label) {
commands.executeCommand('vscode.open', error.openUrl);
} else if (button === USE_BINARY) {
workspace.getConfiguration('xml').update('server.preferBinary', true, ConfigurationTarget.Global);
}
});
}
requirementsData = {} as requirements.RequirementsData;
}

Expand Down
8 changes: 5 additions & 3 deletions src/server/requirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import * as expandHomeDir from 'expand-home-dir';
const isWindows = process.platform.indexOf('win') === 0;
const JAVA_FILENAME = 'java' + (isWindows ? '.exe' : '');

export const NO_JAVA_FOUND = "Java runtime could not be located.";

export interface RequirementsData {
java_home: string;
java_version: number;
Expand Down Expand Up @@ -50,7 +52,7 @@ async function checkJavaRuntime(context: ExtensionContext): Promise<string> {
if (javaHome) {
javaHome = expandHomeDir(javaHome);
if (!pathExists.sync(javaHome)) {
throw openJDKDownload(source + ' points to a missing folder');
throw openJDKDownload(source + ' points to a missing folder.');
} else if (!pathExists.sync(path.resolve(javaHome, 'bin', JAVA_FILENAME))) {
throw openJDKDownload(source + ' does not point to a Java runtime.');
}
Expand All @@ -62,7 +64,7 @@ async function checkJavaRuntime(context: ExtensionContext): Promise<string> {
sortJdksBySource(javaRuntimes);
javaHome = javaRuntimes[0].homedir;
} else {
throw openJDKDownload("Java runtime could not be located. Please download and install Java or use the binary server.");
throw openJDKDownload(NO_JAVA_FOUND);
}
return javaHome;
}
Expand Down Expand Up @@ -153,7 +155,7 @@ function checkJavaVersion(java_home: string): Promise<number> {
cp.execFile(java_home + '/bin/java', ['-version'], {}, (error, stdout, stderr) => {
const javaVersion = parseMajorVersion(stderr);
if (javaVersion < 11) {
reject(openJDKDownload('Java 11 or more recent is required to run. Please download and install a recent Java runtime.'));
reject(openJDKDownload('The Java version specified is older than Java 11.'));
}
else {
resolve(javaVersion);
Expand Down

0 comments on commit 18766de

Please sign in to comment.