diff --git a/packages/dev-container/src/electron-browser/container-info-contribution.ts b/packages/dev-container/src/electron-browser/container-info-contribution.ts index 87b5cde0e220c..aaec7cbc48f57 100644 --- a/packages/dev-container/src/electron-browser/container-info-contribution.ts +++ b/packages/dev-container/src/electron-browser/container-info-contribution.ts @@ -15,14 +15,17 @@ // ***************************************************************************** import { inject, injectable } from '@theia/core/shared/inversify'; -import { FrontendApplicationContribution } from '@theia/core/lib/browser'; -import { RemoteContainerConnectionProvider } from '../electron-common/remote-container-connection-provider'; -import { PortForwardingService } from '@theia/remote/lib/electron-browser/port-forwarding/port-forwarding-service'; import { WindowTitleContribution } from '@theia/core/lib/browser/window/window-title-service'; import { RemoteStatus, RemoteStatusService } from '@theia/remote/lib/electron-common/remote-status-service'; +import { FrontendApplicationContribution, LabelProviderContribution } from '@theia/core/lib/browser'; +import type { ContainerInspectInfo } from 'dockerode'; +import { RemoteContainerConnectionProvider } from '../electron-common/remote-container-connection-provider'; +import { PortForwardingService } from '@theia/remote/lib/electron-browser/port-forwarding/port-forwarding-service'; +import { DEV_CONTAINER_PATH_QUERY } from '../electron-common/dev-container-workspaces'; +import { URI } from '@theia/core'; @injectable() -export class ContainerInfoContribution implements FrontendApplicationContribution, WindowTitleContribution { +export class ContainerInfoContribution implements FrontendApplicationContribution, WindowTitleContribution, LabelProviderContribution { @inject(RemoteContainerConnectionProvider) protected readonly connectionProvider: RemoteContainerConnectionProvider; @@ -33,6 +36,8 @@ export class ContainerInfoContribution implements FrontendApplicationContributio protected readonly remoteStatusService: RemoteStatusService; protected status: RemoteStatus | undefined; + protected containerInfo: ContainerInspectInfo | undefined; + protected containerFilePath: string | undefined; async onStart(): Promise { const containerPort = parseInt(new URLSearchParams(location.search).get('port') ?? '0'); @@ -56,4 +61,23 @@ export class ContainerInfoContribution implements FrontendApplicationContributio return title; } + canHandle(element: object): number { + if ('query' in element) { + let containerFilePath = new URLSearchParams((element as URI).query).get(DEV_CONTAINER_PATH_QUERY); + if (containerFilePath) { + if (containerFilePath.startsWith((element as URI).path.toString())) { + containerFilePath = containerFilePath.replace((element as URI).path.toString(), ''); + } + this.containerFilePath = containerFilePath; + return 100; + }; + return 0; + } + return 0; + } + + getLongName(element: URI): string | undefined { + return `${element.path.base} [Dev Container: ${this.containerFilePath}]`; + } + } diff --git a/packages/dev-container/src/electron-browser/dev-container-frontend-module.ts b/packages/dev-container/src/electron-browser/dev-container-frontend-module.ts index 5e51d9a6eaeec..c74deaaae7a8d 100644 --- a/packages/dev-container/src/electron-browser/dev-container-frontend-module.ts +++ b/packages/dev-container/src/electron-browser/dev-container-frontend-module.ts @@ -13,14 +13,14 @@ // // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** -import { ContainerModule } from '@theia/core/shared/inversify'; +import { ContainerModule } from 'inversify'; import { RemoteRegistryContribution } from '@theia/remote/lib/electron-browser/remote-registry-contribution'; import { RemoteContainerConnectionProvider, RemoteContainerConnectionProviderPath } from '../electron-common/remote-container-connection-provider'; import { ContainerConnectionContribution } from './container-connection-contribution'; import { ServiceConnectionProvider } from '@theia/core/lib/browser/messaging/service-connection-provider'; import { ContainerOutputProvider } from './container-output-provider'; import { ContainerInfoContribution } from './container-info-contribution'; -import { FrontendApplicationContribution } from '@theia/core/lib/browser'; +import { FrontendApplicationContribution, LabelProviderContribution } from '@theia/core/lib/browser'; import { WorkspaceOpenHandlerContribution } from '@theia/workspace/lib/browser/workspace-service'; import { WindowTitleContribution } from '@theia/core/lib/browser/window/window-title-service'; @@ -39,4 +39,5 @@ export default new ContainerModule(bind => { bind(ContainerInfoContribution).toSelf().inSingletonScope(); bind(FrontendApplicationContribution).toService(ContainerInfoContribution); bind(WindowTitleContribution).toService(ContainerInfoContribution); + bind(LabelProviderContribution).toService(ContainerInfoContribution); });