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
55 changes: 28 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
language: node_js

node_js:
- '--lts'

os:
- linux
- osx

before_install:
- |
if [ $TRAVIS_OS_NAME == "linux" ]; then
export CXX="g++-4.9" CC="gcc-4.9"
export DISPLAY=':99.0'
/usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
sleep 3
fi
install:
- npm install -g vsce
- npm install -g typescript
- npm install -g gulp
- npm install

script:
- gulp tslint
- vsce package
- npm test
language: node_js

node_js:
- '--lts'

os:
- linux
- osx

before_install:
- |
if [ $TRAVIS_OS_NAME == "linux" ]; then
export CXX="g++-4.9" CC="gcc-4.9"
export DISPLAY=':99.0'
/usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
sleep 3
fi

install:
- npm install -g vsce
- npm install -g typescript
- npm install -g gulp
- npm install

script:
- gulp tslint
- vsce package
- npm test
12 changes: 12 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

import * as vscode from "vscode";
import * as utility from "./utility";

export const VSCODE_STARTDEBUG = "vscode.startDebug";

Expand Down Expand Up @@ -31,5 +32,16 @@ export const JAVA_CHECK_PROJECT_SETTINGS = "vscode.java.checkProjectSettings";

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);
}

export function executeJavaExtensionCommand(commandName: string, ...rest) {
if (!utility.isJavaExtEnabled()) {
throw new utility.JavaExtensionNotActivatedError(`Cannot execute command ${commandName}, VS Code Java Extension is not enabled.`);
}
return vscode.commands.executeCommand(commandName, ...rest);
}
41 changes: 27 additions & 14 deletions src/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,20 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration

private provideDebugConfigurationsAsync(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken) {
return vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, (p) => {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
p.report({ message: "Auto generating configuration..." });
lsPlugin.resolveMainClass(folder ? folder.uri : undefined).then((res: lsPlugin.IMainClassOption[]) => {
const defaultLaunchConfig = {
type: "java",
name: "Debug (Launch) - Current File",
request: "launch",
// tslint:disable-next-line
mainClass: "${file}",
};
try {
const mainClasses = await lsPlugin.resolveMainClass(folder ? folder.uri : undefined);
let cache;
cache = {};
const defaultLaunchConfig = {
type: "java",
name: "Debug (Launch) - Current File",
request: "launch",
// tslint:disable-next-line
mainClass: "${file}",
};
const launchConfigs = res.map((item) => {
const launchConfigs = mainClasses.map((item) => {
return {
...defaultLaunchConfig,
name: this.constructLaunchConfigName(item.mainClass, item.projectName, cache),
Expand All @@ -80,10 +81,13 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
};
});
resolve([defaultLaunchConfig, ...launchConfigs]);
}, (ex) => {
} catch (ex) {
if (ex instanceof utility.JavaExtensionNotActivatedError) {
utility.guideToInstallJavaExtension();
}
p.report({ message: `failed to generate configuration. ${ex}` });
reject(ex);
});
resolve(defaultLaunchConfig);
}
});
});
}
Expand Down Expand Up @@ -160,8 +164,13 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration

if (needsBuildWorkspace()) {
try {
const buildResult = await vscode.commands.executeCommand(commands.JAVA_BUILD_WORKSPACE, false);
const buildResult = await commands.executeJavaExtensionCommand(commands.JAVA_BUILD_WORKSPACE, false);
} catch (err) {
if (err instanceof utility.JavaExtensionNotActivatedError) {
utility.guideToInstallJavaExtension();
return undefined;
}

const ans = await utility.showErrorMessageWithTroubleshooting({
message: "Build failed, do you want to continue?",
type: Type.USAGEERROR,
Expand Down Expand Up @@ -238,6 +247,10 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
throw new Error("Failed to start debug server.");
}
} catch (ex) {
if (ex instanceof utility.JavaExtensionNotActivatedError) {
utility.guideToInstallJavaExtension();
return undefined;
}
if (ex instanceof utility.UserError) {
utility.showErrorMessageWithTroubleshooting(ex.context);
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 @@ -61,7 +61,7 @@ function initializeExtension(operationId: string, context: vscode.ExtensionConte
await autobuildConfig.update("enabled", true);
// Force an incremental build to avoid auto build is not finishing during HCR.
try {
await vscode.commands.executeCommand(commands.JAVA_BUILD_WORKSPACE, false)
await commands.executeJavaExtensionCommand(commands.JAVA_BUILD_WORKSPACE, false)
} catch (err) {
// do nothing.
}
Expand Down
41 changes: 40 additions & 1 deletion src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@
// Licensed under the MIT license.

import * as vscode from "vscode";
import { setUserError } from "vscode-extension-telemetry-wrapper";
import { logger, Type } from "./logger";

const TROUBLESHOOTING_LINK = "https://github.com/Microsoft/vscode-java-debug/blob/master/Troubleshooting.md";
const LEARN_MORE = "Learn More";
const JAVA_EXTENSION_ID = "redhat.java";

export class UserError extends Error {
public context: ITroubleshootingMessage;

constructor(context: ITroubleshootingMessage) {
super(context.message);
this.context = context;
setUserError(this);
}
}

export class JavaExtensionNotActivatedError extends Error {
constructor(message) {
super(message);
setUserError(this);
}
}

Expand Down Expand Up @@ -85,6 +95,27 @@ function handleTroubleshooting(choice: string, message: string, anchor: string):
return choice;
}

export async function guideToInstallJavaExtension() {
const MESSAGE = "Language Support for Java is required. Please install and enable it.";
const INSTALL = "Install";
const choice = await vscode.window.showWarningMessage(MESSAGE, INSTALL);
if (choice === INSTALL) {
await installJavaExtension();
}
}

async function installJavaExtension() {
await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification }, async (p) => {
p.report({ message: "Installing Language Support for Java ..." });
await vscode.commands.executeCommand("workbench.extensions.installExtension", JAVA_EXTENSION_ID);
});
const RELOAD = "Reload Window";
const choice = await vscode.window.showInformationMessage("Please reload window to activate Language Support for Java.", RELOAD);
if (choice === RELOAD) {
await vscode.commands.executeCommand("workbench.action.reloadWindow");
}
}

export function formatErrorProperties(ex: any): IProperties {
const exception = (ex && ex.data && ex.data.cause)
|| { stackTrace: (ex && ex.stack), detailMessage: String((ex && ex.message) || ex || "Unknown exception") };
Expand All @@ -106,7 +137,10 @@ export function formatErrorProperties(ex: any): IProperties {
}

export async function getJavaHome(): Promise<string> {
const extension = vscode.extensions.getExtension("redhat.java");
const extension = vscode.extensions.getExtension(JAVA_EXTENSION_ID);
if (!extension) {
throw new JavaExtensionNotActivatedError("VS Code Java Extension is not enabled.");
}
try {
const extensionApi = await extension.activate();
if (extensionApi && extensionApi.javaRequirement) {
Expand All @@ -117,3 +151,8 @@ export async function getJavaHome(): Promise<string> {

return "";
}

export function isJavaExtEnabled() {
const javaExt = vscode.extensions.getExtension(JAVA_EXTENSION_ID);
return !!javaExt;
}