Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,10 @@
{
"id": "openshiftWatchView",
"name": "Watch Sessions"
},
{
"id": "openshiftDebugView",
"name": "Debug Sessions"
}
]
},
Expand Down
102 changes: 102 additions & 0 deletions src/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();
}

}
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import { registerCommands } from './vscommand';
import { ToolsConfig } from './tools';
import { extendClusterExplorer } from './k8s/clusterExplorer';
import { WatchSessionsView } from './watch';
import { DebugSessionsView } from './debug';

import path = require('path');
import fsx = require('fs-extra');
import treeKill = require('tree-kill');


// eslint-disable-next-line @typescript-eslint/no-empty-function
// this method is called when your extension is deactivated
export function deactivate(): void {
Expand Down Expand Up @@ -70,6 +72,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<any>
),
OpenShiftExplorer.getInstance(),
WatchSessionsView.getInstance(),
DebugSessionsView.getInstance(),
...Component.init(extensionContext)
];
disposable.forEach((value) => extensionContext.subscriptions.push(value));
Expand Down