Skip to content

Commit 67c0819

Browse files
committed
Move show and log functions to common
This moves the `showAndLog` family of functions to the `common/logging` directory. It explicitly moves the `showAndLogExceptionWithTelemetry` function to the `common/vscode/logging.ts` file because it still has a dependency on the `telemetryListener`, which depends on the `vscode` module.
1 parent 9ff2d56 commit 67c0819

48 files changed

Lines changed: 101 additions & 112 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

extensions/ql-vscode/src/codeql-cli/distribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
import {
2626
showAndLogErrorMessage,
2727
showAndLogWarningMessage,
28-
} from "../common/vscode/log";
28+
} from "../common/logging";
2929

3030
/**
3131
* distribution.ts

extensions/ql-vscode/src/codeql-cli/query-language.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { isQueryLanguage, QueryLanguage } from "../common/query-language";
44
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
55
import { extLogger } from "../common";
66
import { UserCancellationException } from "../common/vscode/progress";
7-
import { showAndLogErrorMessage } from "../common/vscode/log";
7+
import { showAndLogErrorMessage } from "../common/logging";
88

99
/**
1010
* Finds the language that a query targets.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from "./logger";
22
export * from "./notification-logger";
3+
export * from "./notifications";
34
export * from "./tee-logger";
45
export * from "./vscode/loggers";
56
export * from "./vscode/output-channel-logger";

extensions/ql-vscode/src/common/vscode/log.ts renamed to extensions/ql-vscode/src/common/logging/notifications.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,13 @@
1-
import { RedactableError } from "../../pure/errors";
2-
import { telemetryListener } from "../../telemetry";
3-
import { NotificationLogger } from "../logging";
1+
import { NotificationLogger } from "./notification-logger";
42

5-
interface ShowAndLogExceptionOptions extends ShowAndLogOptions {
6-
/** Custom properties to include in the telemetry report. */
7-
extraTelemetryProperties?: { [key: string]: string };
8-
}
9-
10-
interface ShowAndLogOptions {
3+
export interface ShowAndLogOptions {
114
/**
125
* An alternate message that is added to the log, but not displayed in the popup.
136
* This is useful for adding extra detail to the logs that would be too noisy for the popup.
147
*/
158
fullMessage?: string;
169
}
1710

18-
/**
19-
* Show an error message, log it to the console, and emit redacted information as telemetry
20-
*
21-
* @param logger The logger that will receive the message.
22-
* @param error The error to show. Only redacted information will be included in the telemetry.
23-
* @param options See individual fields on `ShowAndLogExceptionOptions` type.
24-
*
25-
* @return A promise that resolves to the selected item or undefined when being dismissed.
26-
*/
27-
export async function showAndLogExceptionWithTelemetry(
28-
logger: NotificationLogger,
29-
error: RedactableError,
30-
options: ShowAndLogExceptionOptions = {},
31-
): Promise<void> {
32-
telemetryListener?.sendError(error, options.extraTelemetryProperties);
33-
return showAndLogErrorMessage(logger, error.fullMessage, options);
34-
}
35-
3611
/**
3712
* Show an error message and log it to the console
3813
*

extensions/ql-vscode/src/common/vscode/commands.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { commands, Disposable } from "vscode";
22
import { CommandFunction, CommandManager } from "../../packages/commands";
3-
import { extLogger, OutputChannelLogger } from "../logging";
3+
import {
4+
extLogger,
5+
OutputChannelLogger,
6+
showAndLogWarningMessage,
7+
} from "../logging";
48
import {
59
asError,
610
getErrorMessage,
@@ -9,10 +13,7 @@ import {
913
import { redactableError } from "../../pure/errors";
1014
import { UserCancellationException } from "./progress";
1115
import { telemetryListener } from "../../telemetry";
12-
import {
13-
showAndLogExceptionWithTelemetry,
14-
showAndLogWarningMessage,
15-
} from "./log";
16+
import { showAndLogExceptionWithTelemetry } from "./logging";
1617

1718
/**
1819
* Create a command manager for VSCode, wrapping registerCommandWithErrorHandling

extensions/ql-vscode/src/common/vscode/external-files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
getErrorMessage,
88
getErrorStack,
99
} from "../../pure/helpers-pure";
10-
import { showAndLogExceptionWithTelemetry } from "./log";
1110
import { extLogger } from "../logging";
11+
import { showAndLogExceptionWithTelemetry } from "./logging";
1212

1313
export async function tryOpenExternalFile(
1414
commandManager: AppCommandManager,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {
2+
NotificationLogger,
3+
showAndLogErrorMessage,
4+
ShowAndLogOptions,
5+
} from "../logging";
6+
import { RedactableError } from "../../pure/errors";
7+
import { telemetryListener } from "../../telemetry";
8+
9+
interface ShowAndLogExceptionOptions extends ShowAndLogOptions {
10+
/** Custom properties to include in the telemetry report. */
11+
extraTelemetryProperties?: { [key: string]: string };
12+
}
13+
14+
/**
15+
* Show an error message, log it to the console, and emit redacted information as telemetry
16+
*
17+
* @param logger The logger that will receive the message.
18+
* @param error The error to show. Only redacted information will be included in the telemetry.
19+
* @param options See individual fields on `ShowAndLogExceptionOptions` type.
20+
*
21+
* @return A promise that resolves to the selected item or undefined when being dismissed.
22+
*/
23+
export async function showAndLogExceptionWithTelemetry(
24+
logger: NotificationLogger,
25+
error: RedactableError,
26+
options: ShowAndLogExceptionOptions = {},
27+
): Promise<void> {
28+
telemetryListener?.sendError(error, options.extraTelemetryProperties);
29+
return showAndLogErrorMessage(logger, error.fullMessage, options);
30+
}

extensions/ql-vscode/src/common/vscode/selection-commands.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {
33
TreeViewContextMultiSelectionCommandFunction,
44
TreeViewContextSingleSelectionCommandFunction,
55
} from "../commands";
6-
import { showAndLogErrorMessage } from "./log";
7-
import { extLogger } from "../logging";
6+
import { showAndLogErrorMessage, extLogger } from "../logging";
87

98
// A hack to match types that are not an array, which is useful to help avoid
109
// misusing createSingleSelectionCommand, e.g. where T accidentally gets instantiated

extensions/ql-vscode/src/compare/compare-view.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
QueryCompareResult,
77
} from "../pure/interface-types";
88
import { extLogger, Logger } from "../common";
9+
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
910
import { CodeQLCliServer } from "../codeql-cli/cli";
1011
import { DatabaseManager } from "../databases/local-databases";
1112
import { jumpToLocation } from "../databases/local-databases/locations";
@@ -25,8 +26,6 @@ import {
2526
import { telemetryListener } from "../telemetry";
2627
import { redactableError } from "../pure/errors";
2728

28-
import { showAndLogExceptionWithTelemetry } from "../common/vscode/log";
29-
3029
interface ComparePair {
3130
from: CompletedLocalQueryInfo;
3231
to: CompletedLocalQueryInfo;

extensions/ql-vscode/src/data-extensions-editor/data-extensions-editor-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { join } from "path";
99
import { App } from "../common/app";
1010
import { withProgress } from "../common/vscode/progress";
1111
import { pickExtensionPackModelFile } from "./extension-pack-picker";
12-
import { showAndLogErrorMessage } from "../common/vscode/log";
12+
import { showAndLogErrorMessage } from "../common/logging";
1313
import { extLogger } from "../common";
1414

1515
const SUPPORTED_LANGUAGES: string[] = ["java", "csharp"];

0 commit comments

Comments
 (0)