Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose TreeDataProviders in API #402

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/api/pickAppResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PickAppResourceOptions } from "@microsoft/vscode-azext-utils/hostapi";
import { ext } from "../extensionVariables";

export async function pickAppResource<T extends AzExtTreeItem>(context: ITreeItemPickerContext, options?: PickAppResourceOptions): Promise<T> {
return await compatibilityPickAppResourceExperience<T>(context, ext.v2.resourceGroupsTreeDataProvider, {
return await compatibilityPickAppResourceExperience<T>(context, ext.v2.applicationResourceTreeDataProvider, {
resourceTypes: convertAppResourceFilterToAzExtResourceType(options?.filter),
childItemFilter: convertExpectedChildContextValueToContextValueFilter(options?.expectedChildContextValue)
});
Expand Down
4 changes: 4 additions & 0 deletions src/api/v2/v2AzureResourcesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ export interface ResourcePickOptions {
* The current (v2) Azure Resources extension API.
*/
export interface V2AzureResourcesApi extends AzureResourcesApiBase {

applicationResourceTreeDataProvider: vscode.TreeDataProvider<unknown>;
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved
workspaceResourceTreeDataProvider: vscode.TreeDataProvider<unknown>;

/**
* Reveals an item in the application/workspace resource tree
* @param resourceId The ID of the resource to reveal.
Expand Down
8 changes: 6 additions & 2 deletions src/api/v2/v2AzureResourcesApiImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import * as vscode from 'vscode';
import { ApplicationResourceBranchDataProviderManager } from '../../tree/v2/application/ApplicationResourceBranchDataProviderManager';
import { ApplicationResourceTreeDataProvider } from '../../tree/v2/application/ApplicationResourceTreeDataProvider';
import { WorkspaceResourceBranchDataProviderManager } from '../../tree/v2/workspace/WorkspaceResourceBranchDataProviderManager';
import { WorkspaceResourceTreeDataProvider } from '../../tree/v2/workspace/WorkspaceResourceTreeDataProvider';
import { ApplicationResourceProviderManager, WorkspaceResourceProviderManager } from './ResourceProviderManagers';
import { ApplicationResource, ApplicationResourceProvider, BranchDataProvider, ResourceModelBase, V2AzureResourcesApi, WorkspaceResource, WorkspaceResourceProvider } from './v2AzureResourcesApi';

Expand All @@ -16,8 +18,10 @@ export class V2AzureResourcesApiImplementation implements V2AzureResourcesApi {
private readonly applicationResourceProviderManager: ApplicationResourceProviderManager,
private readonly applicationResourceBranchDataProviderManager: ApplicationResourceBranchDataProviderManager,
private readonly workspaceResourceProviderManager: WorkspaceResourceProviderManager,
private readonly workspaceResourceBranchDataProviderManager: WorkspaceResourceBranchDataProviderManager) {
}
private readonly workspaceResourceBranchDataProviderManager: WorkspaceResourceBranchDataProviderManager,
public readonly applicationResourceTreeDataProvider: ApplicationResourceTreeDataProvider,
public readonly workspaceResourceTreeDataProvider: WorkspaceResourceTreeDataProvider,
) { }

get apiVersion(): string {
return V2AzureResourcesApiImplementation.apiVersion;
Expand Down
8 changes: 8 additions & 0 deletions src/api/v2/v2AzureResourcesApiWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export class V2AzureResourcesApiWrapper implements V2AzureResourcesApi {
return this.api.apiVersion;
}

get applicationResourceTreeDataProvider(): vscode.TreeDataProvider<unknown> {
return this.callWithTelemetryAndErrorHandlingSync('v2.getApplicationResourceTreeDataProvider', () => this.api.applicationResourceTreeDataProvider);
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved
}

get workspaceResourceTreeDataProvider(): vscode.TreeDataProvider<unknown> {
return this.callWithTelemetryAndErrorHandlingSync('v2.getWorkspaceResourceTreeDataProvider', () => this.api.workspaceResourceTreeDataProvider);
}

revealResource(resourceId: string): Promise<void> {
return this.callWithTelemetryAndErrorHandling('v2.revealResource', async () => await this.api.revealResource(resourceId));
}
Expand Down
27 changes: 15 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import { GroupTreeItemBase } from './tree/GroupTreeItemBase';
import { HelpTreeItem } from './tree/HelpTreeItem';
import { ApplicationResourceBranchDataProviderManager } from './tree/v2/application/ApplicationResourceBranchDataProviderManager';
import { DefaultApplicationResourceBranchDataProvider } from './tree/v2/application/DefaultApplicationResourceBranchDataProvider';
import { registerResourceGroupsTreeV2 } from './tree/v2/application/registerResourceGroupsTreeV2';
import { registerWorkspaceTreeV2 } from './tree/v2/workspace/registerWorkspaceTreeV2';
import { registerApplicationTree } from './tree/v2/application/registerResourceGroupsTreeV2';
import { registerWorkspaceTree } from './tree/v2/workspace/registerWorkspaceTreeV2';
import { WorkspaceDefaultBranchDataProvider } from './tree/v2/workspace/WorkspaceDefaultBranchDataProvider';
import { WorkspaceResourceBranchDataProviderManager } from './tree/v2/workspace/WorkspaceResourceBranchDataProviderManager';
import { WorkspaceTreeItem } from './tree/WorkspaceTreeItem';
Expand Down Expand Up @@ -122,25 +122,28 @@ export async function activateInternal(context: vscode.ExtensionContext, perfSta
type => void extensionManager.activateWorkspaceResourceBranchDataProvider(type));
const workspaceResourceProviderManager = new WorkspaceResourceProviderManager(() => extensionManager.activateWorkspaceResourceProviders());

registerResourceGroupsTreeV2(
context,
const { applicationResourceTreeDataProvider } = registerApplicationTree(context, {
branchDataProviderManager,
refreshEventEmitter.event,
resourceProviderManager);
resourceProviderManager,
refreshEvent: refreshEventEmitter.event,
});

registerWorkspaceTreeV2(
workspaceResourceBranchDataProviderManager,
context,
refreshWorkspaceEmitter.event,
workspaceResourceProviderManager);
const { workspaceResourceTreeDataProvider } = registerWorkspaceTree(context, {
branchDataProviderManager: workspaceResourceBranchDataProviderManager,
workspaceResourceProviderManager,
refreshEvent: refreshWorkspaceEmitter.event,
});

const v2ApiFactory = () => {
if (v2Api === undefined) {
v2Api = new V2AzureResourcesApiImplementation(
resourceProviderManager,
branchDataProviderManager,
workspaceResourceProviderManager,
workspaceResourceBranchDataProviderManager);
workspaceResourceBranchDataProviderManager,
applicationResourceTreeDataProvider,
workspaceResourceTreeDataProvider
);

context.subscriptions.push(v2Api.registerApplicationResourceProvider('TODO: is ID useful?', new DefaultApplicationResourceProvider()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/extensionVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ export namespace ext {

export namespace v2 {
export let api: V2AzureResourcesApi;
export let resourceGroupsTreeDataProvider: TreeDataProvider<ResourceGroupsItem>;
export let applicationResourceTreeDataProvider: TreeDataProvider<ResourceGroupsItem>;
}
}
26 changes: 19 additions & 7 deletions src/tree/v2/application/registerResourceGroupsTreeV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,44 @@ import { ApplicationResourceGroupingManager } from './ApplicationResourceGroupin
import { ApplicationResourceTreeDataProvider } from './ApplicationResourceTreeDataProvider';
import { createGroupingItemFactory } from './GroupingItem';

export function registerResourceGroupsTreeV2(
context: vscode.ExtensionContext,
interface RegisterApplicationTreeOptions {
branchDataProviderManager: ApplicationResourceBranchDataProviderManager,
refreshEvent: vscode.Event<void>,
resourceProviderManager: ApplicationResourceProviderManager): void {
resourceProviderManager: ApplicationResourceProviderManager
}

interface RegisterApplicationTreeResult {
applicationResourceTreeDataProvider: ApplicationResourceTreeDataProvider;
}

export function registerApplicationTree(context: vscode.ExtensionContext, options: RegisterApplicationTreeOptions): RegisterApplicationTreeResult {
const { branchDataProviderManager, resourceProviderManager, refreshEvent } = options;

const itemCache = new ResourceGroupsItemCache();
const branchDataItemFactory = createApplicationResourceBranchDataItemFactory(itemCache);
const groupingItemFactory = createGroupingItemFactory(branchDataItemFactory, resource => branchDataProviderManager.getProvider(resource.azExtResourceType ?? resource.type.type));
const resourceGroupingManager = new ApplicationResourceGroupingManager(groupingItemFactory);

context.subscriptions.push(resourceGroupingManager);

const treeDataProvider = new ApplicationResourceTreeDataProvider(branchDataProviderManager.onDidChangeTreeData, itemCache, refreshEvent, resourceGroupingManager, resourceProviderManager);
ext.v2.resourceGroupsTreeDataProvider = treeDataProvider;
const applicationResourceTreeDataProvider = new ApplicationResourceTreeDataProvider(branchDataProviderManager.onDidChangeTreeData, itemCache, refreshEvent, resourceGroupingManager, resourceProviderManager);
ext.v2.applicationResourceTreeDataProvider = applicationResourceTreeDataProvider;

context.subscriptions.push(treeDataProvider);
context.subscriptions.push(applicationResourceTreeDataProvider);

const treeView = vscode.window.createTreeView(
'azureResourceGroupsV2',
{
canSelectMany: true,
showCollapseAll: true,
treeDataProvider
treeDataProvider: applicationResourceTreeDataProvider
});

treeView.description = localize('remote', 'Remote');

context.subscriptions.push(treeView);

return {
applicationResourceTreeDataProvider
}
}
24 changes: 18 additions & 6 deletions src/tree/v2/workspace/registerWorkspaceTreeV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,39 @@ import { localize } from './../../../utils/localize';
import { WorkspaceResourceBranchDataProviderManager } from './WorkspaceResourceBranchDataProviderManager';
import { WorkspaceResourceTreeDataProvider } from './WorkspaceResourceTreeDataProvider';

export function registerWorkspaceTreeV2(
interface RegisterWorkspaceTreeOptions {
branchDataProviderManager: WorkspaceResourceBranchDataProviderManager,
context: vscode.ExtensionContext,
refreshEvent: vscode.Event<void>,
workspaceResourceProviderManager: WorkspaceResourceProviderManager): void {
const treeDataProvider = new WorkspaceResourceTreeDataProvider(
workspaceResourceProviderManager: WorkspaceResourceProviderManager
}

interface RegisterWorkspaceTreeResult {
workspaceResourceTreeDataProvider: WorkspaceResourceTreeDataProvider;
}

export function registerWorkspaceTree(context: vscode.ExtensionContext, options: RegisterWorkspaceTreeOptions): RegisterWorkspaceTreeResult {
const { branchDataProviderManager, refreshEvent, workspaceResourceProviderManager } = options;

const workspaceResourceTreeDataProvider = new WorkspaceResourceTreeDataProvider(
branchDataProviderManager,
refreshEvent,
workspaceResourceProviderManager);

context.subscriptions.push(treeDataProvider);
context.subscriptions.push(workspaceResourceTreeDataProvider);

const treeView = vscode.window.createTreeView(
'azureWorkspaceV2',
{
canSelectMany: true,
showCollapseAll: true,
treeDataProvider
treeDataProvider: workspaceResourceTreeDataProvider
});

treeView.description = localize('local', 'Local');

context.subscriptions.push(treeView);

return {
workspaceResourceTreeDataProvider
}
}