Skip to content

Commit 77f098e

Browse files
authored
Create simple 'Debug Sessions' view to show comps under debugging (#1629)
* Create simple 'Debug Sessions' view to show comps under debugging Fix #1619. Signed-off-by: Denis Golovin <dgolovin@redhat.com>
1 parent 37f185a commit 77f098e

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,10 @@
728728
{
729729
"id": "openshiftWatchView",
730730
"name": "Watch Sessions"
731+
},
732+
{
733+
"id": "openshiftDebugView",
734+
"name": "Debug Sessions"
731735
}
732736
]
733737
},

src/debug.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*-----------------------------------------------------------------------------------------------
2+
* Copyright (c) Red Hat, Inc. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE file in the project root for license information.
4+
*-----------------------------------------------------------------------------------------------*/
5+
6+
import {
7+
TreeDataProvider,
8+
TreeItem,
9+
Event,
10+
ProviderResult,
11+
EventEmitter,
12+
Disposable,
13+
TreeView,
14+
window,
15+
TreeItemCollapsibleState,
16+
debug,
17+
DebugSession,
18+
} from 'vscode';
19+
20+
import { Odo, OdoImpl } from './odo';
21+
22+
class DebugSessionEntry {
23+
label: string;
24+
session: DebugSession;
25+
}
26+
27+
export class DebugSessionsView implements TreeDataProvider<string>, Disposable {
28+
private static instance: DebugSessionsView;
29+
private static sessions: Map<string, DebugSessionEntry> = new Map();
30+
31+
private static odoctl: Odo = OdoImpl.Instance;
32+
33+
private treeView: TreeView<string>;
34+
35+
private onDidChangeTreeDataEmitter: EventEmitter<string> =
36+
new EventEmitter<string | undefined>();
37+
38+
readonly onDidChangeTreeData: Event<string | undefined> = this
39+
.onDidChangeTreeDataEmitter.event;
40+
41+
private constructor() {
42+
this.treeView = window.createTreeView('openshiftDebugView', {
43+
treeDataProvider: this,
44+
});
45+
debug.onDidStartDebugSession((session) => {
46+
if (session.configuration.contextPath) {
47+
const osObj = DebugSessionsView.odoctl.getOpenShiftObjectByContext(session.configuration.contextPath.fsPath);
48+
DebugSessionsView.sessions.set(session.configuration.contextPath.fsPath, {
49+
label: `${osObj.getParent().getParent().getName()}/${osObj.getParent().getName()}/${osObj.getName()}`,
50+
session
51+
});
52+
this.refresh();
53+
}
54+
}),
55+
debug.onDidTerminateDebugSession((session) => {
56+
if (session.configuration?.contextPath) {
57+
DebugSessionsView.sessions.delete(session.configuration.contextPath.fsPath);
58+
this.refresh();
59+
}
60+
})
61+
}
62+
63+
static getInstance(): DebugSessionsView {
64+
if (!DebugSessionsView.instance) {
65+
DebugSessionsView.instance = new DebugSessionsView();
66+
}
67+
return DebugSessionsView.instance;
68+
}
69+
70+
// eslint-disable-next-line class-methods-use-this
71+
getTreeItem(element: string): TreeItem | Thenable<TreeItem> {
72+
return {
73+
label: DebugSessionsView.sessions.get(element).label,
74+
collapsibleState: TreeItemCollapsibleState.None,
75+
contextValue: 'openshift.debug.session',
76+
iconPath: DebugSessionsView.odoctl.getOpenShiftObjectByContext(element).iconPath,
77+
command: {
78+
command: 'workbench.view.debug',
79+
title: 'Show Debug and Run'
80+
}
81+
};
82+
}
83+
84+
// eslint-disable-next-line class-methods-use-this
85+
getChildren(): ProviderResult<string[]> {
86+
return [...DebugSessionsView.sessions.keys()];
87+
}
88+
89+
// eslint-disable-next-line class-methods-use-this
90+
getParent?(): string {
91+
return undefined;
92+
}
93+
94+
refresh(): void {
95+
this.onDidChangeTreeDataEmitter.fire();
96+
}
97+
98+
dispose(): void {
99+
this.treeView.dispose();
100+
}
101+
102+
}

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ import { registerCommands } from './vscommand';
2121
import { ToolsConfig } from './tools';
2222
import { extendClusterExplorer } from './k8s/clusterExplorer';
2323
import { WatchSessionsView } from './watch';
24+
import { DebugSessionsView } from './debug';
2425

2526
import path = require('path');
2627
import fsx = require('fs-extra');
2728
import treeKill = require('tree-kill');
2829

30+
2931
// eslint-disable-next-line @typescript-eslint/no-empty-function
3032
// this method is called when your extension is deactivated
3133
export function deactivate(): void {
@@ -70,6 +72,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<any>
7072
),
7173
OpenShiftExplorer.getInstance(),
7274
WatchSessionsView.getInstance(),
75+
DebugSessionsView.getInstance(),
7376
...Component.init(extensionContext)
7477
];
7578
disposable.forEach((value) => extensionContext.subscriptions.push(value));

0 commit comments

Comments
 (0)