55
66/* eslint-disable @typescript-eslint/no-var-requires */
77
8- import { window , commands , QuickPickItem , Uri , workspace , ExtensionContext , debug , DebugConfiguration , extensions , ProgressLocation } from 'vscode' ;
8+ import { window , commands , QuickPickItem , Uri , workspace , ExtensionContext , debug , DebugConfiguration , extensions , ProgressLocation , DebugSession , Disposable } from 'vscode' ;
99import { ChildProcess , exec } from 'child_process' ;
1010import { isURL } from 'validator' ;
1111import OpenShiftItem , { selectTargetApplication , selectTargetComponent } from './openshiftItem' ;
@@ -29,6 +29,23 @@ const waitPort = require('wait-port');
2929
3030export class Component extends OpenShiftItem {
3131 public static extensionContext : ExtensionContext ;
32+ public static debugSessions : Map < Uri , DebugSession > = new Map ( ) ;
33+
34+ public static init ( context : ExtensionContext ) : Disposable [ ] {
35+ Component . extensionContext = context ;
36+ return [
37+ debug . onDidStartDebugSession ( ( session ) => {
38+ if ( session . configuration . contextPath ) {
39+ Component . debugSessions . set ( session . configuration . contextPath , session ) ;
40+ }
41+ } ) ,
42+ debug . onDidTerminateDebugSession ( ( session ) => {
43+ if ( session . configuration . contextPath ) {
44+ Component . debugSessions . delete ( session . configuration . contextPath ) ;
45+ }
46+ } )
47+ ] ;
48+ }
3249
3350 static async getOpenshiftData ( context : OpenShiftObject ) : Promise < OpenShiftObject > {
3451 return Component . getOpenShiftCmdData ( context ,
@@ -704,11 +721,12 @@ export class Component extends OpenShiftItem {
704721 }
705722 } ) ;
706723 cp . stderr . on ( 'data' , ( data : string ) => {
707- if ( ! `${ data } ` . includes ( 'address already in use ' ) ) {
724+ if ( ! `${ data } ` . includes ( 'the local debug port 5858 is not free ' ) ) {
708725 reject ( data ) ;
709726 }
710727 } ) ;
711728 } ) . then ( ( result ) => {
729+ config . contextPath = component . contextPath ;
712730 config . port = result ;
713731 config . odoPid = cp . pid ;
714732 return debug . startDebugging ( workspace . getWorkspaceFolder ( component . contextPath ) , config ) ;
0 commit comments