Skip to content

Commit ae23fcb

Browse files
"Learn More" link jumps to the associated troubleshooting paragraph directly (microsoft#371)
* Learn More link to the corresponding troubleshooting paragraph directly Signed-off-by: Jinbo Wang <jinbwan@microsoft.com> * Update LS troubleshooting anchor point * make tslint happy * Give a meaningful sample message instead of xyz * Refactor IMessage interface
1 parent a51187a commit ae23fcb

5 files changed

Lines changed: 56 additions & 17 deletions

File tree

‎Troubleshooting.md‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ The debugger works with [Language Support for Java(TM) by Red Hat](https://marke
1818

1919
## Failed to resolve classpath:
2020
### Reason:
21+
Below are the common failure reasons.
22+
- Main class 'C:\demo\org\microsoft\app\Main.java' doesn't exist in the workspace.
23+
- Main class 'org.microsoft.app.Main' isn't unique in the workspace.
24+
- The project 'demo' is not a valid java project.
25+
2126
In launch mode, the debugger resolves the classpaths automatically based on the given `mainClass` and `projectName`. It looks for the class specified by `mainClass` as the entry point for launching an application. If there are multiple classes with the same name in the current workspace, the debugger uses the one inside the project specified by `projectName`.
2227

2328
### Try:
@@ -65,7 +70,7 @@ You configure the incorrect main class name in `mainClass` of *launch.json*.
6570

6671
### Try:
6772
1. Check whether the class name specified in `mainClass` exists and is in the right form.
68-
2. If the problem persists, it's probably because the language server doesn't load your project correctly. Please reference *"Java Language Support extension fails to start"* paragraph for more troubleshooting info.
73+
2. If the problem persists, it's probably because the language server doesn't load your project correctly. Please reference the [language server troubleshooting](#try) paragraph for more troubleshooting info.
6974

7075
## The DEBUG CONSOLE throws ClassNotFoundException
7176
### Reason:
@@ -74,12 +79,20 @@ This error indicates your application attempts to reference some classes which a
7479
### Try:
7580
1. Check whether you configure the required libraries in the dependency settings file (e.g. *pom.xml*).
7681
2. Run VS Code command *"Java: Force Java compilation"* to force the language server to rebuild the current project.
77-
3. If the problem persists, it's probably because the language server doesn't load your project correctly. Please reference *"Java Language Support extension fails to start"* paragraph for more troubleshooting info.
82+
3. If the problem persists, it's probably because the language server doesn't load your project correctly. Please reference the [language server troubleshooting](#try) paragraph for more troubleshooting info.
7883

7984
## Cannot find a class with the main method
8085
### Reason:
8186
When the `mainClass` is unconfigured in the *launch.json*, the debugger will resolve a class with main method automatically. This error indicates the debugger doesn't find any main class in the whole workspace.
8287

8388
### Try:
8489
1. Check at least one main class exists in your workspace.
85-
2. If no main class exists, please create a main class first. Otherwise, it's probably because the language server fails to start. Please reference *"Java Language Support extension fails to start"* paragraph for more troubleshooting info.
90+
2. If no main class exists, please create a main class first. Otherwise, it's probably because the language server fails to start. Please reference the [language server troubleshooting](#try) paragraph for more troubleshooting info.
91+
92+
## Build failed, do you want to continue?
93+
### Reason:
94+
The error indicates your workspace has build errors. There are two kinds of build errors. One is compilation error for source code, the other is project error.
95+
96+
### Try:
97+
1. Open VS Code PROBLEMS View, and fix the errors there.
98+
2. If no errors are found in the PROBLEMS View, reference the [language server troubleshooting](#try) paragraph to update project configuration, and clean workspace cache.

‎src/anchor.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
export const LS_FAILS_TO_START = "java-language-support-extension-fails-to-start";
3+
export const FAILED_TO_RESOLVE_CLASSPATH = "failed-to-resolve-classpath";
4+
export const REQUEST_TYPE_NOT_SUPPORTED = "request-type-xyz-is-not-supported-only-launch-and-attach-are-supported";
5+
export const FAILED_TO_COMPLETE_HCR = "failed-to-complete-hot-code-replace";
6+
export const ATTACH_CONFIG_ERROR = "please-specify-the-host-name-and-the-port-of-the-remote-debuggee-in-the-launchjson";
7+
export const EVALUATE_ON_RUNNING_THREAD = "failed-to-evaluate-reason-cannot-evaluate-because-the-thread-is-resumed";
8+
export const DEBUGCONSOLE_MAIN_CLASS_NOT_FOUND = "the-debug-console-throws-error-could-not-find-or-load-main-class-xyz";
9+
export const DEBUGCONSOLE_CLASS_NOT_FOUND_EXCEPTION = "the-debug-console-throws-classnotfoundexception";
10+
export const CANNOT_FIND_MAIN_CLASS = "cannot-find-a-class-with-the-main-method";
11+
export const BUILD_FAILED = "build-failed-do-you-want-to-continue";

‎src/configurationProvider.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the MIT license.
33

44
import * as vscode from "vscode";
5+
6+
import * as anchor from "./anchor";
57
import * as commands from "./commands";
68
import { logger, Type } from "./logger";
79
import * as utility from "./utility";
@@ -113,7 +115,11 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
113115
try {
114116
const buildResult = await vscode.commands.executeCommand(commands.JAVA_BUILD_WORKSPACE, false);
115117
} catch (err) {
116-
const ans = await vscode.window.showErrorMessage("Build failed, do you want to continue?", "Proceed", "Abort");
118+
const ans = await utility.showErrorMessageWithTroubleshooting({
119+
message: "Build failed, do you want to continue?",
120+
type: Type.USAGEERROR,
121+
anchor: anchor.BUILD_FAILED,
122+
}, "Proceed", "Abort");
117123
if (ans !== "Proceed") {
118124
return undefined;
119125
}
@@ -144,13 +150,15 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
144150
utility.showErrorMessageWithTroubleshooting({
145151
message: "Please specify the host name and the port of the remote debuggee in the launch.json.",
146152
type: Type.USAGEERROR,
153+
anchor: anchor.ATTACH_CONFIG_ERROR,
147154
});
148155
return undefined;
149156
}
150157
} else {
151158
const ans = await utility.showErrorMessageWithTroubleshooting({
152159
message: `Request type "${config.request}" is not supported. Only "launch" and "attach" are supported.`,
153160
type: Type.USAGEERROR,
161+
anchor: anchor.REQUEST_TYPE_NOT_SUPPORTED,
154162
}, "Open launch.json");
155163
if (ans === "Open launch.json") {
156164
await vscode.commands.executeCommand(commands.VSCODE_ADD_DEBUGCONFIGURATION);
@@ -201,6 +209,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
201209
utility.showErrorMessageWithTroubleshooting({
202210
message: "Cannot find a class with the main method.",
203211
type: Type.USAGEERROR,
212+
anchor: anchor.CANNOT_FIND_MAIN_CLASS,
204213
});
205214
return undefined;
206215
}

‎src/hotCodeReplace.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import * as vscode from "vscode";
55

6+
import * as anchor from "./anchor";
67
import { HCR_EVENT, JAVA_LANGID } from "./constants";
78
import * as utility from "./utility";
89

@@ -43,6 +44,7 @@ export function handleHotCodeReplaceCustomEvent(hcrEvent) {
4344
if (!suppressedReasons.has(hcrEvent.body.message)) {
4445
utility.showWarningMessageWithTroubleshooting({
4546
message: `Hot code replace failed - ${hcrEvent.body.message}. Would you like to restart the debug session?`,
47+
anchor: anchor.FAILED_TO_COMPLETE_HCR,
4648
}, YES_BUTTON, NO_BUTTON, NEVER_BUTTON).then((res) => {
4749
if (res === NEVER_BUTTON) {
4850
suppressedReasons.add(hcrEvent.body.message);

‎src/utility.ts‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ import { logger, Type } from "./logger";
88
const TROUBLESHOOTING_LINK = "https://github.com/Microsoft/vscode-java-debug/blob/master/Troubleshooting.md";
99
const LEARN_MORE = "Learn More";
1010

11-
interface IMessage {
11+
interface ILoggingMessage {
1212
message: string;
1313
type?: Type;
1414
details?: { [key: string]: string; };
1515
}
1616

17-
function logMessage(message: IMessage): void {
17+
interface ITroubleshootingMessage extends ILoggingMessage {
18+
anchor?: string;
19+
}
20+
21+
function logMessage(message: ILoggingMessage): void {
1822
if (!message.type) {
1923
return;
2024
}
@@ -26,43 +30,43 @@ function logMessage(message: IMessage): void {
2630
}
2731
}
2832

29-
export async function showInformationMessage(message: IMessage, ...items: string[]): Promise<string | undefined> {
33+
export async function showInformationMessage(message: ILoggingMessage, ...items: string[]): Promise<string | undefined> {
3034
logMessage(message);
3135
return await vscode.window.showInformationMessage(message.message, ...items);
3236
}
3337

34-
export async function showWarningMessage(message: IMessage, ...items: string[]): Promise<string | undefined> {
38+
export async function showWarningMessage(message: ILoggingMessage, ...items: string[]): Promise<string | undefined> {
3539
logMessage(message);
3640
return await vscode.window.showWarningMessage(message.message, ...items);
3741
}
3842

39-
export async function showErrorMessage(message: IMessage, ...items: string[]): Promise<string | undefined> {
43+
export async function showErrorMessage(message: ILoggingMessage, ...items: string[]): Promise<string | undefined> {
4044
logMessage(message);
4145
return await vscode.window.showErrorMessage(message.message, ...items);
4246
}
4347

44-
export async function showInformationMessageWithTroubleshooting(message: IMessage, ...items: string[]): Promise<string | undefined> {
48+
export async function showInformationMessageWithTroubleshooting(message: ITroubleshootingMessage, ...items: string[]): Promise<string | undefined> {
4549
const choice = await showInformationMessage(message, ...items, LEARN_MORE);
46-
return handleTroubleshooting(choice, message.message);
50+
return handleTroubleshooting(choice, message.message, message.anchor);
4751
}
4852

49-
export async function showWarningMessageWithTroubleshooting(message: IMessage, ...items: string[]): Promise<string | undefined> {
53+
export async function showWarningMessageWithTroubleshooting(message: ITroubleshootingMessage, ...items: string[]): Promise<string | undefined> {
5054
const choice = await showWarningMessage(message, ...items, LEARN_MORE);
51-
return handleTroubleshooting(choice, message.message);
55+
return handleTroubleshooting(choice, message.message, message.anchor);
5256
}
5357

54-
export async function showErrorMessageWithTroubleshooting(message: IMessage, ...items: string[]): Promise<string | undefined> {
58+
export async function showErrorMessageWithTroubleshooting(message: ITroubleshootingMessage, ...items: string[]): Promise<string | undefined> {
5559
const choice = await showErrorMessage(message, ...items, LEARN_MORE);
56-
return handleTroubleshooting(choice, message.message);
60+
return handleTroubleshooting(choice, message.message, message.anchor);
5761
}
5862

5963
function openLink(url: string): void {
6064
opn(url);
6165
}
6266

63-
function handleTroubleshooting(choice: string, message: string): string | undefined {
67+
function handleTroubleshooting(choice: string, message: string, anchor: string): string | undefined {
6468
if (choice === LEARN_MORE) {
65-
openLink(TROUBLESHOOTING_LINK);
69+
openLink(anchor ? `${TROUBLESHOOTING_LINK}#${anchor}` : TROUBLESHOOTING_LINK);
6670
logger.log(Type.USAGEDATA, {
6771
troubleshooting: "yes",
6872
troubleshootingMessage: message,

0 commit comments

Comments
 (0)