Skip to content

Commit cdd14a0

Browse files
committed
Add revealWorkspaceResource function to expose resources in Workspace tree view
1 parent be5a429 commit cdd14a0

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

api/src/resources/resourcesApi.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ export interface ResourcesApi {
6161
*/
6262
revealAzureResource(id: string, options?: VSCodeRevealOptions): Promise<void>;
6363

64+
/**
65+
* Reveal a resource in the Workspace tree view.
66+
*
67+
* @param id - The Workspace Resource ID to reveal in the Workspace tree view.
68+
* @param options - Options for revealing the resource. See {@link vscode.TreeView.reveal}
69+
*/
70+
revealWorkspaceResource(id: string, options?: VSCodeRevealOptions): Promise<void>;
71+
6472
/**
6573
* Gets a list of node IDs for nodes recently used/interacted with in the Azure tree view.
6674
*

src/api/createAzureResourcesHostApi.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { callWithTelemetryAndErrorHandling } from '@microsoft/vscode-azext-utils';
77
import * as vscode from 'vscode';
88
import { AzExtResourceType, AzureResource, BranchDataProvider, ResourceModelBase, VSCodeRevealOptions, WorkspaceResource, WorkspaceResourceProvider } from '../../api/src/index';
9-
import { revealResource } from '../commands/revealResource';
9+
import { revealResource, revealWorkspaceResource } from '../commands/revealResource';
1010
import { AzureResourceProvider, AzureResourcesHostApiInternal } from '../hostapi.v2.internal';
1111
import { AzureResourceBranchDataProviderManager } from '../tree/azure/AzureResourceBranchDataProviderManager';
1212
import { AzureResourceTreeDataProvider } from '../tree/azure/AzureResourceTreeDataProvider';
@@ -54,6 +54,15 @@ export function createAzureResourcesHostApi(
5454
});
5555
},
5656

57+
revealWorkspaceResource: (id: string, options?: VSCodeRevealOptions) => {
58+
return callWithTelemetryAndErrorHandling('internalRevealWorkspaceResource', context => {
59+
context.errorHandling.rethrow = true;
60+
context.errorHandling.suppressDisplay = true;
61+
context.errorHandling.suppressReportIssue = true;
62+
return revealWorkspaceResource(context, id, options);
63+
});
64+
},
65+
5766
getRecentlyUsedAzureNodes: () => {
5867
return getRecentlyUsedAzureNodes();
5968
},

src/api/createWrappedAzureResourcesExtensionApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function createWrappedAzureResourcesExtensionApi(api: AzureResourcesApiIn
2626
workspaceResourceTreeDataProvider: api.resources.workspaceResourceTreeDataProvider,
2727
...wrapFunctionsInTelemetry({
2828
revealAzureResource: api.resources.revealAzureResource.bind(api) as typeof api.resources.revealAzureResource,
29+
revealWorkspaceResource: api.resources.revealWorkspaceResource.bind(api) as typeof api.resources.revealWorkspaceResource,
2930
}, wrapOptions),
3031
...wrapFunctionsInTelemetrySync({
3132
registerAzureResourceBranchDataProvider: api.resources.registerAzureResourceBranchDataProvider.bind(api) as typeof api.resources.registerAzureResourceBranchDataProvider,

src/commands/revealResource.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ export async function revealResource(context: IActionContext, resourceId: string
2323
}
2424
}
2525

26+
export async function revealWorkspaceResource(context: IActionContext, resourceId: string, options?: VSCodeRevealOptions): Promise<void> {
27+
try {
28+
const item: ResourceGroupsItem | undefined = await (ext.v2.api.resources.workspaceResourceTreeDataProvider as ResourceTreeDataProviderBase).findItemById(resourceId);
29+
if (item) {
30+
await ext.workspaceTreeView.reveal(item as unknown as AzExtTreeItem, options ?? { expand: false, focus: true, select: true });
31+
}
32+
} catch (error) {
33+
context.telemetry.properties.revealError = maskUserInfo(parseError(error).message, []);
34+
}
35+
}
36+
2637
function setTelemetryPropertiesForId(context: IActionContext, resourceId: string): void {
2738
const parsedAzureResourceId = parsePartialAzureResourceId(resourceId);
2839
const resourceKind = getResourceKindFromId(parsedAzureResourceId);

0 commit comments

Comments
 (0)