Skip to content

Commit d321094

Browse files
committed
Create simple 'Debug Sessions' view to show comps under debugging
Fix #1619. Signed-off-by: Denis Golovin <dgolovin@redhat.com>
1 parent 37f185a commit d321094

File tree

3 files changed

+110
-0
lines changed

3 files changed

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

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)