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
15 changes: 8 additions & 7 deletions src/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
try {
// See https://github.com/microsoft/vscode-java-debug/issues/778
// Merge the platform specific properties to the global config to simplify the subsequent resolving logic.
this.mergePlatformProperties(folder, config);
this.mergePlatformProperties(config, folder);
return this.resolveAndValidateDebugConfiguration(folder, config);
} catch (ex) {
utility.showErrorMessage({
Expand Down Expand Up @@ -110,7 +110,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
const launchConfigs = mainClasses.map((item) => {
return {
...defaultLaunchConfig,
name: this.constructLaunchConfigName(item.mainClass, item.projectName, cache),
name: this.constructLaunchConfigName(item.mainClass, cache, item.projectName),
mainClass: item.mainClass,
projectName: item.projectName,
};
Expand All @@ -127,7 +127,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
});
}

private mergePlatformProperties(_folder: vscode.WorkspaceFolder, config: vscode.DebugConfiguration) {
private mergePlatformProperties(config: vscode.DebugConfiguration, _folder?: vscode.WorkspaceFolder) {
if (config && platformName && config[platformName]) {
try {
for (const key of Object.keys(config[platformName])) {
Expand All @@ -140,7 +140,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
}
}

private constructLaunchConfigName(mainClass: string, projectName: string, cache: {[key: string]: any}) {
private constructLaunchConfigName(mainClass: string, cache: {[key: string]: any}, projectName?: string) {
const prefix = "Debug (Launch)-";
let name = prefix + mainClass.substr(mainClass.lastIndexOf(".") + 1);
if (projectName !== undefined) {
Expand Down Expand Up @@ -333,7 +333,8 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
return Object.keys(config).filter((key: string) => key !== "noDebug").length === 0;
}

private async resolveLaunchConfig(folder: vscode.Uri | undefined, config: vscode.DebugConfiguration): Promise<lsPlugin.IMainClassOption> {
private async resolveLaunchConfig(folder: vscode.Uri | undefined,
config: vscode.DebugConfiguration): Promise<lsPlugin.IMainClassOption | undefined> {
if (!config.mainClass || this.isFile(config.mainClass)) {
const currentFile = config.mainClass || _.get(vscode.window.activeTextEditor, "document.uri.fsPath");
if (currentFile) {
Expand All @@ -350,7 +351,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
}

const containsExternalClasspaths = !_.isEmpty(config.classPaths) || !_.isEmpty(config.modulePaths);
const validationResponse = await lsPlugin.validateLaunchConfig(folder, config.mainClass, config.projectName, containsExternalClasspaths);
const validationResponse = await lsPlugin.validateLaunchConfig(config.mainClass, config.projectName, containsExternalClasspaths, folder);
if (!validationResponse.mainClass.isValid || !validationResponse.projectName.isValid) {
return this.fixMainClass(folder, config, validationResponse);
}
Expand Down Expand Up @@ -391,7 +392,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
const selectedFix = await mainClassPicker.showQuickPick(validationResponse.proposals,
"Please select main class<project name>.", false);
if (selectedFix) {
sendInfo(null, {
sendInfo("", {
fix: "yes",
fixMessage: errors.join(os.EOL),
});
Expand Down
10 changes: 5 additions & 5 deletions src/debugCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ function debugJavaProgram(mainClass: string, projectName: string, uri: vscode.Ur
return startDebugging(mainClass, projectName, uri, false);
}

async function constructDebugConfig(mainClass: string, projectName: string, workspace: vscode.Uri): Promise<vscode.DebugConfiguration> {
async function constructDebugConfig(mainClass: string, projectName: string, workspace?: vscode.Uri): Promise<vscode.DebugConfiguration> {
const launchConfigurations: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("launch", workspace);
const rawConfigs: vscode.DebugConfiguration[] = launchConfigurations.configurations;

let debugConfig: vscode.DebugConfiguration = _.find(rawConfigs, (config) => {
let debugConfig: vscode.DebugConfiguration | undefined = _.find(rawConfigs, (config) => {
return config.mainClass === mainClass && _.toString(config.projectName) === _.toString(projectName);
});

Expand Down Expand Up @@ -174,7 +174,7 @@ async function constructDebugConfig(mainClass: string, projectName: string, work
return _.cloneDeep(debugConfig);
}

async function launchJsonExists(workspace: vscode.Uri): Promise<boolean> {
async function launchJsonExists(workspace?: vscode.Uri): Promise<boolean> {
if (!workspace) {
return false;
}
Expand All @@ -185,8 +185,8 @@ async function launchJsonExists(workspace: vscode.Uri): Promise<boolean> {
}

export async function startDebugging(mainClass: string, projectName: string, uri: vscode.Uri, noDebug: boolean): Promise<boolean> {
const workspaceFolder: vscode.WorkspaceFolder = vscode.workspace.getWorkspaceFolder(uri);
const workspaceUri: vscode.Uri = workspaceFolder ? workspaceFolder.uri : undefined;
const workspaceFolder: vscode.WorkspaceFolder | undefined = vscode.workspace.getWorkspaceFolder(uri);
const workspaceUri: vscode.Uri | undefined = workspaceFolder ? workspaceFolder.uri : undefined;
const onClasspath = await isOnClasspath(uri.toString());
if (workspaceUri && onClasspath === false && !(await addToClasspath(uri))) {
return false;
Expand Down
16 changes: 8 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function specifyProgramArguments(context: vscode.ExtensionContext): Thenable<str
}

async function applyHCR(hcrStatusBar: NotificationBar) {
const debugSession: vscode.DebugSession = vscode.debug.activeDebugSession;
const debugSession: vscode.DebugSession | undefined = vscode.debug.activeDebugSession;
if (!debugSession) {
return;
}
Expand Down Expand Up @@ -246,7 +246,7 @@ async function runJavaFile(uri: vscode.Uri, noDebug: boolean) {
throw ex;
}

const activeEditor: vscode.TextEditor = vscode.window.activeTextEditor;
const activeEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
if (!uri && activeEditor && _.endsWith(path.basename(activeEditor.document.fileName), ".java")) {
uri = activeEditor.document.uri;
}
Expand Down Expand Up @@ -279,7 +279,7 @@ async function runJavaFile(uri: vscode.Uri, noDebug: boolean) {
} else {
const launchMainChoice: string = "main() method";
const launchTestChoice: string = "unit tests";
const choice: string = await vscode.window.showQuickPick(
const choice: string | undefined = await vscode.window.showQuickPick(
[launchMainChoice, launchTestChoice],
{ placeHolder: "Please select which kind of task you would like to launch" },
);
Expand Down Expand Up @@ -317,7 +317,7 @@ async function launchMain(mainMethods: IMainClassOption[], uri: vscode.Uri, noDe
return;
}

await startDebugging(pick.mainClass, pick.projectName, uri, noDebug);
await startDebugging(pick.mainClass, pick.projectName || "", uri, noDebug);
}

async function runJavaProject(node: any, noDebug: boolean) {
Expand All @@ -342,13 +342,13 @@ async function runJavaProject(node: any, noDebug: boolean) {
return;
}

const projectName: string = pick.projectName;
const projectName: string | undefined = pick.projectName;
const mainClass: string = pick.mainClass;
const filePath: string = pick.filePath;
const workspaceFolder: vscode.WorkspaceFolder = filePath ? vscode.workspace.getWorkspaceFolder(vscode.Uri.file(filePath)) : undefined;
const filePath: string | undefined = pick.filePath;
const workspaceFolder: vscode.WorkspaceFolder | undefined = filePath ? vscode.workspace.getWorkspaceFolder(vscode.Uri.file(filePath)) : undefined;
const launchConfigurations: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("launch", workspaceFolder);
const existingConfigs: vscode.DebugConfiguration[] = launchConfigurations.configurations;
const existConfig: vscode.DebugConfiguration = _.find(existingConfigs, (config) => {
const existConfig: vscode.DebugConfiguration | undefined = _.find(existingConfigs, (config) => {
return config.mainClass === mainClass && _.toString(config.projectName) === _.toString(projectName);
});
const debugConfig = existConfig || {
Expand Down
5 changes: 3 additions & 2 deletions src/javaDebugAdapterDescriptorFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { Type } from "./logger";
import { convertErrorToMessage, showErrorMessageWithTroubleshooting } from "./utility";

export class JavaDebugAdapterDescriptorFactory implements DebugAdapterDescriptorFactory {
public async createDebugAdapterDescriptor(_session: DebugSession, _executable: DebugAdapterExecutable): Promise<DebugAdapterDescriptor> {
let error: Error;
public async createDebugAdapterDescriptor(_session: DebugSession,
_executable: DebugAdapterExecutable): Promise<DebugAdapterDescriptor | undefined> {
let error: Error| undefined;
try {
const debugServerPort = <number> (await startDebugSession());
if (debugServerPort) {
Expand Down
4 changes: 2 additions & 2 deletions src/languageServerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ export function resolveClasspath(mainClass: string, projectName: string) {
return commands.executeJavaLanguageServerCommand(commands.JAVA_RESOLVE_CLASSPATH, mainClass, projectName);
}

export function resolveMainClass(workspaceUri: vscode.Uri): Promise<IMainClassOption[]> {
export function resolveMainClass(workspaceUri?: vscode.Uri): Promise<IMainClassOption[]> {
if (workspaceUri) {
return <Promise<IMainClassOption[]>>commands.executeJavaLanguageServerCommand(commands.JAVA_RESOLVE_MAINCLASS, workspaceUri.toString());
}
return <Promise<IMainClassOption[]>>commands.executeJavaLanguageServerCommand(commands.JAVA_RESOLVE_MAINCLASS);
}

export function validateLaunchConfig(workspaceUri: vscode.Uri, mainClass: string, projectName: string, containsExternalClasspaths: boolean):
export function validateLaunchConfig(mainClass: string, projectName: string, containsExternalClasspaths: boolean, workspaceUri?: vscode.Uri):
Promise<ILaunchValidationResponse> {
return <Promise<ILaunchValidationResponse>>commands.executeJavaLanguageServerCommand(commands.JAVA_VALIDATE_LAUNCHCONFIG,
workspaceUri ? workspaceUri.toString() : undefined, mainClass, projectName, containsExternalClasspaths);
Expand Down
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const SENSITIVE_PROPS = ["message", "stacktrace", "detailmessage"];

// Deprecate
class Logger implements vscode.Disposable {
private reporter: TelemetryReporter = null;
private reporter: TelemetryReporter | null = null;

public initialize(context: vscode.ExtensionContext, firstParty?: boolean): void {
if (this.reporter) {
Expand Down
13 changes: 8 additions & 5 deletions src/mainClassPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,19 @@ class MainClassPicker {
return this.getMRUTimestamp(b) - this.getMRUTimestamp(a);
});

const mostRecentlyUsedOption: IMainClassOption = (options.length && this.contains(options[0])) ? options[0] : undefined;
const mostRecentlyUsedOption: IMainClassOption | undefined = (options.length && this.contains(options[0])) ? options[0] : undefined;
const isMostRecentlyUsed = (option: IMainClassOption): boolean => {
return mostRecentlyUsedOption
return !!mostRecentlyUsedOption
&& mostRecentlyUsedOption.mainClass === option.mainClass
&& mostRecentlyUsedOption.projectName === option.projectName;
};
const isFromActiveEditor = (option: IMainClassOption): boolean => {
const activeEditor: TextEditor = window.activeTextEditor;
const activeEditor: TextEditor | undefined = window.activeTextEditor;
const currentActiveFile: string = _.get(activeEditor, "document.uri.fsPath");
return option.filePath && currentActiveFile && path.relative(option.filePath, currentActiveFile) === "";
if (option.filePath && currentActiveFile) {
return path.relative(option.filePath, currentActiveFile) === "";
}
return false;
};
const isPrivileged = (option: IMainClassOption): boolean => {
return isMostRecentlyUsed(option) || isFromActiveEditor(option);
Expand All @@ -124,7 +127,7 @@ class MainClassPicker {
adjustedDetail.push("$(clock) recently used");
}

if (isFromActiveEditor(option)) {
if (isFromActiveEditor(option) && option.filePath) {
adjustedDetail.push(`$(file-text) active editor (${path.basename(option.filePath)})`);
}

Expand Down
2 changes: 1 addition & 1 deletion src/processPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function convertToJavaProcess(pid: number, command: string, args: string): IJava
return undefined;
}

export async function pickJavaProcess(): Promise<IJavaProcess> {
export async function pickJavaProcess(): Promise<IJavaProcess | undefined> {
const javaProcesses: IJavaProcess[] = [];
try {
await getProcesses((pid: number, _ppid: number, command: string, args: string, _date: number) => {
Expand Down
2 changes: 1 addition & 1 deletion src/terminalLinkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class JavaTerminalLinkProvder implements TerminalLinkProvider<IJavaTermin
}

const regex = new RegExp("(\\sat\\s+)([\\w$\\.]+\\/)?(([\\w$]+\\.)+[<\\w$>]+)\\(([\\w-$]+\\.java:\\d+)\\)");
const result: RegExpExecArray = regex.exec(context.line);
const result: RegExpExecArray | null = regex.exec(context.line);
if (result && result.length) {
const stackTrace = `${result[2] || ""}${result[3]}(${result[5]})`;
const sourceLineNumber = Number(result[5].split(":")[1]);
Expand Down
2 changes: 1 addition & 1 deletion src/threadOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function initializeThreadOperations(context: vscode.ExtensionContext) {
}

async function operateThread(request: string, threadId: any): Promise<void> {
const debugSession: vscode.DebugSession = vscode.debug.activeDebugSession;
const debugSession: vscode.DebugSession | undefined = vscode.debug.activeDebugSession;
if (!debugSession) {
return;
}
Expand Down
22 changes: 11 additions & 11 deletions src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ function logMessage(message: ILoggingMessage): void {
}
sendError(error);
} else {
sendInfo(null, { message: message.message });
sendInfo("", { message: message.message });
}

// Deprecated
logger.log(message.type, { message: message.message, stack: message.stack });
logger.log(message.type, { message: message.message, stack: message.stack || "" });
}

export async function showInformationMessage(message: ILoggingMessage, ...items: string[]): Promise<string | undefined> {
Expand All @@ -79,20 +79,20 @@ export async function showErrorMessage(message: ILoggingMessage, ...items: strin

export async function showInformationMessageWithTroubleshooting(message: ITroubleshootingMessage, ...items: string[]): Promise<string | undefined> {
const choice = await showInformationMessage(message, ...items, LEARN_MORE);
return handleTroubleshooting(choice, message.message, message.anchor);
return handleTroubleshooting(message.message, choice, message.anchor);
}

export async function showWarningMessageWithTroubleshooting(message: ITroubleshootingMessage, ...items: string[]): Promise<string | undefined> {
const choice = await showWarningMessage(message, ...items, LEARN_MORE);
return handleTroubleshooting(choice, message.message, message.anchor);
return handleTroubleshooting(message.message, choice, message.anchor);
}

export async function showErrorMessageWithTroubleshooting(message: ITroubleshootingMessage, ...items: string[]): Promise<string | undefined> {
const choice = await showErrorMessage(message, ...items, LEARN_MORE);
return handleTroubleshooting(choice, message.message, message.anchor);
return handleTroubleshooting(message.message, choice, message.anchor);
}

function handleTroubleshooting(choice: string, message: string, anchor: string): string | undefined {
function handleTroubleshooting(message: string, choice?: string, anchor?: string): string | undefined {
if (choice === LEARN_MORE) {
openTroubleshootingPage(message, anchor);
return undefined;
Expand All @@ -101,9 +101,9 @@ function handleTroubleshooting(choice: string, message: string, anchor: string):
return choice;
}

export function openTroubleshootingPage(message: string, anchor: string) {
export function openTroubleshootingPage(message: string, anchor?: string) {
vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(anchor ? `${TROUBLESHOOTING_LINK}#${anchor}` : TROUBLESHOOTING_LINK));
sendInfo(null, {
sendInfo("", {
troubleshooting: "yes",
troubleshootingMessage: message,
});
Expand Down Expand Up @@ -183,7 +183,7 @@ export function getJavaExtensionAPI(): Thenable<any> {
return extension.activate();
}

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

Expand All @@ -194,11 +194,11 @@ export function isJavaExtEnabled(): boolean {

export function isJavaExtActivated(): boolean {
const javaExt = vscode.extensions.getExtension(JAVA_EXTENSION_ID);
return javaExt && javaExt.isActive;
return !!javaExt && javaExt.isActive;
}

export function getLauncherScriptPath() {
const ext = vscode.extensions.getExtension(DEBUGGER_EXTENSION_ID);
const ext = vscode.extensions.getExtension(DEBUGGER_EXTENSION_ID)!;
return path.join(ext.extensionPath, "scripts", "launcher.bat");
}

Expand Down
2 changes: 1 addition & 1 deletion test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ suite("Extension Tests", () => {

test("should activate", function() {
this.timeout(1 * 60 * 1000);
return vscode.extensions.getExtension("vscjava.vscode-java-debug").activate().then((_api) => {
return vscode.extensions.getExtension("vscjava.vscode-java-debug")!.activate().then((_api) => {
assert.ok(true);
});
});
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"noImplicitAny": true,
"noImplicitReturns": true,
"noUnusedParameters": true,
"strictNullChecks": true,
"alwaysStrict": true
},
"exclude": [
Expand Down