From d3210940d65be4504b5c8066946b5cdcdb118db3 Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Mon, 6 Jul 2020 22:05:03 -0700 Subject: [PATCH 1/2] Create simple 'Debug Sessions' view to show comps under debugging Fix #1619. Signed-off-by: Denis Golovin --- package.json | 4 ++ src/debug.ts | 103 +++++++++++++++++++++++++++++++++++++++++++++++ src/extension.ts | 3 ++ 3 files changed, 110 insertions(+) create mode 100644 src/debug.ts diff --git a/package.json b/package.json index fe60fec1a..78dbe26d0 100644 --- a/package.json +++ b/package.json @@ -728,6 +728,10 @@ { "id": "openshiftWatchView", "name": "Watch Sessions" + }, + { + "id": "openshiftDebugView", + "name": "Debug Sessions" } ] }, diff --git a/src/debug.ts b/src/debug.ts new file mode 100644 index 000000000..0365af965 --- /dev/null +++ b/src/debug.ts @@ -0,0 +1,103 @@ +/*----------------------------------------------------------------------------------------------- + * 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, + commands, + debug, + DebugSession, +} from 'vscode'; + +import { Odo, OdoImpl } from './odo'; + +class DebugSessionEntry { + label: string; + session: DebugSession; +} + +export class DebugSessionsView implements TreeDataProvider, Disposable { + private static instance: DebugSessionsView; + private static sessions: Map = new Map(); + + private static odoctl: Odo = OdoImpl.Instance; + + private treeView: TreeView; + + private onDidChangeTreeDataEmitter: EventEmitter = + new EventEmitter(); + + readonly onDidChangeTreeData: Event = 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 { + 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 { + 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(); + } + +} diff --git a/src/extension.ts b/src/extension.ts index f72835b38..8b16e9ae9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 { @@ -70,6 +72,7 @@ export async function activate(extensionContext: ExtensionContext): Promise ), OpenShiftExplorer.getInstance(), WatchSessionsView.getInstance(), + DebugSessionsView.getInstance(), ...Component.init(extensionContext) ]; disposable.forEach((value) => extensionContext.subscriptions.push(value)); From 8fddadf2c5057a7689ffad71ea4e635f12832a41 Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Mon, 6 Jul 2020 22:23:33 -0700 Subject: [PATCH 2/2] Fix eslint errors Signed-off-by: Denis Golovin --- src/debug.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/debug.ts b/src/debug.ts index 0365af965..e5caee460 100644 --- a/src/debug.ts +++ b/src/debug.ts @@ -13,7 +13,6 @@ import { TreeView, window, TreeItemCollapsibleState, - commands, debug, DebugSession, } from 'vscode';