Skip to content

Commit de640e3

Browse files
Introduce ShowAndLogOptions
1 parent ca1d63a commit de640e3

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

extensions/ql-vscode/src/helpers.ts

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from "vscode";
2020
import { CodeQLCliServer, QlpacksInfo } from "./cli";
2121
import { UserCancellationException } from "./commandRunner";
22-
import { extLogger } from "./common";
22+
import { extLogger, OutputChannelLogger } from "./common";
2323
import { QueryMetadata } from "./pure/interface-types";
2424

2525
// Shared temporary folder for the extension.
@@ -43,6 +43,12 @@ export const tmpDirDisposal = {
4343
},
4444
};
4545

46+
interface ShowAndLogOptions {
47+
outputLogger?: OutputChannelLogger;
48+
items?: string[];
49+
fullMessage?: string;
50+
}
51+
4652
/**
4753
* Show an error message and log it to the console
4854
*
@@ -57,18 +63,12 @@ export const tmpDirDisposal = {
5763
*/
5864
export async function showAndLogErrorMessage(
5965
message: string,
60-
{
61-
outputLogger = extLogger,
62-
items = [] as string[],
63-
fullMessage = undefined as string | undefined,
64-
} = {},
66+
options?: ShowAndLogOptions,
6567
): Promise<string | undefined> {
6668
return internalShowAndLog(
6769
dropLinesExceptInitial(message),
68-
items,
69-
outputLogger,
7070
Window.showErrorMessage,
71-
fullMessage,
71+
options,
7272
);
7373
}
7474

@@ -82,40 +82,36 @@ function dropLinesExceptInitial(message: string, n = 2) {
8282
* @param message The message to show.
8383
* @param options.outputLogger The output logger that will receive the message
8484
* @param options.items A set of items that will be rendered as actions in the message.
85+
* @param options.fullMessage An alternate message that is added to the log, but not displayed
86+
* in the popup. This is useful for adding extra detail to the logs
87+
* that would be too noisy for the popup.
8588
*
8689
* @return A promise that resolves to the selected item or undefined when being dismissed.
8790
*/
8891
export async function showAndLogWarningMessage(
8992
message: string,
90-
{ outputLogger = extLogger, items = [] as string[] } = {},
93+
options?: ShowAndLogOptions,
9194
): Promise<string | undefined> {
92-
return internalShowAndLog(
93-
message,
94-
items,
95-
outputLogger,
96-
Window.showWarningMessage,
97-
);
95+
return internalShowAndLog(message, Window.showWarningMessage, options);
9896
}
97+
9998
/**
10099
* Show an information message and log it to the console
101100
*
102101
* @param message The message to show.
103102
* @param options.outputLogger The output logger that will receive the message
104103
* @param options.items A set of items that will be rendered as actions in the message.
104+
* @param options.fullMessage An alternate message that is added to the log, but not displayed
105+
* in the popup. This is useful for adding extra detail to the logs
106+
* that would be too noisy for the popup.
105107
*
106108
* @return A promise that resolves to the selected item or undefined when being dismissed.
107109
*/
108110
export async function showAndLogInformationMessage(
109111
message: string,
110-
{ outputLogger = extLogger, items = [] as string[], fullMessage = "" } = {},
112+
options?: ShowAndLogOptions,
111113
): Promise<string | undefined> {
112-
return internalShowAndLog(
113-
message,
114-
items,
115-
outputLogger,
116-
Window.showInformationMessage,
117-
fullMessage,
118-
);
114+
return internalShowAndLog(message, Window.showInformationMessage, options);
119115
}
120116

121117
type ShowMessageFn = (
@@ -125,10 +121,8 @@ type ShowMessageFn = (
125121

126122
async function internalShowAndLog(
127123
message: string,
128-
items: string[],
129-
outputLogger = extLogger,
130124
fn: ShowMessageFn,
131-
fullMessage?: string,
125+
{ items = [], outputLogger = extLogger, fullMessage }: ShowAndLogOptions = {},
132126
): Promise<string | undefined> {
133127
const label = "Show Log";
134128
void outputLogger.log(fullMessage || message);

0 commit comments

Comments
 (0)