Skip to content

Commit ff661af

Browse files
committed
Save started component debug sessions in map URI->DebugSession
Signed-off-by: Denis Golovin <dgolovin@redhat.com>
1 parent 367b297 commit ff661af

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ async function verifyBundledBinaries(): Promise<any> {
5151
export async function activate(extensionContext: ExtensionContext): Promise<any> {
5252
migrateFromOdo018();
5353
Cluster.extensionContext = extensionContext;
54-
Component.extensionContext = extensionContext;
5554
TokenStore.extensionContext = extensionContext;
5655
const disposable = [
5756
...(await registerCommands(
@@ -69,6 +68,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<any>
6968
commands.executeCommand('extension.vsKubernetesUseNamespace', context),
7069
),
7170
OpenShiftExplorer.getInstance(),
71+
...Component.init(extensionContext)
7272
];
7373
disposable.forEach((value) => extensionContext.subscriptions.push(value));
7474

src/openshift/component.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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';
99
import { ChildProcess , exec } from 'child_process';
1010
import { isURL } from 'validator';
1111
import OpenShiftItem, { selectTargetApplication, selectTargetComponent } from './openshiftItem';
@@ -29,6 +29,23 @@ const waitPort = require('wait-port');
2929

3030
export 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

Comments
 (0)