-
Notifications
You must be signed in to change notification settings - Fork 68
/
index.d.ts
2474 lines (2103 loc) · 101 KB
/
index.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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Environment } from '@azure/ms-rest-azure-env';
import type { AzExtResourceType, AzureResource, AzureSubscription, ResourceModelBase } from '@microsoft/vscode-azureresources-api';
import { AuthenticationSession, CancellationToken, CancellationTokenSource, Disposable, Event, ExtensionContext, FileChangeEvent, FileChangeType, FileStat, FileSystemProvider, FileType, InputBoxOptions, LogOutputChannel, MarkdownString, MessageItem, MessageOptions, OpenDialogOptions, OutputChannel, Progress, ProviderResult, QuickPickItem, TextDocumentShowOptions, ThemeIcon, TreeDataProvider, TreeItem, TreeItemCollapsibleState, TreeView, Uri, QuickPickOptions as VSCodeQuickPickOptions, WorkspaceFolder, WorkspaceFolderPickOptions } from 'vscode';
import { TargetPopulation } from 'vscode-tas-client';
import type { Activity, ActivityTreeItemOptions, AppResource, OnErrorActivityData, OnProgressActivityData, OnStartActivityData, OnSuccessActivityData } from './hostapi'; // This must remain `import type` or else a circular reference will result
export declare interface RunWithTemporaryDescriptionOptions {
description: string;
/**
* If true, runWithTemporaryDescription will not call refresh or refreshUIOnly on the tree item.
*/
softRefresh?: boolean;
}
/**
* Tree Data Provider for an *Az*ure *Ext*ension
*/
export declare class AzExtTreeDataProvider implements TreeDataProvider<AzExtTreeItem>, Disposable {
public onDidChangeTreeData: Event<AzExtTreeItem | undefined>;
public onTreeItemCreate: Event<AzExtTreeItem>;
/**
* Fired when a tree item is expanded, or the view is refreshed and that tree item is auto-expanded by VSCode. Note, this event cannot be accessed unless `trackTreeItemCollapsibleState` is called first!
*/
public onDidExpandOrRefreshExpandedTreeItem: Event<AzExtTreeItem>;
/**
* Azure Tree Data Provider
* @param rootTreeItem The root tree item. This item will not actually be displayed - just used to provide children.
* @param loadMoreCommandId The command your extension will register for the 'Load More...' tree item
*/
public constructor(rootTreeItem: AzExtParentTreeItem, loadMoreCommandId: string);
/**
* Should not be called directly
*/
public getTreeItem(treeItem: AzExtTreeItem): TreeItem;
/**
* Should not be called directly
*/
public getChildren(treeItem?: AzExtParentTreeItem): Promise<AzExtTreeItem[]>;
/**
* Refreshes the tree
* @param treeItem The treeItem to refresh or 'undefined' to refresh the whole tree
*/
public refresh(context: IActionContext, treeItem?: AzExtTreeItem): Promise<void>;
/**
* Refreshes only the tree UI so `refreshImpl` is not called and setCache is not set to true
* @param treeItem The treeItem to refresh or 'undefined' to refresh the whole tree
*/
public refreshUIOnly(treeItem: AzExtTreeItem | undefined): void
/**
* Loads more children for a specific tree item
* @param treeItem the load more tree item
* @param context The action context
*/
public loadMore(treeItem: AzExtTreeItem, context: IActionContext): Promise<void>;
/**
* Used to traverse the tree with a quick pick at each level. Primarily for command palette support
* @param expectedContextValues a single context value or multiple matching context values matching the desired tree items
* @param context The action context, with any additional user-defined properties that need to be passed along to `AzExtParentTreeItem.createChildImpl`
* @param startingTreeItem An optional parameter to start the picker from somewhere other than the root of the tree
*/
public showTreeItemPicker<T extends AzExtTreeItem>(expectedContextValues: string | RegExp | (string | RegExp)[], context: ITreeItemPickerContext & { canPickMany: true }, startingTreeItem?: AzExtTreeItem): Promise<T[]>;
public showTreeItemPicker<T extends AzExtTreeItem>(expectedContextValues: string | RegExp | (string | RegExp)[], context: ITreeItemPickerContext, startingTreeItem?: AzExtTreeItem): Promise<T>;
/**
* Traverses a tree to find a node matching the given fullId of a tree item
* @param fullId The full ID of the tree item
* @param context The action context
*/
public findTreeItem<T extends AzExtTreeItem>(fullId: string, context: IFindTreeItemContext): Promise<T | undefined>;
/**
* Optional method to return the parent of `element`.
* Return `null` or `undefined` if `element` is a child of root.
*
* **NOTE:** This method should be implemented in order to access [reveal](#TreeView.reveal) API.
*
* @param element The element for which the parent has to be returned.
* @return Parent of `element`.
*/
public getParent(treeItem: AzExtTreeItem): Promise<AzExtTreeItem | undefined>;
/**
* Call to track the collapsible state of tree items in the tree view.
* @param treeView The tree view to watch the collapsible state for. This must be the tree view created from this `AzExtTreeDataProvider`.
*/
public trackTreeItemCollapsibleState(treeView: TreeView<AzExtTreeItem>): Disposable;
public dispose(): void;
}
export interface ILoadingTreeContext extends IActionContext {
/**
* A custom message to overwrite the default message while loading
*/
loadingMessage?: string;
/**
* Number of seconds to delay before showing the progress message (default is 2)
* This is meant to avoid flashing a progress message in cases where it takes less than 2 seconds to load everything
*/
loadingMessageDelay?: number;
}
export interface IFindTreeItemContext extends ILoadingTreeContext {
/**
* If true, this will load all children when searching for the tree item
*/
loadAll?: boolean;
}
export interface ITreeItemPickerContext extends IActionContext {
/**
* If set to true, the last (and _only_ the last) stage of the tree item picker will show a multi-select quick pick
*/
canPickMany?: boolean;
/**
* If set to true, the 'Create new...' pick will not be displayed.
* For example, this could be used when the command deletes a tree item.
*/
suppressCreatePick?: boolean;
/**
* If set to true, the quick pick dialog will not close when focus moves out. Defaults to `true`.
*/
ignoreFocusOut?: boolean;
/**
* When no item is available for user to pick, this message will be displayed in the error notification.
* This will also suppress the report issue button.
*/
noItemFoundErrorMessage?: string;
}
/**
* Loose type to use for T2 versions of Azure credentials. The Azure Account extension returns
* credentials that will satisfy T2 requirements
*/
export type AzExtServiceClientCredentials = AzExtServiceClientCredentialsT2;
/**
* Loose interface to allow for the use of different versions of Azure SDKs
* Used specifically for T2 Azure SDKs
*/
export interface AzExtServiceClientCredentialsT2 {
/**
* Gets the token provided by this credential.
*
* This method is called automatically by Azure SDK client libraries. You may call this method
* directly, but you must also handle token caching and token refreshing.
*
* @param scopes - The list of scopes for which the token will have access.
* @param options - The options used to configure any requests this
* TokenCredential implementation might make.
*/
getToken(scopes?: string | string[], options?: any): Promise<any | null>;
}
/**
* Information specific to the Subscription
*/
export interface ISubscriptionContext {
credentials: AzExtServiceClientCredentials;
createCredentialsForScopes: (scopes: string[]) => Promise<AzExtServiceClientCredentials>;
subscriptionDisplayName: string;
subscriptionId: string;
subscriptionPath: string;
tenantId: string;
userId: string;
environment: Environment;
isCustomCloud: boolean;
}
export type TreeItemIconPath = string | Uri | { light: string | Uri; dark: string | Uri } | ThemeIcon;
/**
* AzExtTreeItem properties that can be called but should not be overridden
*/
export interface SealedAzExtTreeItem {
/**
* This id represents the effective/serializable full id of the item in the tree. It always starts with the parent's fullId and ends with either the AzExtTreeItem.id property (if implemented) or AzExtTreeItem.label property
* This is used for AzureTreeDataProvider.findTreeItem and openInPortal
*/
readonly fullId: string;
readonly parent?: AzExtParentTreeItem;
readonly treeDataProvider: AzExtTreeDataProvider;
/**
* The subscription information for this branch of the tree
* Throws an error if this branch of the tree is not actually for Azure resources
*/
readonly subscription: ISubscriptionContext;
/**
* Values to mask in error messages whenever an action uses this tree item
* NOTE: Some values are automatically masked without the need to add anything here, like the label and parts of the id if it's an Azure id
*/
readonly valuesToMask: string[];
/**
* If the `AzExtTreeDataProvider.trackTreeItemCollapsibleState` has been called, this should return the true TreeItemCollapsibleState
* Otherwise, it will return whatever initial value is given
*/
readonly collapsibleState: TreeItemCollapsibleState | undefined;
/**
* Set to true if the label of this tree item does not need to be masked
*/
suppressMaskLabel?: boolean;
/**
* Refresh this node in the tree
*/
refresh(context: IActionContext): Promise<void>;
/**
* This class wraps deleteTreeItemImpl and ensures the tree is updated correctly when an item is deleted
*/
deleteTreeItem(context: IActionContext): Promise<void>;
/**
* Displays a 'Loading...' icon and temporarily changes the item's description while `callback` is being run
*/
runWithTemporaryDescription(context: IActionContext, description: string, callback: () => Promise<void>): Promise<void>;
runWithTemporaryDescription(context: IActionContext, options: RunWithTemporaryDescriptionOptions, callback: () => Promise<void>): Promise<void>;
}
// AzExtTreeItem stuff we need them to implement
/**
* AzExtTreeItem properties that can be overridden
*/
export interface AbstractAzExtTreeItem {
id?: string;
label: string;
/**
* Additional information about a tree item that is appended to the label with the format `label (description)`
*/
description?: string;
iconPath?: TreeItemIconPath;
commandId?: string;
tooltip?: string;
initialCollapsibleState?: TreeItemCollapsibleState;
/**
* The arguments to pass in when executing `commandId`. If not specified, this tree item will be used.
*/
commandArgs?: unknown[];
contextValue: string;
/**
* Implement this to display child resources. Should not be called directly
* @param clearCache If true, you should start the "Load more..." process over
* @param context The action context
*/
loadMoreChildrenImpl?(clearCache: boolean, context: IActionContext): Promise<AzExtTreeItem[]>;
/**
* Implement this as a part of the "Load more..." action. Should not be called directly
* @returns 'true' if there are more children and a "Load more..." node should be displayed
*/
hasMoreChildrenImpl?(): boolean;
/**
* Implement this if you want the 'create' option to show up in the tree picker. Should not be called directly
* @param context The action context and any additional user-defined options that are passed to the `AzExtParentTreeItem.createChild` or `AzExtTreeDataProvider.showTreeItemPicker`
*/
createChildImpl?(context: ICreateChildImplContext): Promise<AzExtTreeItem>;
/**
* Override this if you want non-default (i.e. non-alphabetical) sorting of children. Should not be called directly
* @param item1 The first item to compare
* @param item2 The second item to compare
* @returns A negative number if the item1 occurs before item2; positive if item1 occurs after item2; 0 if they are equivalent
*/
compareChildrenImpl?(item1: AzExtTreeItem, item2: AzExtTreeItem): number;
/**
* If this treeItem should not show up in the tree picker or you want custom logic to show quick picks, implement this to provide a child that corresponds to the expectedContextValue. Should not be called directly
* Otherwise, all children will be shown in the tree picker
*/
pickTreeItemImpl?(expectedContextValues: (string | RegExp)[], context: IActionContext): AzExtTreeItem | undefined | Promise<AzExtTreeItem | undefined>;
/**
* Implement this to support the 'delete' action in the tree. Should not be called directly
*/
deleteTreeItemImpl?(context: IActionContext): Promise<void>;
/**
* Implement this to execute any async code when this node is refreshed. Should not be called directly
*/
refreshImpl?(context: IActionContext): Promise<void>;
/**
* Optional function to filter items displayed in the tree picker. Should not be called directly
* If not implemented, it's assumed that 'isAncestorOf' evaluates to true
*/
isAncestorOfImpl?(contextValue: string | RegExp): boolean;
/**
* If implemented, resolves the tooltip at the time of hovering, and the value of the `tooltip` property is ignored. Otherwise, the `tooltip` property is used.
*/
resolveTooltip?(): Promise<string | MarkdownString>;
}
export type IAzExtTreeItem = AbstractAzExtTreeItem & SealedAzExtTreeItem;
export interface IAzExtParentTreeItem extends IAzExtTreeItem {
/**
* Implement this to display child resources. Should not be called directly
* @param clearCache If true, you should start the "Load more..." process over
* @param context The action context
*/
loadMoreChildrenImpl(clearCache: boolean, context: IActionContext): Promise<AzExtTreeItem[]>;
/**
* Implement this as a part of the "Load more..." action. Should not be called directly
* @returns 'true' if there are more children and a "Load more..." node should be displayed
*/
hasMoreChildrenImpl(): boolean;
}
/**
* Base class for all tree items in an *Az*ure *ext*ension, even if those resources aren't actually in Azure.
* This provides more value than `TreeItem` (provided by `vscode`)
* NOTE: *Impl methods are not meant to be called directly - just implemented.
*/
export declare abstract class AzExtTreeItem implements IAzExtTreeItem {
//#region Properties implemented by base class
/**
* This is is used for the openInPortal action. It is also used per the following documentation copied from VS Code:
* Optional id for the treeItem that has to be unique across tree. The id is used to preserve the selection and expansion state of the treeItem.
*
* If not provided, an id is generated using the treeItem's label. **Note** that when labels change, ids will change and that selection and expansion state cannot be kept stable anymore.
*/
public set id(id: string | undefined)
public get id(): string | undefined;
public abstract label: string;
/**
* Additional information about a tree item that is appended to the label with the format `label (description)`
*/
public set description(desc: string | undefined)
public get description(): string | undefined;
public set iconPath(ip: TreeItemIconPath | undefined);
public get iconPath(): TreeItemIconPath | undefined;
public set commandId(id: string | undefined);
public get commandId(): string | undefined;
public set tooltip(tt: string | undefined);
public get tooltip(): string | undefined;
public get collapsibleState(): TreeItemCollapsibleState | undefined;
/**
* The arguments to pass in when executing `commandId`. If not specified, this tree item will be used.
*/
public commandArgs?: unknown[];
public abstract contextValue: string;
//#endregion
/**
* This id represents the effective/serializable full id of the item in the tree. It always starts with the parent's fullId and ends with either the AzExtTreeItem.id property (if implemented) or AzExtTreeItem.label property
* This is used for AzureTreeDataProvider.findTreeItem and openInPortal
*/
public readonly fullId: string;
public readonly parent?: AzExtParentTreeItem;
public readonly treeDataProvider: AzExtTreeDataProvider;
/**
* The subscription information for this branch of the tree
* Throws an error if this branch of the tree is not actually for Azure resources
*/
public get subscription(): ISubscriptionContext;
/**
* Values to mask in error messages whenever an action uses this tree item
* NOTE: Some values are automatically masked without the need to add anything here, like the label and parts of the id if it's an Azure id
*/
public readonly valuesToMask: string[];
/**
* Set to true if the label of this tree item does not need to be masked
*/
public suppressMaskLabel?: boolean;
/**
* @param parent The parent of the new tree item or 'undefined' if it is a root item
*/
public constructor(parent: AzExtParentTreeItem | undefined);
//#region Methods implemented by base class
/**
* Implement this to support the 'delete' action in the tree. Should not be called directly
*/
public deleteTreeItemImpl?(context: IActionContext): Promise<void>;
/**
* Implement this to execute any async code when this node is refreshed. Should not be called directly
*/
public refreshImpl?(context: IActionContext): Promise<void>;
/**
* Optional function to filter items displayed in the tree picker. Should not be called directly
* If not implemented, it's assumed that 'isAncestorOf' evaluates to true
*/
public isAncestorOfImpl?(contextValue: string | RegExp): boolean;
//#endregion
/**
* Refresh this node in the tree
*/
public refresh(context: IActionContext): Promise<void>;
/**
* This class wraps deleteTreeItemImpl and ensures the tree is updated correctly when an item is deleted
*/
public deleteTreeItem(context: IActionContext): Promise<void>;
/**
* Displays a 'Loading...' icon and temporarily changes the item's description while `callback` is being run
*/
public runWithTemporaryDescription(context: IActionContext, description: string, callback: () => Promise<void>): Promise<void>;
public runWithTemporaryDescription(context: IActionContext, options: RunWithTemporaryDescriptionOptions, callback: () => Promise<void>): Promise<void>;
/**
* If implemented, resolves the tooltip at the time of hovering, and the value of the `tooltip` property is ignored. Otherwise, the `tooltip` property is used.
*/
public resolveTooltip?(): Promise<string | MarkdownString>;
}
export declare function isAzExtTreeItem(maybeTreeItem: unknown): maybeTreeItem is AzExtTreeItem;
export declare function isAzExtParentTreeItem(maybeParentTreeItem: unknown): maybeParentTreeItem is AzExtParentTreeItem;
export interface GenericParentTreeItemOptions {
childTypeLabel?: string;
contextValue: string;
iconPath?: TreeItemIconPath;
initialCollapsibleState?: TreeItemCollapsibleState;
label: string;
suppressMaskLabel?: boolean;
compareChildrenImpl?(item1: AzExtTreeItem, item2: AzExtTreeItem): number;
loadMoreChildrenImpl?(clearCache: boolean, context: IActionContext): Promise<AzExtTreeItem[]>;
}
/**
* A convenience class used for very basic parent tree items
*/
export declare class GenericParentTreeItem extends AzExtParentTreeItem {
public childTypeLabel?: string;
public contextValue: string;
public label: string;
public suppressMaskLabel?: boolean;
public readonly initialCollapsibleState: TreeItemCollapsibleState;
constructor(parent: AzExtParentTreeItem | undefined, options: GenericParentTreeItemOptions);
public compareChildrenImpl(item1: AzExtTreeItem, item2: AzExtTreeItem): number;
public hasMoreChildrenImpl(): boolean;
public loadMoreChildrenImpl(clearCache: boolean, context: IActionContext): Promise<AzExtTreeItem[]>;
}
export interface IGenericTreeItemOptions {
id?: string;
label: string;
description?: string;
iconPath?: TreeItemIconPath;
commandId?: string;
contextValue: string;
/**
* If true, the tree item picker will execute `commandId`, refresh the tree, and re-prompt at the same level of the tree.
* For example, if the command is "Sign in to Azure...", this will execute a sign-in, refresh the tree, and prompt again for subscriptions.
* If `commandId` is not defined, it will throw an error.
*/
includeInTreeItemPicker?: boolean;
}
/**
* A convenience class used for very basic tree items
*/
export declare class GenericTreeItem extends AzExtTreeItem {
public label: string;
public contextValue: string;
constructor(parent: AzExtParentTreeItem | undefined, options: IGenericTreeItemOptions);
}
export interface IInvalidTreeItemOptions {
label: string;
contextValue: string;
/**
* Defaults to "Invalid" if undefined
*/
description?: string;
/**
* Any arbitrary data to include with this tree item
*/
data?: unknown;
}
export declare class InvalidTreeItem extends AzExtParentTreeItem {
public contextValue: string;
public label: string;
public get iconPath(): TreeItemIconPath;
public readonly data?: unknown;
constructor(parent: AzExtParentTreeItem, error: unknown, options: IInvalidTreeItemOptions);
public loadMoreChildrenImpl(): Promise<AzExtTreeItem[]>;
public hasMoreChildrenImpl(): boolean;
}
/**
* Base class for all parent tree items in an *Az*ure *ext*ension, even if those resources aren't actually in Azure.
* This provides more value than `TreeItem` (provided by `vscode`)
* NOTE: *Impl methods are not meant to be called directly - just implemented.
*/
export declare abstract class AzExtParentTreeItem extends AzExtTreeItem implements IAzExtParentTreeItem {
//#region Properties implemented by base class
/**
* This will be used in the tree picker prompt when selecting children
*/
childTypeLabel?: string;
/**
* If true and there is only one child node, that child will automatically be used in the tree item picker.
* Otherwise, it will prompt for a child like normal.
*/
autoSelectInTreeItemPicker?: boolean;
/**
* If true, an advanced creation pick will be shown in the tree item picker
*/
supportsAdvancedCreation?: boolean;
/**
* If specified, this will be shown instead of the default message `Create new ${this.childTypeLabel}...` in the tree item picker
*/
createNewLabel?: string;
//#endregion
/**
* Sets the initial collapsible state.
*/
public readonly initialCollapsibleState: TreeItemCollapsibleState | undefined;
//#region Methods implemented by base class
/**
* Implement this to display child resources. Should not be called directly
* @param clearCache If true, you should start the "Load more..." process over
* @param context The action context
*/
public abstract loadMoreChildrenImpl(clearCache: boolean, context: IActionContext): Promise<AzExtTreeItem[]>;
/**
* Implement this as a part of the "Load more..." action. Should not be called directly
* @returns 'true' if there are more children and a "Load more..." node should be displayed
*/
public abstract hasMoreChildrenImpl(): boolean;
/**
* Implement this if you want the 'create' option to show up in the tree picker. Should not be called directly
* @param context The action context and any additional user-defined options that are passed to the `AzExtParentTreeItem.createChild` or `AzExtTreeDataProvider.showTreeItemPicker`
*/
createChildImpl?(context: ICreateChildImplContext): Promise<AzExtTreeItem>;
/**
* Override this if you want non-default (i.e. non-alphabetical) sorting of children. Should not be called directly
* @param item1 The first item to compare
* @param item2 The second item to compare
* @returns A negative number if the item1 occurs before item2; positive if item1 occurs after item2; 0 if they are equivalent
*/
compareChildrenImpl(item1: AzExtTreeItem, item2: AzExtTreeItem): number;
/**
* If this treeItem should not show up in the tree picker or you want custom logic to show quick picks, implement this to provide a child that corresponds to the expectedContextValue. Should not be called directly
* Otherwise, all children will be shown in the tree picker
*/
pickTreeItemImpl?(expectedContextValues: (string | RegExp)[], context: IActionContext): AzExtTreeItem | undefined | Promise<AzExtTreeItem | undefined>;
//#endregion
/**
* Used to ensure a single invalid object does not prevent display of other valid objects
* Invalid objects will be shown with the error and the object's name. If the name cannot be determined for any invalid objects, a TreeItem will be added to the end with a generic label like "Some items cannot be displayed"
* @param sourceArray The collection of source objects before converting to TreeItems
* @param invalidContextValue The context value to use for invalid source objects
* @param createTreeItem A function that converts a source object to a TreeItem. Return undefined if you want this object to be skipped.
* @param getLabelOnError A minimal function that gets the label to display for an invalid source object
*/
createTreeItemsWithErrorHandling<TSource>(
sourceArray: TSource[] | undefined | null,
invalidContextValue: string,
createTreeItem: (source: TSource) => AzExtTreeItem | undefined | Promise<AzExtTreeItem | undefined>,
getLabelOnError: (source: TSource) => string | undefined | Promise<string | undefined>): Promise<AzExtTreeItem[]>;
/**
* This class wraps createChildImpl and ensures the tree is updated correctly when an item is created
* @param context The action context, with any additional user-defined properties that need to be passed along to `AzExtParentTreeItem.createChildImpl`
*/
createChild<T extends AzExtTreeItem>(context: IActionContext): Promise<T>;
/**
* Get the currently cached children for this tree item. This will load the first batch if they have not been loaded yet.
* @param context The action context
*/
getCachedChildren(context: IActionContext): Promise<AzExtTreeItem[]>;
/**
* Loads all children and displays a progress notification allowing the user to cancel.
* @throws `UserCancelledError` if the user cancels.
*/
loadAllChildren(context: ILoadingTreeContext): Promise<AzExtTreeItem[]>;
}
export interface ICreateChildImplContext extends IActionContext {
/**
* Call this function to show a "Creating..." item in the tree while the create is in progress
*/
showCreatingTreeItem(label: string): void;
/**
* Indicates advanced creation should be used
*/
advancedCreation?: boolean;
}
export declare class UserCancelledError extends Error {
constructor(stepName?: string);
}
/**
* Checks if the given error is a UserCancelledError.
*
* Note: only works with errors created by versions >=1.1.1 of this package.
*/
export declare function isUserCancelledError(error: unknown): error is UserCancelledError;
export declare class NoResourceFoundError extends Error {
constructor(context?: ITreeItemPickerContext);
}
export type CommandCallback = (context: IActionContext, ...args: any[]) => any;
/**
* Used to register VSCode commands. It wraps your callback with consistent error and telemetry handling
* Use debounce property if you need a delay between clicks for this particular command
* A telemetry event is automatically sent whenever a command is executed. The telemetry event ID will default to the same as the
* commandId passed in, but can be overridden per command with telemetryId
* The telemetry event for this command will be named telemetryId if specified, otherwise it defaults to the commandId
* NOTE: If the environment variable `DEBUGTELEMETRY` is set to a non-empty, non-zero value, then telemetry will not be sent. If the value is 'verbose' or 'v', telemetry will be displayed in the console window.
*/
export declare function registerCommand(commandId: string, callback: CommandCallback, debounce?: number, telemetryId?: string): void;
/**
* Used to register VSCode events. It wraps your callback with consistent error and telemetry handling
* NOTE #1: By default, this sends a telemetry event every single time the event fires. It it recommended to use 'context.telemetry.suppressIfSuccessful' to only send events if they apply to your extension
* NOTE #2: If the environment variable `DEBUGTELEMETRY` is set to a non-empty, non-zero value, then telemetry will not be sent. If the value is 'verbose' or 'v', telemetry will be displayed in the console window.
*/
export declare function registerEvent<T>(eventId: string, event: Event<T>, callback: (context: IActionContext, ...args: any[]) => any): void;
/**
* NOTE: If the environment variable `DEBUGTELEMETRY` is set to a non-empty, non-zero value, then telemetry will not be sent. If the value is 'verbose' or 'v', telemetry will be displayed in the console window.
*/
export declare function callWithTelemetryAndErrorHandling<T>(callbackId: string, callback: (context: IActionContext) => T | PromiseLike<T>): Promise<T | undefined>;
/**
* NOTE: If the environment variable `DEBUGTELEMETRY` is set to a non-empty, non-zero value, then telemetry will not be sent. If the value is 'verbose' or 'v', telemetry will be displayed in the console window.
*/
export declare function callWithTelemetryAndErrorHandlingSync<T>(callbackId: string, callback: (context: IActionContext) => T): T | undefined;
/**
* Used to mask values in error messages to protect user's confidential information from displaying in output and telemetry
*/
export declare function callWithMaskHandling<T>(callback: () => Promise<T>, valueToMask: string): Promise<T>;
/**
* Add an extension-wide value to mask for all commands
* This will apply to telemetry and "Report Issue", but _not_ VS Code UI (i.e. the error notification or output channel)
* IMPORTANT: For the most sensitive information, `callWithMaskHandling` should be used instead
*/
export declare function addExtensionValueToMask(...values: (string | undefined)[]): void;
/**
* A generic context object that describes the behavior of an action and allows for specifying custom telemetry properties and measurements
* You may also extend this object if you need to pass along custom properties through things like a wizard or tree item picker
*/
export interface IActionContext {
/**
* Describes the behavior of telemetry for this action
*/
telemetry: ITelemetryContext;
/**
* Describes the behavior of error handling for this action
*/
errorHandling: IErrorHandlingContext;
/**
* Custom implementation of common methods that handle user input (as opposed to using `vscode.window`)
* Provides additional functionality to support wizards, grouping, 'recently used', telemetry, etc.
* For more information, see the docs on each method and on each `options` object
*/
ui: IAzureUserInput;
/**
* Add a value to mask for this action
* This will apply to telemetry and "Report Issue", but _not_ VS Code UI (i.e. the error notification or output channel)
* IMPORTANT: For the most sensitive information, `callWithMaskHandling` should be used instead
*/
valuesToMask: string[];
}
export interface ITelemetryContext {
/**
* Custom properties that will be included in telemetry
*/
properties: TelemetryProperties;
/**
* Custom measurements that will be included in telemetry
*/
measurements: TelemetryMeasurements;
/**
* Defaults to `false`. If true, successful events are suppressed from telemetry, but cancel and error events are still sent.
*/
suppressIfSuccessful?: boolean;
/**
* Defaults to `false`. If true, all events are suppressed from telemetry.
*/
suppressAll?: boolean;
/**
* If true, any error message for this event will not be tracked in telemetry
*/
maskEntireErrorMessage?: boolean;
/**
* Will be appended to the end of the telemetry event name if specified. This is typically used when the original event has been suppressed/retired for some reason
*/
eventVersion?: number;
}
export interface AzExtErrorButton extends MessageItem {
/**
* To be called if the button is clicked
*/
callback: () => Promise<void>;
}
export interface IErrorHandlingContext {
/**
* Defaults to `false`. If true, does not display this error to the user and does not include it in the "Report Issue" command.
*/
suppressDisplay?: boolean;
/**
* Defaults to `false`. If true, re-throws error outside the context of this action.
*/
rethrow?: boolean;
/**
* Defaults to `false`. If true, does not show the "Report Issue" button in the error notification.
*/
suppressReportIssue?: boolean;
/**
* Defaults to `false`. If true, this error will be included in the "Report Issue" command regardless of `suppressDisplay`
*/
forceIncludeInReportIssueCommand?: boolean;
/**
* Additional buttons to include in error notification besides "Report an Issue"
*/
buttons?: AzExtErrorButton[];
/**
* Custom properties that will be included in any error reports generated during this action
*/
issueProperties: { [key: string]: string | undefined };
}
export interface TelemetryProperties {
/**
* Defaults to `false`
* This is used to more accurately track usage, since activation events generally shouldn't 'count' as usage
*/
isActivationEvent?: 'true' | 'false';
result?: 'Succeeded' | 'Failed' | 'Canceled';
error?: string;
errorMessage?: string;
/**
* @deprecated Specify a stepName in the constructor of `UserCancelledError` or on `AzExtUserInputOptions` instead
*/
cancelStep?: string;
/**
* The last step attempted regardless of the result of the action. Will be automatically set in most cases
*/
lastStep?: string;
[key: string]: string | undefined;
}
export interface TelemetryMeasurements {
duration?: number;
[key: string]: number | undefined;
}
export interface IHandlerContext extends IActionContext {
/**
* The id for the callback, used as the id for the telemetry event. This may be modified by any handler
*/
callbackId: string;
}
export interface IErrorHandlerContext extends IHandlerContext {
/**
* The error to be handled. This may be modified by any handler
*/
error: unknown;
}
export type ErrorHandler = (context: IErrorHandlerContext) => void;
export type TelemetryHandler = (context: IHandlerContext) => void;
export type OnActionStartHandler = (context: IHandlerContext) => void;
/**
* Register a handler to run right after an `IActionContext` is created and before the action starts
* NOTE: If more than one handler is registered, they are run in an arbitrary order.
*/
export declare function registerOnActionStartHandler(handler: OnActionStartHandler): Disposable;
/**
* Register a handler to run after a callback errors out, but before the default error handling.
* NOTE: If more than one handler is registered, they are run in an arbitrary order.
*/
export declare function registerErrorHandler(handler: ErrorHandler): Disposable;
/**
* Register a handler to run after a callback finishes, but before the default telemetry handling.
* NOTE: If more than one handler is registered, they are run in an arbitrary order.
*/
export declare function registerTelemetryHandler(handler: TelemetryHandler): Disposable;
export declare function parseError(error: any): IParsedError;
export interface IParsedError {
errorType: string;
message: string;
stack?: string;
stepName?: string;
isUserCancelledError: boolean;
}
export type PromptResult = {
value: string | QuickPickItem | QuickPickItem[] | MessageItem | Uri[] | WorkspaceFolder;
/**
* True if the user did not change from the default value, currently only supported for `showInputBox`
*/
matchesDefault?: boolean;
};
/**
* Wrapper interface of several methods that handle user input
* The implementations of this interface are accessed through `IActionContext.ui` or `TestActionContext.ui` (in the "@microsoft/vscode-azext-dev" package)
*/
export interface IAzureUserInput {
readonly onDidFinishPrompt: Event<PromptResult>;
/**
* Shows a multi-selection list.
*
* @param items An array of items, or a promise that resolves to an array of items.
* @param options Configures the behavior of the selection list.
* @throws `UserCancelledError` if the user cancels.
* @return A promise that resolves to an array of items the user picked.
*/
showQuickPick<T extends QuickPickItem>(items: T[] | Thenable<T[]>, options: IAzureQuickPickOptions & { canPickMany: true }): Promise<T[]>;
/**
* Shows a selection list.
* Automatically persists the 'recently used' item and displays that at the top of the list
*
* @param items An array of items, or a promise that resolves to an array of items.
* @param options Configures the behavior of the selection list.
* @throws `UserCancelledError` if the user cancels.
* @return A promise that resolves to the item the user picked.
*/
showQuickPick<T extends QuickPickItem>(items: T[] | Thenable<T[]>, options: IAzureQuickPickOptions): Promise<T>;
/**
* Opens an input box to ask the user for input.
*
* @param options Configures the behavior of the input box.
* @throws `UserCancelledError` if the user cancels.
* @return A promise that resolves to a string the user provided.
*/
showInputBox(options: AzExtInputBoxOptions): Promise<string>;
/**
* Show a warning message.
*
* @param message The message to show.
* @param items A set of items that will be rendered as actions in the message.
* @throws `UserCancelledError` if the user cancels.
* @return A thenable that resolves to the selected item when being dismissed.
*/
showWarningMessage<T extends MessageItem>(message: string, ...items: T[]): Promise<T>;
/**
* Show a warning message.
*
* @param message The message to show.
* @param options Configures the behavior of the message.
* @param items A set of items that will be rendered as actions in the message.
* @throws `UserCancelledError` if the user cancels.
* @return A thenable that resolves to the selected item when being dismissed.
*/
showWarningMessage<T extends MessageItem>(message: string, options: IAzureMessageOptions, ...items: T[]): Promise<T>;
/**
* Shows a file open dialog to the user which allows to select a file
* for opening-purposes.
*
* @param options Options that control the dialog.
* @throws `UserCancelledError` if the user cancels.
* @returns A promise that resolves to the selected resources.
*/
showOpenDialog(options: AzExtOpenDialogOptions): Promise<Uri[]>;
/**
* Shows a selection list of existing workspace folders to choose from.
*
* @param options Configures the behavior of the workspace folder list.
* @throws `UserCancelledError` if the user cancels.
* @returns A promise that resolves to the selected `WorkspaceFolder`.
*/
showWorkspaceFolderPick(options: AzExtWorkspaceFolderPickOptions): Promise<WorkspaceFolder>;
}
/**
* Common options used for all user input in Azure Extensions
*/
export interface AzExtUserInputOptions {
/**
* Optional step name to be used in telemetry
*/
stepName?: string;
}
/**
* Specifies the sort priority of a quick pick item
*/
export type AzureQuickPickItemPriority = 'highest' | 'normal'; // 'highest' items come before the recently used item
/**
* Provides additional options for QuickPickItems used in Azure Extensions
*/
export interface IAzureQuickPickItem<T = undefined> extends QuickPickItem {
/**
* An optional id to uniquely identify this item across sessions, used in persisting previous selections
* If not specified, a hash of the label will be used
*/
id?: string;
data: T;