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
33 changes: 31 additions & 2 deletions src/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as os from "os";
import * as path from "path";
import * as vscode from "vscode";

import { instrumentOperation, sendInfo } from "vscode-extension-telemetry-wrapper";
import { instrumentOperation, sendError, sendInfo, setUserError } from "vscode-extension-telemetry-wrapper";
import * as anchor from "./anchor";
import { buildWorkspace } from "./build";
import { populateStepFilters, substituteFilterVariables } from "./classFilter";
Expand Down Expand Up @@ -539,16 +539,43 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
}
}

private getValidationErrorMessage(error: lsPlugin.IValidationResult): string {
switch (error.kind) {
case lsPlugin.CONFIGERROR_INVALID_CLASS_NAME:
return "ConfigError: mainClass was configured with an invalid class name.";
case lsPlugin.CONFIGERROR_MAIN_CLASS_NOT_EXIST:
return "ConfigError: mainClass does not exist.";
case lsPlugin.CONFIGERROR_MAIN_CLASS_NOT_UNIQUE:
return "ConfigError: mainClass is not unique in the workspace";
case lsPlugin.CONFIGERROR_INVALID_JAVA_PROJECT:
return "ConfigError: could not find a Java project with the configured projectName.";
}

return "ConfigError: Invalid mainClass/projectName configs.";
}

private async fixMainClass(folder: vscode.Uri | undefined, config: vscode.DebugConfiguration,
validationResponse: lsPlugin.ILaunchValidationResponse, progressReporter: IProgressReporter):
Promise<lsPlugin.IMainClassOption | undefined> {
const errors: string[] = [];
if (!validationResponse.mainClass.isValid) {
errors.push(String(validationResponse.mainClass.message));
const errorLog: Error = {
name: "error",
message: this.getValidationErrorMessage(validationResponse.mainClass),
};
setUserError(errorLog);
sendError(errorLog);
}

if (!validationResponse.projectName.isValid) {
errors.push(String(validationResponse.projectName.message));
const errorLog: Error = {
name: "error",
message: this.getValidationErrorMessage(validationResponse.projectName),
};
setUserError(errorLog);
sendError(errorLog);
}

if (validationResponse.proposals && validationResponse.proposals.length) {
Expand All @@ -557,14 +584,15 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
message: errors.join(os.EOL),
type: Type.USAGEERROR,
anchor: anchor.FAILED_TO_RESOLVE_CLASSPATH,
bypassLog: true, // Avoid logging the raw user input in the logger for privacy.
}, "Fix");
if (answer === "Fix") {
const selectedFix = await mainClassPicker.showQuickPick(validationResponse.proposals,
"Please select main class<project name>.", false);
if (selectedFix) {
sendInfo("", {
fix: "yes",
fixMessage: errors.join(os.EOL),
fixMessage: "Fix the configs of mainClass and projectName",
});
await this.persistMainClassOption(folder, config, selectedFix);
}
Expand All @@ -579,6 +607,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
message: errors.join(os.EOL),
type: Type.USAGEERROR,
anchor: anchor.FAILED_TO_RESOLVE_CLASSPATH,
bypassLog: true, // Avoid logging the raw user input in the logger for privacy.
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/languageServerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ export interface IMainMethod extends IMainClassOption {
range: vscode.Range;
}

export const CONFIGERROR_INVALID_CLASS_NAME = 1;
export const CONFIGERROR_MAIN_CLASS_NOT_EXIST = 2;
export const CONFIGERROR_MAIN_CLASS_NOT_UNIQUE = 3;
export const CONFIGERROR_INVALID_JAVA_PROJECT = 4;
export interface IValidationResult {
readonly isValid: boolean;
readonly message?: string;
readonly kind?: number;
}

export interface ILaunchValidationResponse {
Expand Down
3 changes: 2 additions & 1 deletion src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ interface ILoggingMessage {
type?: Type;
message: string;
stack?: string;
bypassLog?: boolean;
}

interface ITroubleshootingMessage extends ILoggingMessage {
anchor?: string;
}

function logMessage(message: ILoggingMessage): void {
if (!message.type) {
if (!message.type || message.bypassLog) {
return;
}

Expand Down