@@ -19,7 +19,7 @@ import {
1919} from "vscode" ;
2020import { CodeQLCliServer , QlpacksInfo } from "./cli" ;
2121import { UserCancellationException } from "./commandRunner" ;
22- import { extLogger } from "./common" ;
22+ import { extLogger , OutputChannelLogger } from "./common" ;
2323import { QueryMetadata } from "./pure/interface-types" ;
2424
2525// Shared temporary folder for the extension.
@@ -43,32 +43,34 @@ export const tmpDirDisposal = {
4343 } ,
4444} ;
4545
46+ interface ShowAndLogOptions {
47+ /** The output logger that will receive the message. */
48+ outputLogger ?: OutputChannelLogger ;
49+ /** A set of items that will be rendered as actions in the message. */
50+ items ?: string [ ] ;
51+ /**
52+ * An alternate message that is added to the log, but not displayed in the popup.
53+ * This is useful for adding extra detail to the logs that would be too noisy for the popup.
54+ */
55+ fullMessage ?: string ;
56+ }
57+
4658/**
4759 * Show an error message and log it to the console
4860 *
4961 * @param message The message to show.
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.
52- * @param options.fullMessage An alternate message that is added to the log, but not displayed
53- * in the popup. This is useful for adding extra detail to the logs
54- * that would be too noisy for the popup.
62+ * @param options See indivual fields on `ShowAndLogOptions` type.
5563 *
5664 * @return A promise that resolves to the selected item or undefined when being dismissed.
5765 */
5866export async function showAndLogErrorMessage (
5967 message : string ,
60- {
61- outputLogger = extLogger ,
62- items = [ ] as string [ ] ,
63- fullMessage = undefined as string | undefined ,
64- } = { } ,
68+ options ?: ShowAndLogOptions ,
6569) : Promise < string | undefined > {
6670 return internalShowAndLog (
6771 dropLinesExceptInitial ( message ) ,
68- items ,
69- outputLogger ,
7072 Window . showErrorMessage ,
71- fullMessage ,
73+ options ,
7274 ) ;
7375}
7476
@@ -80,42 +82,30 @@ function dropLinesExceptInitial(message: string, n = 2) {
8082 * Show a warning message and log it to the console
8183 *
8284 * @param message The message to show.
83- * @param options.outputLogger The output logger that will receive the message
84- * @param options.items A set of items that will be rendered as actions in the message.
85+ * @param options See indivual fields on `ShowAndLogOptions` type.
8586 *
8687 * @return A promise that resolves to the selected item or undefined when being dismissed.
8788 */
8889export async function showAndLogWarningMessage (
8990 message : string ,
90- { outputLogger = extLogger , items = [ ] as string [ ] } = { } ,
91+ options ?: ShowAndLogOptions ,
9192) : Promise < string | undefined > {
92- return internalShowAndLog (
93- message ,
94- items ,
95- outputLogger ,
96- Window . showWarningMessage ,
97- ) ;
93+ return internalShowAndLog ( message , Window . showWarningMessage , options ) ;
9894}
95+
9996/**
10097 * Show an information message and log it to the console
10198 *
10299 * @param message The message to show.
103- * @param options.outputLogger The output logger that will receive the message
104- * @param options.items A set of items that will be rendered as actions in the message.
100+ * @param options See indivual fields on `ShowAndLogOptions` type.
105101 *
106102 * @return A promise that resolves to the selected item or undefined when being dismissed.
107103 */
108104export async function showAndLogInformationMessage (
109105 message : string ,
110- { outputLogger = extLogger , items = [ ] as string [ ] , fullMessage = "" } = { } ,
106+ options ?: ShowAndLogOptions ,
111107) : Promise < string | undefined > {
112- return internalShowAndLog (
113- message ,
114- items ,
115- outputLogger ,
116- Window . showInformationMessage ,
117- fullMessage ,
118- ) ;
108+ return internalShowAndLog ( message , Window . showInformationMessage , options ) ;
119109}
120110
121111type ShowMessageFn = (
@@ -125,10 +115,8 @@ type ShowMessageFn = (
125115
126116async function internalShowAndLog (
127117 message : string ,
128- items : string [ ] ,
129- outputLogger = extLogger ,
130118 fn : ShowMessageFn ,
131- fullMessage ?: string ,
119+ { items = [ ] , outputLogger = extLogger , fullMessage } : ShowAndLogOptions = { } ,
132120) : Promise < string | undefined > {
133121 const label = "Show Log" ;
134122 void outputLogger . log ( fullMessage || message ) ;
0 commit comments