From 84144157e786ac70bbd4131dd324a34fc2c560da Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Mon, 9 Mar 2020 11:39:10 -0700 Subject: [PATCH 1/3] Add "Show log" button for all messages This change ensures that "Show log" is available on all messages from the extension. It's important to note that the only place that was specifying an "item" before was doing it incorrectly. That's been fixed. Closes #287 --- extensions/ql-vscode/src/databases.ts | 2 +- extensions/ql-vscode/src/helpers.ts | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/extensions/ql-vscode/src/databases.ts b/extensions/ql-vscode/src/databases.ts index 5ddda564a87..15d3e60f45e 100644 --- a/extensions/ql-vscode/src/databases.ts +++ b/extensions/ql-vscode/src/databases.ts @@ -571,7 +571,7 @@ export class DatabaseManager extends DisposableObject { } } catch (e) { // database list had an unexpected type - nothing to be done? - showAndLogErrorMessage('Database list loading failed: ${}', e.message); + showAndLogErrorMessage(`Database list loading failed: ${e.message}`); } } diff --git a/extensions/ql-vscode/src/helpers.ts b/extensions/ql-vscode/src/helpers.ts index 17c8b70fbd1..26e90f13013 100644 --- a/extensions/ql-vscode/src/helpers.ts +++ b/extensions/ql-vscode/src/helpers.ts @@ -51,9 +51,8 @@ export function withProgress( * * @return A thenable that resolves to the selected item or undefined when being dismissed. */ -export function showAndLogErrorMessage(message: string, ...items: string[]): Thenable { - logger.log(message); - return Window.showErrorMessage(message, ...items); +export async function showAndLogErrorMessage(message: string, ...items: string[]): Promise { + return internalShowAndLog(message, Window.showErrorMessage, ...items); } /** * Show a warning message and log it to the console @@ -63,9 +62,8 @@ export function showAndLogErrorMessage(message: string, ...items: string[]): The * * @return A thenable that resolves to the selected item or undefined when being dismissed. */ -export function showAndLogWarningMessage(message: string, ...items: string[]): Thenable { - logger.log(message); - return Window.showWarningMessage(message, ...items); +export async function showAndLogWarningMessage(message: string, ...items: string[]): Promise { + return internalShowAndLog(message, Window.showWarningMessage, ...items); } /** * Show an information message and log it to the console @@ -75,9 +73,18 @@ export function showAndLogWarningMessage(message: string, ...items: string[]): T * * @return A thenable that resolves to the selected item or undefined when being dismissed. */ -export function showAndLogInformationMessage(message: string, ...items: string[]): Thenable { +export async function showAndLogInformationMessage(message: string, ...items: string[]): Promise { + return internalShowAndLog(message, Window.showInformationMessage, ...items); +} + +async function internalShowAndLog(message: string, fn: Function, ...items: string[]): Promise { logger.log(message); - return Window.showInformationMessage(message, ...items); + const label = 'Show log'; + const result = await fn(message, label, ...items); + if (result === label) { + logger.show(); + } + return result; } /** From a2a2aafa98bd432d5ba0e4a49e055228c759d13f Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Mon, 9 Mar 2020 11:47:08 -0700 Subject: [PATCH 2/3] Update changelog --- extensions/ql-vscode/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index 7df629fd58f..1a024d3395c 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -1,5 +1,12 @@ # CodeQL for Visual Studio Code: Changelog +## 1.0.7 + +- Add a "Show log" button to all information, error, and warning + popups that will display the CodeQL extension log. +- Display a message when a query times out. +- Show canceled queries in query history. + ## 1.0.6 - 28 February 2020 - Add command to restart query server. From f399da75d013cd8040c50e21aa97b7379c5cda1e Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Mon, 9 Mar 2020 13:25:29 -0700 Subject: [PATCH 3/3] Migrate to using showAndLogInformationMessage Also, changes the showAndLog* signatures to accept an optional logger argument. --- extensions/ql-vscode/src/extension.ts | 9 +++-- extensions/ql-vscode/src/helpers.ts | 47 ++++++++++++++++++--------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/extensions/ql-vscode/src/extension.ts b/extensions/ql-vscode/src/extension.ts index 1c6e6957fb0..847c2e9e8fe 100644 --- a/extensions/ql-vscode/src/extension.ts +++ b/extensions/ql-vscode/src/extension.ts @@ -201,7 +201,9 @@ export async function activate(ctx: ExtensionContext): Promise { } else if (distributionResult.kind === FindDistributionResultKind.NoDistribution) { registerErrorStubs([checkForUpdatesCommand], command => async () => { const installActionName = "Install CodeQL CLI"; - const chosenAction = await helpers.showAndLogErrorMessage(`Can't execute ${command}: missing CodeQL CLI.`, installActionName); + const chosenAction = await helpers.showAndLogErrorMessage(`Can't execute ${command}: missing CodeQL CLI.`, { + items: [installActionName] + }); if (chosenAction === installActionName) { installOrUpdateThenTryActivate({ isUserInitiated: true, @@ -319,10 +321,7 @@ async function activateWithInstalledDistribution(ctx: ExtensionContext, distribu ctx.subscriptions.push(commands.registerCommand('codeQL.quickQuery', async () => displayQuickQuery(ctx, cliServer, databaseUI))); ctx.subscriptions.push(commands.registerCommand('codeQL.restartQueryServer', async () => { await qs.restartQueryServer(); - const response = await Window.showInformationMessage('CodeQL Query Server restarted.', 'Show Log'); - if (response === 'Show Log') { - qs.showLog(); - } + helpers.showAndLogInformationMessage('CodeQL Query Server restarted.', { outputLogger: queryServerLogger }); })); ctx.subscriptions.push(client.start()); diff --git a/extensions/ql-vscode/src/helpers.ts b/extensions/ql-vscode/src/helpers.ts index 26e90f13013..c9285067b5e 100644 --- a/extensions/ql-vscode/src/helpers.ts +++ b/extensions/ql-vscode/src/helpers.ts @@ -47,42 +47,57 @@ export function withProgress( * Show an error message and log it to the console * * @param message The message to show. - * @param items A set of items that will be rendered as actions in the message. + * @param options.outputLogger The output logger that will receive the message + * @param options.items A set of items that will be rendered as actions in the message. * - * @return A thenable that resolves to the selected item or undefined when being dismissed. + * @return A promise that resolves to the selected item or undefined when being dismissed. */ -export async function showAndLogErrorMessage(message: string, ...items: string[]): Promise { - return internalShowAndLog(message, Window.showErrorMessage, ...items); +export async function showAndLogErrorMessage(message: string, { + outputLogger = logger, + items = [] as string[] +} = {}): Promise { + return internalShowAndLog(message, items, outputLogger, Window.showErrorMessage); } /** * Show a warning message and log it to the console * * @param message The message to show. - * @param items A set of items that will be rendered as actions in the message. + * @param options.outputLogger The output logger that will receive the message + * @param options.items A set of items that will be rendered as actions in the message. * - * @return A thenable that resolves to the selected item or undefined when being dismissed. + * @return A promise that resolves to the selected item or undefined when being dismissed. */ -export async function showAndLogWarningMessage(message: string, ...items: string[]): Promise { - return internalShowAndLog(message, Window.showWarningMessage, ...items); +export async function showAndLogWarningMessage(message: string, { + outputLogger = logger, + items = [] as string[] +} = {}): Promise { + return internalShowAndLog(message, items, outputLogger, Window.showWarningMessage); } /** * Show an information message and log it to the console * * @param message The message to show. - * @param items A set of items that will be rendered as actions in the message. + * @param options.outputLogger The output logger that will receive the message + * @param options.items A set of items that will be rendered as actions in the message. * - * @return A thenable that resolves to the selected item or undefined when being dismissed. + * @return A promise that resolves to the selected item or undefined when being dismissed. */ -export async function showAndLogInformationMessage(message: string, ...items: string[]): Promise { - return internalShowAndLog(message, Window.showInformationMessage, ...items); +export async function showAndLogInformationMessage(message: string, { + outputLogger = logger, + items = [] as string[] +} = {}): Promise { + return internalShowAndLog(message, items, outputLogger, Window.showInformationMessage); } -async function internalShowAndLog(message: string, fn: Function, ...items: string[]): Promise { - logger.log(message); - const label = 'Show log'; +type ShowMessageFn = (message: string, ...items: string[]) => Thenable; + +async function internalShowAndLog(message: string, items: string[], outputLogger = logger, + fn: ShowMessageFn): Promise { + const label = 'Show Log'; + outputLogger.log(message); const result = await fn(message, label, ...items); if (result === label) { - logger.show(); + outputLogger.show(); } return result; }