Merge pull request #2010 from github/robertbrignull/logging_types
Introduce ShowAndLogOptions
This commit is contained in:
Коммит
07f5d2b20d
|
@ -19,7 +19,7 @@ import {
|
|||
} from "vscode";
|
||||
import { CodeQLCliServer, QlpacksInfo } from "./cli";
|
||||
import { UserCancellationException } from "./commandRunner";
|
||||
import { extLogger } from "./common";
|
||||
import { extLogger, OutputChannelLogger } from "./common";
|
||||
import { QueryMetadata } from "./pure/interface-types";
|
||||
|
||||
// Shared temporary folder for the extension.
|
||||
|
@ -43,32 +43,34 @@ export const tmpDirDisposal = {
|
|||
},
|
||||
};
|
||||
|
||||
interface ShowAndLogOptions {
|
||||
/** The output logger that will receive the message. */
|
||||
outputLogger?: OutputChannelLogger;
|
||||
/** A set of items that will be rendered as actions in the message. */
|
||||
items?: string[];
|
||||
/**
|
||||
* An alternate message that is added to the log, but not displayed in the popup.
|
||||
* This is useful for adding extra detail to the logs that would be too noisy for the popup.
|
||||
*/
|
||||
fullMessage?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an error message and log it to the console
|
||||
*
|
||||
* @param message The message to show.
|
||||
* @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.
|
||||
* @param options.fullMessage An alternate message that is added to the log, but not displayed
|
||||
* in the popup. This is useful for adding extra detail to the logs
|
||||
* that would be too noisy for the popup.
|
||||
* @param options See indivual fields on `ShowAndLogOptions` type.
|
||||
*
|
||||
* @return A promise that resolves to the selected item or undefined when being dismissed.
|
||||
*/
|
||||
export async function showAndLogErrorMessage(
|
||||
message: string,
|
||||
{
|
||||
outputLogger = extLogger,
|
||||
items = [] as string[],
|
||||
fullMessage = undefined as string | undefined,
|
||||
} = {},
|
||||
options?: ShowAndLogOptions,
|
||||
): Promise<string | undefined> {
|
||||
return internalShowAndLog(
|
||||
dropLinesExceptInitial(message),
|
||||
items,
|
||||
outputLogger,
|
||||
Window.showErrorMessage,
|
||||
fullMessage,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -80,42 +82,30 @@ function dropLinesExceptInitial(message: string, n = 2) {
|
|||
* Show a warning message and log it to the console
|
||||
*
|
||||
* @param message The message to show.
|
||||
* @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.
|
||||
* @param options See indivual fields on `ShowAndLogOptions` type.
|
||||
*
|
||||
* @return A promise that resolves to the selected item or undefined when being dismissed.
|
||||
*/
|
||||
export async function showAndLogWarningMessage(
|
||||
message: string,
|
||||
{ outputLogger = extLogger, items = [] as string[] } = {},
|
||||
options?: ShowAndLogOptions,
|
||||
): Promise<string | undefined> {
|
||||
return internalShowAndLog(
|
||||
message,
|
||||
items,
|
||||
outputLogger,
|
||||
Window.showWarningMessage,
|
||||
);
|
||||
return internalShowAndLog(message, Window.showWarningMessage, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an information message and log it to the console
|
||||
*
|
||||
* @param message The message to show.
|
||||
* @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.
|
||||
* @param options See indivual fields on `ShowAndLogOptions` type.
|
||||
*
|
||||
* @return A promise that resolves to the selected item or undefined when being dismissed.
|
||||
*/
|
||||
export async function showAndLogInformationMessage(
|
||||
message: string,
|
||||
{ outputLogger = extLogger, items = [] as string[], fullMessage = "" } = {},
|
||||
options?: ShowAndLogOptions,
|
||||
): Promise<string | undefined> {
|
||||
return internalShowAndLog(
|
||||
message,
|
||||
items,
|
||||
outputLogger,
|
||||
Window.showInformationMessage,
|
||||
fullMessage,
|
||||
);
|
||||
return internalShowAndLog(message, Window.showInformationMessage, options);
|
||||
}
|
||||
|
||||
type ShowMessageFn = (
|
||||
|
@ -125,10 +115,8 @@ type ShowMessageFn = (
|
|||
|
||||
async function internalShowAndLog(
|
||||
message: string,
|
||||
items: string[],
|
||||
outputLogger = extLogger,
|
||||
fn: ShowMessageFn,
|
||||
fullMessage?: string,
|
||||
{ items = [], outputLogger = extLogger, fullMessage }: ShowAndLogOptions = {},
|
||||
): Promise<string | undefined> {
|
||||
const label = "Show Log";
|
||||
void outputLogger.log(fullMessage || message);
|
||||
|
|
Загрузка…
Ссылка в новой задаче