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
11 changes: 1 addition & 10 deletions src/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
});
}

const debugServerPort = await lsPlugin.startDebugSession();
if (debugServerPort) {
config.debugServer = debugServerPort;
return config;
} else {
// Information for diagnostic:
// tslint:disable-next-line:no-console
console.log("Cannot find a port for debugging session");
throw new Error("Failed to start debug server.");
}
return config;
} catch (ex) {
if (ex instanceof utility.JavaExtensionNotEnabledError) {
utility.guideToInstallJavaExtension();
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { JavaDebugConfigurationProvider } from "./configurationProvider";
import { HCR_EVENT, JAVA_LANGID, USER_NOTIFICATION_EVENT } from "./constants";
import { initializeCodeLensProvider, startDebugging } from "./debugCodeLensProvider";
import { handleHotCodeReplaceCustomEvent, initializeHotCodeReplace, NO_BUTTON, YES_BUTTON } from "./hotCodeReplace";
import { JavaDebugAdapterDescriptorFactory } from "./javaDebugAdapterDescriptorFactory";
import { IMainMethod, resolveMainMethod } from "./languageServerPlugin";
import { logger, Type } from "./logger";
import { initializeThreadOperations } from "./threadOperations";
Expand All @@ -33,6 +34,7 @@ function initializeExtension(operationId: string, context: vscode.ExtensionConte
registerDebugEventListener(context);
context.subscriptions.push(logger);
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider("java", new JavaDebugConfigurationProvider()));
context.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory("java", new JavaDebugAdapterDescriptorFactory()));
context.subscriptions.push(instrumentOperationAsVsCodeCommand("JavaDebug.SpecifyProgramArgs", async () => {
return specifyProgramArguments(context);
}));
Expand Down
39 changes: 39 additions & 0 deletions src/javaDebugAdapterDescriptorFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { DebugAdapterDescriptor, DebugAdapterDescriptorFactory, DebugAdapterExecutable, DebugAdapterServer, DebugSession } from "vscode";

import { startDebugSession } from "./languageServerPlugin";
import { Type } from "./logger";
import { formatErrorProperties, showErrorMessageWithTroubleshooting } from "./utility";

export class JavaDebugAdapterDescriptorFactory implements DebugAdapterDescriptorFactory {
public async createDebugAdapterDescriptor(session: DebugSession, executable: DebugAdapterExecutable): Promise<DebugAdapterDescriptor> {
let error;
try {
const debugServerPort = <number> (await startDebugSession());
if (debugServerPort) {
return new DebugAdapterServer(debugServerPort);
} else {
// Information for diagnostic:
// tslint:disable-next-line:no-console
console.log("Cannot find a port for debugging session");
}
} catch (err) {
error = err;
}

let errorMessage = "Failed to start debug server.";
let details = {};
if (error) {
errorMessage = error.message || String(error);
details = formatErrorProperties(error);
}

showErrorMessageWithTroubleshooting({
message: errorMessage,
type: Type.EXCEPTION,
details,
});
}
}