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