@@ -47,37 +47,59 @@ 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 function showAndLogErrorMessage ( message : string , ...items : string [ ] ) : Thenable < string | undefined > {
55- logger . log ( message ) ;
56- return Window . showErrorMessage ( message , ...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 ) ;
5760}
5861/**
5962 * Show a warning message and log it to the console
6063 *
6164 * @param message The message to show.
62- * @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.
6367 *
64- * @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.
6569 */
66- export function showAndLogWarningMessage ( message : string , ...items : string [ ] ) : Thenable < string | undefined > {
67- logger . log ( message ) ;
68- return Window . showWarningMessage ( message , ...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 ) ;
6975}
7076/**
7177 * Show an information message and log it to the console
7278 *
7379 * @param message The message to show.
74- * @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.
7582 *
76- * @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.
7784 */
78- export function showAndLogInformationMessage ( message : string , ...items : string [ ] ) : Thenable < string | undefined > {
79- logger . log ( message ) ;
80- return Window . showInformationMessage ( message , ...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 ) ;
90+ }
91+
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 ) ;
98+ const result = await fn ( message , label , ...items ) ;
99+ if ( result === label ) {
100+ outputLogger . show ( ) ;
101+ }
102+ return result ;
81103}
82104
83105/**
0 commit comments