@@ -47,42 +47,57 @@ export function withProgress<R>(
4747 * Show an error message and log it to the console
4848 *
4949 * @param message The message to show.
50- * @param items A set of items that will be rendered as actions in the message.
50+ * @param options.outputLogger The output logger that will receive the message
51+ * @param options.items A set of items that will be rendered as actions in the message.
5152 *
52- * @return A thenable that resolves to the selected item or undefined when being dismissed.
53+ * @return A promise that resolves to the selected item or undefined when being dismissed.
5354 */
54- export async function showAndLogErrorMessage ( message : string , ...items : string [ ] ) : Promise < string | undefined > {
55- return internalShowAndLog ( message , Window . showErrorMessage , ...items ) ;
55+ export async function showAndLogErrorMessage ( message : string , {
56+ outputLogger = logger ,
57+ items = [ ] as string [ ]
58+ } = { } ) : Promise < string | undefined > {
59+ return internalShowAndLog ( message , items , outputLogger , Window . showErrorMessage ) ;
5660}
5761/**
5862 * Show a warning message and log it to the console
5963 *
6064 * @param message The message to show.
61- * @param items A set of items that will be rendered as actions in the message.
65+ * @param options.outputLogger The output logger that will receive the message
66+ * @param options.items A set of items that will be rendered as actions in the message.
6267 *
63- * @return A thenable that resolves to the selected item or undefined when being dismissed.
68+ * @return A promise that resolves to the selected item or undefined when being dismissed.
6469 */
65- export async function showAndLogWarningMessage ( message : string , ...items : string [ ] ) : Promise < string | undefined > {
66- return internalShowAndLog ( message , Window . showWarningMessage , ...items ) ;
70+ export async function showAndLogWarningMessage ( message : string , {
71+ outputLogger = logger ,
72+ items = [ ] as string [ ]
73+ } = { } ) : Promise < string | undefined > {
74+ return internalShowAndLog ( message , items , outputLogger , Window . showWarningMessage ) ;
6775}
6876/**
6977 * Show an information message and log it to the console
7078 *
7179 * @param message The message to show.
72- * @param items A set of items that will be rendered as actions in the message.
80+ * @param options.outputLogger The output logger that will receive the message
81+ * @param options.items A set of items that will be rendered as actions in the message.
7382 *
74- * @return A thenable that resolves to the selected item or undefined when being dismissed.
83+ * @return A promise that resolves to the selected item or undefined when being dismissed.
7584 */
76- export async function showAndLogInformationMessage ( message : string , ...items : string [ ] ) : Promise < string | undefined > {
77- return internalShowAndLog ( message , Window . showInformationMessage , ...items ) ;
85+ export async function showAndLogInformationMessage ( message : string , {
86+ outputLogger = logger ,
87+ items = [ ] as string [ ]
88+ } = { } ) : Promise < string | undefined > {
89+ return internalShowAndLog ( message , items , outputLogger , Window . showInformationMessage ) ;
7890}
7991
80- async function internalShowAndLog ( message : string , fn : Function , ...items : string [ ] ) : Promise < string | undefined > {
81- logger . log ( message ) ;
82- const label = 'Show log' ;
92+ type ShowMessageFn = ( message : string , ...items : string [ ] ) => Thenable < string | undefined > ;
93+
94+ async function internalShowAndLog ( message : string , items : string [ ] , outputLogger = logger ,
95+ fn : ShowMessageFn ) : Promise < string | undefined > {
96+ const label = 'Show Log' ;
97+ outputLogger . log ( message ) ;
8398 const result = await fn ( message , label , ...items ) ;
8499 if ( result === label ) {
85- logger . show ( ) ;
100+ outputLogger . show ( ) ;
86101 }
87102 return result ;
88103}
0 commit comments