Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function buildWorkspace(): Promise<boolean> {
}

async function handleBuildFailure(operationId: string, err: any): Promise<boolean> {
if (err instanceof utility.JavaExtensionNotActivatedError) {
if (err instanceof utility.JavaExtensionNotEnabledError) {
utility.guideToInstallJavaExtension();
return false;
}
Expand Down
18 changes: 9 additions & 9 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ export const JAVA_IS_ON_CLASSPATH = "vscode.java.isOnClasspath";
export const JAVA_RESOLVE_JAVAEXECUTABLE = "vscode.java.resolveJavaExecutable";

export function executeJavaLanguageServerCommand(...rest) {
// TODO: need to handle error and trace telemetry
if (!utility.isJavaExtEnabled()) {
throw new utility.JavaExtensionNotActivatedError(
`Cannot execute command ${JAVA_EXECUTE_WORKSPACE_COMMAND}, VS Code Java Extension is not enabled.`);
}
return vscode.commands.executeCommand(JAVA_EXECUTE_WORKSPACE_COMMAND, ...rest);
return executeJavaExtensionCommand(JAVA_EXECUTE_WORKSPACE_COMMAND, ...rest);
}

export function executeJavaExtensionCommand(commandName: string, ...rest) {
if (!utility.isJavaExtEnabled()) {
throw new utility.JavaExtensionNotActivatedError(`Cannot execute command ${commandName}, VS Code Java Extension is not enabled.`);
export async function executeJavaExtensionCommand(commandName: string, ...rest) {
// TODO: need to handle error and trace telemetry
const javaExtension = utility.getJavaExtension();
if (!javaExtension) {
throw new utility.JavaExtensionNotEnabledError(`Cannot execute command ${commandName}, VS Code Java Extension is not enabled.`);
}
if (!javaExtension.isActive) {
await javaExtension.activate();
}
return vscode.commands.executeCommand(commandName, ...rest);
}
4 changes: 2 additions & 2 deletions src/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
});
resolve([defaultLaunchConfig, ...launchConfigs]);
} catch (ex) {
if (ex instanceof utility.JavaExtensionNotActivatedError) {
if (ex instanceof utility.JavaExtensionNotEnabledError) {
utility.guideToInstallJavaExtension();
}
p.report({ message: `failed to generate configuration. ${ex}` });
Expand Down Expand Up @@ -232,7 +232,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
throw new Error("Failed to start debug server.");
}
} catch (ex) {
if (ex instanceof utility.JavaExtensionNotActivatedError) {
if (ex instanceof utility.JavaExtensionNotEnabledError) {
utility.guideToInstallJavaExtension();
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ async function runJavaFile(uri: vscode.Uri, noDebug: boolean) {
// Wait for Java Language Support extension being activated.
await utility.getJavaExtensionAPI();
} catch (ex) {
if (ex instanceof utility.JavaExtensionNotActivatedError) {
if (ex instanceof utility.JavaExtensionNotEnabledError) {
utility.guideToInstallJavaExtension();
return;
}
Expand Down
8 changes: 6 additions & 2 deletions src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class UserError extends Error {
}
}

export class JavaExtensionNotActivatedError extends Error {
export class JavaExtensionNotEnabledError extends Error {
constructor(message) {
super(message);
setUserError(this);
Expand Down Expand Up @@ -154,12 +154,16 @@ export async function getJavaHome(): Promise<string> {
export function getJavaExtensionAPI(): Thenable<any> {
const extension = vscode.extensions.getExtension(JAVA_EXTENSION_ID);
if (!extension) {
throw new JavaExtensionNotActivatedError("VS Code Java Extension is not enabled.");
throw new JavaExtensionNotEnabledError("VS Code Java Extension is not enabled.");
}

return extension.activate();
}

export function getJavaExtension(): vscode.Extension<any> {
return vscode.extensions.getExtension(JAVA_EXTENSION_ID);
}

export function isJavaExtEnabled(): boolean {
const javaExt = vscode.extensions.getExtension(JAVA_EXTENSION_ID);
return !!javaExt;
Expand Down