Skip to content

Commit

Permalink
Add LabelProvider Contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
jbicker committed Dec 6, 2024
1 parent ebd823e commit 8f12c49
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<void> {
const containerPort = parseInt(new URLSearchParams(location.search).get('port') ?? '0');
Expand All @@ -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}]`;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ContainerConnectionContribution } from './container-connection-contribu
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';

Expand All @@ -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);
});

0 comments on commit 8f12c49

Please sign in to comment.