Skip to content

Commit b577c12

Browse files
authored
Merge pull request #274 from aeisenberg/show-log
Add "Show log" button for all messages
2 parents 7638900 + f399da7 commit b577c12

File tree

4 files changed

+49
-21
lines changed

4 files changed

+49
-21
lines changed

extensions/ql-vscode/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CodeQL for Visual Studio Code: Changelog
22

3+
## 1.0.7
4+
5+
- Add a "Show log" button to all information, error, and warning
6+
popups that will display the CodeQL extension log.
7+
- Display a message when a query times out.
8+
- Show canceled queries in query history.
9+
310
## 1.0.6 - 28 February 2020
411

512
- Add command to restart query server.

extensions/ql-vscode/src/databases.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ export class DatabaseManager extends DisposableObject {
571571
}
572572
} catch (e) {
573573
// database list had an unexpected type - nothing to be done?
574-
showAndLogErrorMessage('Database list loading failed: ${}', e.message);
574+
showAndLogErrorMessage(`Database list loading failed: ${e.message}`);
575575
}
576576
}
577577

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: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,37 +47,59 @@ 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 function showAndLogErrorMessage(message: string, ...items: string[]): Thenable<string | undefined> {
55-
logger.log(message);
56-
return Window.showErrorMessage(message, ...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);
5760
}
5861
/**
5962
* Show a warning message and log it to the console
6063
*
6164
* @param message The message to show.
62-
* @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.
6367
*
64-
* @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.
6569
*/
66-
export function showAndLogWarningMessage(message: string, ...items: string[]): Thenable<string | undefined> {
67-
logger.log(message);
68-
return Window.showWarningMessage(message, ...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);
6975
}
7076
/**
7177
* Show an information message and log it to the console
7278
*
7379
* @param message The message to show.
74-
* @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.
7582
*
76-
* @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.
7784
*/
78-
export function showAndLogInformationMessage(message: string, ...items: string[]): Thenable<string | undefined> {
79-
logger.log(message);
80-
return Window.showInformationMessage(message, ...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);
90+
}
91+
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);
98+
const result = await fn(message, label, ...items);
99+
if (result === label) {
100+
outputLogger.show();
101+
}
102+
return result;
81103
}
82104

83105
/**

0 commit comments

Comments
 (0)