1- import { window } from "vscode" ;
21import { RedactableError } from "../../pure/errors" ;
32import { telemetryListener } from "../../telemetry" ;
4- import { extLogger , OutputChannelLogger } from "../logging" ;
3+ import { NotificationLogger } from "../logging" ;
54
65interface ShowAndLogExceptionOptions extends ShowAndLogOptions {
76 /** Custom properties to include in the telemetry report. */
87 extraTelemetryProperties ?: { [ key : string ] : string } ;
98}
109
1110interface ShowAndLogOptions {
12- /** The output logger that will receive the message. */
13- outputLogger ?: OutputChannelLogger ;
14- /** A set of items that will be rendered as actions in the message. */
15- items ?: string [ ] ;
1611 /**
1712 * An alternate message that is added to the log, but not displayed in the popup.
1813 * This is useful for adding extra detail to the logs that would be too noisy for the popup.
@@ -23,34 +18,39 @@ interface ShowAndLogOptions {
2318/**
2419 * Show an error message, log it to the console, and emit redacted information as telemetry
2520 *
21+ * @param logger The logger that will receive the message.
2622 * @param error The error to show. Only redacted information will be included in the telemetry.
2723 * @param options See individual fields on `ShowAndLogExceptionOptions` type.
2824 *
2925 * @return A promise that resolves to the selected item or undefined when being dismissed.
3026 */
3127export async function showAndLogExceptionWithTelemetry (
28+ logger : NotificationLogger ,
3229 error : RedactableError ,
3330 options : ShowAndLogExceptionOptions = { } ,
34- ) : Promise < string | undefined > {
31+ ) : Promise < void > {
3532 telemetryListener ?. sendError ( error , options . extraTelemetryProperties ) ;
36- return showAndLogErrorMessage ( error . fullMessage , options ) ;
33+ return showAndLogErrorMessage ( logger , error . fullMessage , options ) ;
3734}
3835
3936/**
4037 * Show an error message and log it to the console
4138 *
39+ * @param logger The logger that will receive the message.
4240 * @param message The message to show.
43- * @param options See individual fields on `ShowAndLogOptions` type.
41+ * @param options? See individual fields on `ShowAndLogOptions` type.
4442 *
4543 * @return A promise that resolves to the selected item or undefined when being dismissed.
4644 */
4745export async function showAndLogErrorMessage (
46+ logger : NotificationLogger ,
4847 message : string ,
4948 options ?: ShowAndLogOptions ,
50- ) : Promise < string | undefined > {
49+ ) : Promise < void > {
5150 return internalShowAndLog (
51+ logger ,
5252 dropLinesExceptInitial ( message ) ,
53- window . showErrorMessage ,
53+ logger . showErrorMessage ,
5454 { fullMessage : message , ...options } ,
5555 ) ;
5656}
@@ -62,48 +62,53 @@ function dropLinesExceptInitial(message: string, n = 2) {
6262/**
6363 * Show a warning message and log it to the console
6464 *
65+ * @param logger The logger that will receive the message.
6566 * @param message The message to show.
66- * @param options See individual fields on `ShowAndLogOptions` type.
67+ * @param options? See individual fields on `ShowAndLogOptions` type.
6768 *
6869 * @return A promise that resolves to the selected item or undefined when being dismissed.
6970 */
7071export async function showAndLogWarningMessage (
72+ logger : NotificationLogger ,
7173 message : string ,
7274 options ?: ShowAndLogOptions ,
73- ) : Promise < string | undefined > {
74- return internalShowAndLog ( message , window . showWarningMessage , options ) ;
75+ ) : Promise < void > {
76+ return internalShowAndLog (
77+ logger ,
78+ message ,
79+ logger . showWarningMessage ,
80+ options ,
81+ ) ;
7582}
7683
7784/**
7885 * Show an information message and log it to the console
7986 *
87+ * @param logger The logger that will receive the message.
8088 * @param message The message to show.
81- * @param options See individual fields on `ShowAndLogOptions` type.
89+ * @param options? See individual fields on `ShowAndLogOptions` type.
8290 *
8391 * @return A promise that resolves to the selected item or undefined when being dismissed.
8492 */
8593export async function showAndLogInformationMessage (
94+ logger : NotificationLogger ,
8695 message : string ,
8796 options ?: ShowAndLogOptions ,
88- ) : Promise < string | undefined > {
89- return internalShowAndLog ( message , window . showInformationMessage , options ) ;
97+ ) : Promise < void > {
98+ return internalShowAndLog (
99+ logger ,
100+ message ,
101+ logger . showInformationMessage ,
102+ options ,
103+ ) ;
90104}
91105
92- type ShowMessageFn = (
93- message : string ,
94- ...items : string [ ]
95- ) => Thenable < string | undefined > ;
96-
97106async function internalShowAndLog (
107+ logger : NotificationLogger ,
98108 message : string ,
99- fn : ShowMessageFn ,
100- { items = [ ] , outputLogger = extLogger , fullMessage } : ShowAndLogOptions = { } ,
101- ) : Promise < string | undefined > {
102- const label = "Show Log" ;
103- void outputLogger . log ( fullMessage || message ) ;
104- const result = await fn ( message , label , ...items ) ;
105- if ( result === label ) {
106- outputLogger . show ( ) ;
107- }
108- return result ;
109+ fn : ( message : string ) => Promise < void > ,
110+ { fullMessage } : ShowAndLogOptions = { } ,
111+ ) : Promise < void > {
112+ void logger . log ( fullMessage || message ) ;
113+ await fn . bind ( logger ) ( message ) ;
109114}
0 commit comments