Skip to content

Commit f399da7

Browse files
committed
Migrate to using showAndLogInformationMessage
Also, changes the showAndLog* signatures to accept an optional logger argument.
1 parent a2a2aaf commit f399da7

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

extensions/ql-vscode/src/extension.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
201201
} else if (distributionResult.kind === FindDistributionResultKind.NoDistribution) {
202202
registerErrorStubs([checkForUpdatesCommand], command => async () => {
203203
const installActionName = "Install CodeQL CLI";
204-
const chosenAction = await helpers.showAndLogErrorMessage(`Can't execute ${command}: missing CodeQL CLI.`, installActionName);
204+
const chosenAction = await helpers.showAndLogErrorMessage(`Can't execute ${command}: missing CodeQL CLI.`, {
205+
items: [installActionName]
206+
});
205207
if (chosenAction === installActionName) {
206208
installOrUpdateThenTryActivate({
207209
isUserInitiated: true,
@@ -319,10 +321,7 @@ async function activateWithInstalledDistribution(ctx: ExtensionContext, distribu
319321
ctx.subscriptions.push(commands.registerCommand('codeQL.quickQuery', async () => displayQuickQuery(ctx, cliServer, databaseUI)));
320322
ctx.subscriptions.push(commands.registerCommand('codeQL.restartQueryServer', async () => {
321323
await qs.restartQueryServer();
322-
const response = await Window.showInformationMessage('CodeQL Query Server restarted.', 'Show Log');
323-
if (response === 'Show Log') {
324-
qs.showLog();
325-
}
324+
helpers.showAndLogInformationMessage('CodeQL Query Server restarted.', { outputLogger: queryServerLogger });
326325
}));
327326

328327
ctx.subscriptions.push(client.start());

extensions/ql-vscode/src/helpers.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)