-
Notifications
You must be signed in to change notification settings - Fork 68
/
hostapi.d.ts
334 lines (280 loc) · 11 KB
/
hostapi.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type { AzExtResourceType, AzureSubscription } from '@microsoft/vscode-azureresources-api';
import type * as vscode from 'vscode';
import type { AbstractAzExtTreeItem, AzExtParentTreeItem, AzExtTreeDataProvider, AzExtTreeItem, IAzureQuickPickOptions, ISubscriptionContext, ITreeItemPickerContext, SealedAzExtTreeItem } from './index'; // This must remain `import type` or else a circular reference will result
/**
* The API implemented by the Azure Resource Groups host extension
*/
export interface AzureHostExtensionApi {
/**
* The `AzExtTreeDataProvider` for the shared app resource view
*/
readonly appResourceTree: AzExtTreeDataProvider;
/**
* The VSCode TreeView for the shared app resource view
*/
readonly appResourceTreeView: vscode.TreeView<unknown>;
/**
* The `AzExtTreeDataProvider` for the shared workspace resource view
*/
readonly workspaceResourceTree: AzExtTreeDataProvider;
/**
* The VSCode TreeView for the shared workspace resource view
*/
readonly workspaceResourceTreeView: vscode.TreeView<unknown>;
/**
* Version of the API
*/
readonly apiVersion: string;
/**
* Show a quick picker of app resources. Set `options.type` to filter the picks.
*/
pickAppResource<T extends AzExtTreeItem>(context: ITreeItemPickerContext, options?: PickAppResourceOptions): Promise<T>
/**
* Registers an app resource resolver
* @param id The resolver ID. Must be unique.
* @param resolver The resolver
*/
registerApplicationResourceResolver(id: string, resolver: AppResourceResolver): vscode.Disposable;
/**
* Registers a workspace resource provider
* @param id The provider ID. Must be unique.
* @param provider The provider
*/
registerWorkspaceResourceProvider(id: string, provider: WorkspaceResourceProvider): vscode.Disposable;
/**
* Registers an activity to appear in the activity window
* @param activity The activity information to show
*/
registerActivity(activity: Activity): Promise<void>;
//#region Deprecated things that will be removed soon
/**
* @deprecated Use `appResourceTree` instead
*/
readonly tree: AzExtTreeDataProvider;
/**
* @deprecated Use `appResourceTreeView` instead
*/
readonly treeView: vscode.TreeView<unknown>;
/**
* @deprecated Use `registerWorkspaceResourceProvider` instead
*/
registerLocalResourceProvider(id: string, provider: LocalResourceProvider): vscode.Disposable;
//#endregion
/**
* @deprecated For internal usage only
* @param filter Whether to filter the list returned, according to the list returned
* by `getTenantFilters()` and `getSubscriptionFilters()`.
*/
getSubscriptions: (filter: boolean) => Promise<AzureSubscription[]>;
}
export interface AppResourceFilter {
/**
* App resource type to filter the app resource picks
*/
type: string;
/**
* (Optional) App resource kind to filter the app resource picks
*/
kind?: string;
/**
* (Optional) ARM tags that must be present on the resource. Resource must match all provided tags.
*/
tags?: Record<string, string>;
}
export interface PickAppResourceOptions extends IAzureQuickPickOptions {
/**
* Options to filter the picks to resources that match any of the provided filters
*/
filter?: AppResourceFilter | AppResourceFilter[];
/**
* Set this to pick a child of the selected app resource
*/
expectedChildContextValue?: string | RegExp | (string | RegExp)[];
/**
* Whether `AppResourceTreeItem`s should be resolved before displaying them as quick picks, or only once one has been selected
* If a client extension needs to change label/description/something visible on the quick pick via `resolve`, set to true,
* otherwise set to false. Default will be false.
*/
resolveQuickPicksBeforeDisplay?: boolean;
}
/**
* An abstract interface for GenericResource
*/
export interface AppResource {
readonly id: string;
readonly name: string;
/**
* This is a custom property that unambiguously describes the type of an Azure resource for the purposes of the Azure extensions.
* This accounts for the fact that some Azure resource have overlapping type and kind values.
*/
readonly azExtResourceType?: AzExtResourceType;
readonly type: string;
readonly kind?: string;
readonly location?: string;
/** Resource tags */
readonly tags?: {
[propertyName: string]: string;
};
/* add more properties from GenericResource if needed */
}
/**
* Defines how a group tree item is created and appears in the tree view
*/
export interface GroupNodeConfiguration {
readonly label: string;
readonly id: string;
readonly description?: string;
readonly icon?: vscode.ThemeIcon;
readonly iconPath?: string | vscode.Uri | { light: string | vscode.Uri; dark: string | vscode.Uri } | vscode.ThemeIcon;
readonly contextValuesToAdd?: string[];
}
/**
* Defines how a leaf tree item is grouped
*/
export interface GroupingConfig {
readonly resourceGroup: GroupNodeConfiguration;
readonly resourceType: GroupNodeConfiguration;
[label: string]: GroupNodeConfiguration; // Don't need to support right off the bat but we can put it in the interface
}
/**
* A resource that can be grouped
*/
export interface GroupableResource {
readonly groupConfig: GroupingConfig;
}
interface ContextValuesToAdd {
/**
* Resolvers are not allowed to set the context value. Instead, they must provide `contextValuesToAdd`
*/
contextValue?: never;
/**
* Optionally, context values to add to the tree item. The overall context value string is a deduped, alphabetized, semicolon-separated list of individual context values.
*/
contextValuesToAdd?: string[];
}
/**
* The base of the type that resolvers must return as their resolve result
*/
export type ResolvedAppResourceBase = Partial<{ [P in keyof SealedAzExtTreeItem]: never }> & Partial<AbstractAzExtTreeItem> & ContextValuesToAdd;
/**
* A generic that describes the tree item that would be given as an argument to commands called on tree items in the shared resource tree
*/
export type ResolvedAppResourceTreeItem<T extends ResolvedAppResourceBase> = SealedAzExtTreeItem & AbstractAzExtTreeItem & Omit<T, keyof ResolvedAppResourceBase>;
/**
* The interface that resource resolvers must implement
*/
export interface AppResourceResolver {
/**
* Resolves more information about an AppResource, filling in the remaining functionality of the tree item
* @param subContext The Azure subscription context for the AppResource
* @param resource The AppResource
*/
resolveResource(subContext: ISubscriptionContext, resource: AppResource): vscode.ProviderResult<ResolvedAppResourceBase>;
/**
* Checks if this resolver is a match for a given AppResource. This should be designed to be as fast as possible.
* @param resource The AppResource to check if this resolver matches
*/
matchesResource(resource: AppResource): boolean;
}
// Not part of public interface to start with--only Resource Groups extension will call it (for now)
// currently implemented as AzureResourceProvider
export interface AppResourceProvider {
provideResources(
subContext: ISubscriptionContext
): vscode.ProviderResult<AppResource[]>;
}
/**
* A type to describe the WorkspaceResource objects that providers should give to show in the workspace resource tree
*/
export type WorkspaceResource = AzExtTreeItem;
/**
* A provider for supplying items for the workspace resource tree (e.g., storage emulator, function apps in workspace, etc.)
*/
export interface WorkspaceResourceProvider {
/**
* Called to supply the tree nodes to the workspace resource tree
* @param parent The parent tree item (which will be the root of the workspace resource tree)
*/
provideResources(parent: AzExtParentTreeItem): vscode.ProviderResult<WorkspaceResource[] | undefined>;
}
//#region Deprecated things that will be removed soon
/**
* @deprecated use `AzureHostExtensionApi` instead
*/
export type AzureResourceGroupsExtensionApi = AzureHostExtensionApi;
/**
* @deprecated Use `WorkspaceResource` instead
*/
export type LocalResource = WorkspaceResource;
/**
* @deprecated Use `WorkspaceResourceProvider` instead
*/
export type LocalResourceProvider = WorkspaceResourceProvider;
//#endregion
/**
* Represents an Activity to display in the Activity Log
*/
export interface Activity {
/**
* An ID for the activity. Must be unique.
*/
id: string;
/**
* If the activity supports cancellation, provide this `CancellationTokenSource`. The Activity Log will add a cancel button that will trigger this CTS.
*/
cancellationTokenSource?: vscode.CancellationTokenSource;
/**
* Fire this event to start the activity
*/
onStart: vscode.Event<OnStartActivityData>;
/**
* Fire this event to report progress on the activity
*/
onProgress: vscode.Event<OnProgressActivityData>;
/**
* Fire this event when the activity succeeds
*/
onSuccess: vscode.Event<OnSuccessActivityData>;
/**
* Fire this event when the activity fails
*/
onError: vscode.Event<OnErrorActivityData>;
}
/**
* Options to set on the Activity log tree item
*/
export interface ActivityTreeItemOptions {
/**
* The label of the item
*/
label: string;
/**
* Optionally, context values to add to the tree item. The overall context value string is a deduped, alphabetized, semicolon-separated list of individual context values.
*/
contextValuesToAdd?: string[];
/**
* If the activity should have child tree items, implement this
*/
getChildren?: (parent: AzExtParentTreeItem) => AzExtTreeItem[] | Promise<AzExtTreeItem[]>;
}
type ActivityEventData<T> = ActivityTreeItemOptions & T;
/**
* Event data for activity start
*/
export type OnStartActivityData = ActivityEventData<{}>;
/**
* Event data for activity progress
*/
export type OnProgressActivityData = ActivityEventData<{ message?: string }>;
/**
* Event data for activity success
*/
export type OnSuccessActivityData = ActivityEventData<{}>;
/**
* Event data for activity failure
*/
export type OnErrorActivityData = ActivityEventData<{ error: unknown }>;