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 < string , 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 . fsPath , session ) ;
40+ }
41+ } ) ,
42+ debug . onDidTerminateDebugSession ( ( session ) => {
43+ if ( session . configuration ?. contextPath ) {
44+ Component . debugSessions . delete ( session . configuration . contextPath . fsPath ) ;
45+ }
46+ } )
47+ ] ;
48+ }
3249
3350 static async getOpenshiftData ( context : OpenShiftObject ) : Promise < OpenShiftObject > {
3451 return Component . getOpenShiftCmdData ( context ,
@@ -630,6 +647,13 @@ export class Component extends OpenShiftItem {
630647 }
631648
632649 static async startDebugger ( component : OpenShiftObject ) : Promise < string | undefined > {
650+ if ( Component . debugSessions . get ( component . contextPath . fsPath ) ) {
651+ const choice = await window . showWarningMessage ( `Debugger session is already running for ${ component . getName ( ) } .` , 'Show \'Run and Debug\' view' ) ;
652+ if ( choice ) {
653+ commands . executeCommand ( 'workbench.view.debug' ) ;
654+ }
655+ return null ;
656+ }
633657 const components = await Component . odo . getComponentTypesJson ( ) ;
634658 const componentBuilder = components . find ( ( builder ) => builder . metadata . name === component . builderImage . name ) ;
635659 const imageStreamRef = await Component . odo . getImageStreamRef ( componentBuilder . metadata . name , componentBuilder . metadata . namespace ) ;
@@ -704,11 +728,12 @@ export class Component extends OpenShiftItem {
704728 }
705729 } ) ;
706730 cp . stderr . on ( 'data' , ( data : string ) => {
707- if ( ! `${ data } ` . includes ( 'address already in use ' ) ) {
731+ if ( ! `${ data } ` . includes ( 'the local debug port 5858 is not free ' ) ) {
708732 reject ( data ) ;
709733 }
710734 } ) ;
711735 } ) . then ( ( result ) => {
736+ config . contextPath = component . contextPath ;
712737 config . port = result ;
713738 config . odoPid = cp . pid ;
714739 return debug . startDebugging ( workspace . getWorkspaceFolder ( component . contextPath ) , config ) ;
0 commit comments