import { DebugAdapterDescriptor , DebugAdapterDescriptorFactory , DebugAdapterExecutable , DebugAdapterServer , DebugSession } from "vscode" ; import { Type } from "./javaLogger" ; import { startDebugSession } from "./languageServerPlugin" ; import { convertErrorToMessage , showErrorMessageWithTroubleshooting } from "./utility" ; export class JavaDebugAdapterDescriptorFactory implements DebugAdapterDescriptorFactory { public async createDebugAdapterDescriptor ( _session , _executable ) { let error ; try { const debugServerPort = < number > ( await startDebugSession ( ) ) ; if ( debugServerPort ) { return new DebugAdapterServer ( debugServerPort ) ; } else { console . log ( "Cannot find a port for debugging session" ) ; } } catch ( err ) { error = err ; } const message = error ? convertErrorToMessage ( error ) : { type : Type . EXCEPTION , message : "Failed to start debug server." , } ; showErrorMessageWithTroubleshooting ( message ) ; return undefined ; } }