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
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ async function verifyBundledBinaries(): Promise<any> {
export async function activate(extensionContext: ExtensionContext): Promise<any> {
migrateFromOdo018();
Cluster.extensionContext = extensionContext;
Component.extensionContext = extensionContext;
TokenStore.extensionContext = extensionContext;
const disposable = [
...(await registerCommands(
Expand All @@ -69,6 +68,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<any>
commands.executeCommand('extension.vsKubernetesUseNamespace', context),
),
OpenShiftExplorer.getInstance(),
...Component.init(extensionContext)
];
disposable.forEach((value) => extensionContext.subscriptions.push(value));

Expand Down
29 changes: 27 additions & 2 deletions src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* eslint-disable @typescript-eslint/no-var-requires */

import { window, commands, QuickPickItem, Uri, workspace, ExtensionContext, debug, DebugConfiguration, extensions, ProgressLocation } from 'vscode';
import { window, commands, QuickPickItem, Uri, workspace, ExtensionContext, debug, DebugConfiguration, extensions, ProgressLocation, DebugSession, Disposable } from 'vscode';
import { ChildProcess , exec } from 'child_process';
import { isURL } from 'validator';
import OpenShiftItem, { selectTargetApplication, selectTargetComponent } from './openshiftItem';
Expand All @@ -29,6 +29,23 @@ const waitPort = require('wait-port');

export class Component extends OpenShiftItem {
public static extensionContext: ExtensionContext;
public static debugSessions: Map<string, DebugSession> = new Map();

public static init(context: ExtensionContext): Disposable[] {
Component.extensionContext = context;
return [
debug.onDidStartDebugSession((session) => {
if (session.configuration.contextPath) {
Component.debugSessions.set(session.configuration.contextPath.fsPath, session);
}
}),
debug.onDidTerminateDebugSession((session) => {
if (session.configuration?.contextPath) {
Component.debugSessions.delete(session.configuration.contextPath.fsPath);
}
})
];
}

static async getOpenshiftData(context: OpenShiftObject): Promise<OpenShiftObject> {
return Component.getOpenShiftCmdData(context,
Expand Down Expand Up @@ -630,6 +647,13 @@ export class Component extends OpenShiftItem {
}

static async startDebugger(component: OpenShiftObject): Promise<string | undefined> {
if (Component.debugSessions.get(component.contextPath.fsPath)) {
const choice = await window.showWarningMessage(`Debugger session is already running for ${component.getName()}.`, 'Show \'Run and Debug\' view');
if (choice) {
commands.executeCommand('workbench.view.debug');
}
return null;
}
const components = await Component.odo.getComponentTypesJson();
const componentBuilder = components.find((builder) => builder.metadata.name === component.builderImage.name);
const imageStreamRef = await Component.odo.getImageStreamRef(componentBuilder.metadata.name, componentBuilder.metadata.namespace);
Expand Down Expand Up @@ -704,11 +728,12 @@ export class Component extends OpenShiftItem {
}
});
cp.stderr.on('data', (data: string) => {
if (!`${data}`.includes('address already in use')) {
if (!`${data}`.includes('the local debug port 5858 is not free')) {
reject(data);
}
});
}).then((result) => {
config.contextPath = component.contextPath;
config.port = result;
config.odoPid = cp.pid;
return debug.startDebugging(workspace.getWorkspaceFolder(component.contextPath), config);
Expand Down