Skip to content

Commit b3003fc

Browse files
committed
Merge remote-tracking branch 'origin/main' into koesie10/load-results-tests
2 parents 2b9bff1 + 125867d commit b3003fc

46 files changed

Lines changed: 380 additions & 272 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/archive-filesystem-provider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from "fs-extra";
22
import * as unzipper from "unzipper";
33
import * as vscode from "vscode";
4-
import { logger } from "./common";
4+
import { extLogger } from "./common";
55

66
// All path operations in this file must be on paths *within* the zip
77
// archive.
@@ -118,7 +118,7 @@ class InvalidSourceArchiveUriError extends Error {
118118
export function decodeSourceArchiveUri(uri: vscode.Uri): ZipFileReference {
119119
if (!uri.authority) {
120120
// Uri is malformed, but this is recoverable
121-
void logger.log(
121+
void extLogger.log(
122122
`Warning: ${new InvalidSourceArchiveUriError(uri).message}`,
123123
);
124124
return {
@@ -148,7 +148,7 @@ function ensureFile(map: DirectoryHierarchyMap, file: string) {
148148
const dirname = path.dirname(file);
149149
if (dirname === ".") {
150150
const error = `Ill-formed path ${file} in zip archive (expected absolute path)`;
151-
void logger.log(error);
151+
void extLogger.log(error);
152152
throw new Error(error);
153153
}
154154
ensureDir(map, dirname);

extensions/ql-vscode/src/commandRunner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ProgressLocation,
88
} from "vscode";
99
import { showAndLogErrorMessage, showAndLogWarningMessage } from "./helpers";
10-
import { logger } from "./common";
10+
import { extLogger } from "./common";
1111
import { getErrorMessage, getErrorStack } from "./pure/helpers-pure";
1212
import { telemetryListener } from "./telemetry";
1313

@@ -131,7 +131,7 @@ export function commandRunner(
131131
if (e instanceof UserCancellationException) {
132132
// User has cancelled this action manually
133133
if (e.silent) {
134-
void logger.log(errorMessage);
134+
void extLogger.log(errorMessage);
135135
} else {
136136
void showAndLogWarningMessage(errorMessage);
137137
}
@@ -166,7 +166,7 @@ export function commandRunnerWithProgress<R>(
166166
commandId: string,
167167
task: ProgressTask<R>,
168168
progressOptions: Partial<ProgressOptions>,
169-
outputLogger = logger,
169+
outputLogger = extLogger,
170170
): Disposable {
171171
return commands.registerCommand(commandId, async (...args: any[]) => {
172172
const startTime = Date.now();

extensions/ql-vscode/src/common/logging/logger.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
export interface LogOptions {
2-
/** If false, don't output a trailing newline for the log entry. Default true. */
2+
// If false, don't output a trailing newline for the log entry. Default true.
33
trailingNewline?: boolean;
44

5-
/** If specified, add this log entry to the log file at the specified location. */
5+
// If specified, add this log entry to the log file at the specified location.
66
additionalLogLocation?: string;
77
}
88

99
export interface Logger {
10-
/** Writes the given log message, optionally followed by a newline. */
10+
/**
11+
* Writes the given log message, optionally followed by a newline.
12+
* This function is asynchronous and will only resolve once the message is written
13+
* to the side log (if required). It is not necessary to await the results of this
14+
* function if you don't need to guarantee that the log writing is complete before
15+
* continuing.
16+
*
17+
* @param message The message to log.
18+
* @param options Optional settings.
19+
*/
1120
log(message: string, options?: LogOptions): Promise<void>;
21+
1222
/**
13-
* Reveal this channel in the UI.
23+
* Reveal the logger channel in the UI.
1424
*
1525
* @param preserveFocus When `true` the channel will not take focus.
1626
*/
1727
show(preserveFocus?: boolean): void;
1828

1929
/**
20-
* Remove the log at the specified location
30+
* Remove the log at the specified location.
31+
*
2132
* @param location log to remove
2233
*/
2334
removeAdditionalLogLocation(location: string | undefined): void;
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
/**
2+
* This module contains instantiated loggers to use in the extension.
3+
*/
4+
15
import { OutputChannelLogger } from "./output-channel-logger";
26

3-
/** The global logger for the extension. */
4-
export const logger = new OutputChannelLogger("CodeQL Extension Log");
7+
// Global logger for the extension.
8+
export const extLogger = new OutputChannelLogger("CodeQL Extension Log");
59

6-
/** The logger for messages from the query server. */
10+
// Logger for messages from the query server.
711
export const queryServerLogger = new OutputChannelLogger("CodeQL Query Server");
812

9-
/** The logger for messages from the language server. */
13+
// Logger for messages from the language server.
1014
export const ideServerLogger = new OutputChannelLogger(
1115
"CodeQL Language Server",
1216
);
1317

14-
/** The logger for messages from tests. */
18+
// Logger for messages from tests.
1519
export const testLogger = new OutputChannelLogger("CodeQL Tests");

extensions/ql-vscode/src/common/logging/vscode/output-channel-logger.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import * as path from "path";
44
import { Logger, LogOptions } from "../logger";
55
import { DisposableObject } from "../../../pure/disposable-object";
66

7-
/** A logger that writes messages to an output channel in the Output tab. */
7+
/**
8+
* A logger that writes messages to an output channel in the VS Code Output tab.
9+
*/
810
export class OutputChannelLogger extends DisposableObject implements Logger {
911
public readonly outputChannel: OutputChannel;
1012
private readonly additionalLocations = new Map<
@@ -20,12 +22,6 @@ export class OutputChannelLogger extends DisposableObject implements Logger {
2022
this.isCustomLogDirectory = false;
2123
}
2224

23-
/**
24-
* This function is asynchronous and will only resolve once the message is written
25-
* to the side log (if required). It is not necessary to await the results of this
26-
* function if you don't need to guarantee that the log writing is complete before
27-
* continuing.
28-
*/
2925
async log(message: string, options = {} as LogOptions): Promise<void> {
3026
try {
3127
if (options.trailingNewline === undefined) {
@@ -82,9 +78,7 @@ export class OutputChannelLogger extends DisposableObject implements Logger {
8278
}
8379

8480
class AdditionalLogLocation {
85-
constructor(private location: string) {
86-
/**/
87-
}
81+
constructor(private location: string) {}
8882

8983
async log(message: string, options = {} as LogOptions): Promise<void> {
9084
if (options.trailingNewline === undefined) {

extensions/ql-vscode/src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ConfigurationTarget,
88
} from "vscode";
99
import { DistributionManager } from "./distribution";
10-
import { logger } from "./common";
10+
import { extLogger } from "./common";
1111
import { ONE_DAY_IN_MS } from "./pure/time";
1212

1313
export const ALL_SETTINGS: Setting[] = [];
@@ -349,7 +349,7 @@ export class QueryServerConfigListener
349349
return undefined;
350350
}
351351
if (memory == 0 || typeof memory !== "number") {
352-
void logger.log(
352+
void extLogger.log(
353353
`Ignoring value '${memory}' for setting ${MEMORY_SETTING.qualifiedName}`,
354354
);
355355
return undefined;

extensions/ql-vscode/src/contextual/queryResolver.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { KeyType, kindOfKeyType, nameOfKeyType, tagOfKeyType } from "./keyType";
88
import { CodeQLCliServer } from "../cli";
99
import { DatabaseItem } from "../databases";
1010
import { QlPacksForLanguage } from "../helpers";
11-
import { logger } from "../common";
11+
import { extLogger } from "../common";
1212
import { createInitialQueryInfo } from "../run-queries-shared";
1313
import { CancellationToken, Uri } from "vscode";
1414
import { ProgressCallback } from "../commandRunner";
@@ -161,17 +161,17 @@ async function resolveContextualQuery(
161161
// No lock file, likely because this library pack is in the package cache.
162162
// Create a lock file so that we can resolve dependencies and library path
163163
// for the contextual query.
164-
void logger.log(
164+
void extLogger.log(
165165
`Library pack ${packPath} is missing a lock file; creating a temporary lock file`,
166166
);
167167
await cli.packResolveDependencies(packPath);
168168
createdTempLockFile = true;
169169
// Clear CLI server pack cache before installing dependencies,
170170
// so that it picks up the new lock file, not the previously cached pack.
171-
void logger.log("Clearing the CodeQL CLI server's pack cache");
171+
void extLogger.log("Clearing the CodeQL CLI server's pack cache");
172172
await cli.clearCache();
173173
// Install dependencies.
174-
void logger.log(
174+
void extLogger.log(
175175
`Installing package dependencies for library pack ${packPath}`,
176176
);
177177
await cli.packInstall(packPath);
@@ -181,7 +181,7 @@ async function resolveContextualQuery(
181181

182182
async function removeTemporaryLockFile(packPath: string) {
183183
const tempLockFilePath = path.resolve(packPath, "codeql-pack.lock.yml");
184-
void logger.log(
184+
void extLogger.log(
185185
`Deleting temporary package lock file at ${tempLockFilePath}`,
186186
);
187187
// It's fine if the file doesn't exist.
@@ -212,7 +212,7 @@ export async function runContextualQuery(
212212
},
213213
false,
214214
);
215-
void logger.log(
215+
void extLogger.log(
216216
`Running contextual query ${query}; results will be stored in ${queryStorageDir}`,
217217
);
218218
const queryResult = await qs.compileAndRunQueryAgainstDatabase(

extensions/ql-vscode/src/databaseFetcher.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { retry } from "@octokit/plugin-retry";
1111
import { DatabaseManager, DatabaseItem } from "./databases";
1212
import { showAndLogInformationMessage } from "./helpers";
1313
import { reportStreamProgress, ProgressCallback } from "./commandRunner";
14-
import { logger } from "./common";
14+
import { extLogger } from "./common";
1515
import { tmpDir } from "./helpers";
1616
import { Credentials } from "./authentication";
1717
import { REPO_REGEX, getErrorMessage } from "./pure/helpers-pure";
@@ -585,7 +585,7 @@ export async function convertGithubNwoToDatabaseUrl(
585585
name: repo,
586586
};
587587
} catch (e) {
588-
void logger.log(`Error: ${getErrorMessage(e)}`);
588+
void extLogger.log(`Error: ${getErrorMessage(e)}`);
589589
throw new Error(`Unable to get database for '${githubRepo}'`);
590590
}
591591
}
@@ -696,7 +696,7 @@ export async function convertLgtmUrlToDatabaseUrl(
696696
language,
697697
].join("/")}`;
698698
} catch (e) {
699-
void logger.log(`Error: ${getErrorMessage(e)}`);
699+
void extLogger.log(`Error: ${getErrorMessage(e)}`);
700700
throw new Error(`Invalid LGTM URL: ${lgtmUrl}`);
701701
}
702702
}

extensions/ql-vscode/src/databases-ui.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
isLikelyDbLanguageFolder,
2828
showAndLogErrorMessage,
2929
} from "./helpers";
30-
import { logger } from "./common";
30+
import { extLogger } from "./common";
3131
import {
3232
importArchiveDatabase,
3333
promptImportGithubDatabase,
@@ -241,7 +241,7 @@ export class DatabaseUI extends DisposableObject {
241241
}
242242

243243
init() {
244-
void logger.log("Registering database panel commands.");
244+
void extLogger.log("Registering database panel commands.");
245245
this.push(
246246
commandRunnerWithProgress(
247247
"codeQL.setCurrentDatabase",
@@ -393,14 +393,14 @@ export class DatabaseUI extends DisposableObject {
393393
};
394394

395395
handleRemoveOrphanedDatabases = async (): Promise<void> => {
396-
void logger.log("Removing orphaned databases from workspace storage.");
396+
void extLogger.log("Removing orphaned databases from workspace storage.");
397397
let dbDirs = undefined;
398398

399399
if (
400400
!(await fs.pathExists(this.storagePath)) ||
401401
!(await fs.stat(this.storagePath)).isDirectory()
402402
) {
403-
void logger.log(
403+
void extLogger.log(
404404
"Missing or invalid storage directory. Not trying to remove orphaned databases.",
405405
);
406406
return;
@@ -425,7 +425,7 @@ export class DatabaseUI extends DisposableObject {
425425
dbDirs = await asyncFilter(dbDirs, isLikelyDatabaseRoot);
426426

427427
if (!dbDirs.length) {
428-
void logger.log("No orphaned databases found.");
428+
void extLogger.log("No orphaned databases found.");
429429
return;
430430
}
431431

@@ -434,7 +434,7 @@ export class DatabaseUI extends DisposableObject {
434434
await Promise.all(
435435
dbDirs.map(async (dbDir) => {
436436
try {
437-
void logger.log(`Deleting orphaned database '${dbDir}'.`);
437+
void extLogger.log(`Deleting orphaned database '${dbDir}'.`);
438438
await fs.remove(dbDir);
439439
} catch (e) {
440440
failures.push(`${path.basename(dbDir)}`);

extensions/ql-vscode/src/databases.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
encodeSourceArchiveUri,
1919
} from "./archive-filesystem-provider";
2020
import { DisposableObject } from "./pure/disposable-object";
21-
import { Logger, logger } from "./common";
21+
import { Logger, extLogger } from "./common";
2222
import { getErrorMessage } from "./pure/helpers-pure";
2323
import { QueryRunner } from "./queryRunner";
2424

@@ -545,7 +545,7 @@ function eventFired<T>(
545545
): Promise<T | undefined> {
546546
return new Promise((res, _rej) => {
547547
const timeout = setTimeout(() => {
548-
void logger.log(
548+
void extLogger.log(
549549
`Waiting for event ${event} timed out after ${timeoutMs}ms`,
550550
);
551551
res(undefined);
@@ -657,12 +657,12 @@ export class DatabaseManager extends DisposableObject {
657657

658658
const msg = item.verifyZippedSources();
659659
if (msg) {
660-
void logger.log(`Could not add source folder because ${msg}`);
660+
void extLogger.log(`Could not add source folder because ${msg}`);
661661
return;
662662
}
663663

664664
const uri = item.getSourceArchiveExplorerUri();
665-
void logger.log(
665+
void extLogger.log(
666666
`Adding workspace folder for ${item.name} source archive at index ${end}`,
667667
);
668668
if ((vscode.workspace.workspaceFolders || []).length < 2) {
@@ -916,7 +916,7 @@ export class DatabaseManager extends DisposableObject {
916916
(folder) => item.belongsToSourceArchiveExplorerUri(folder.uri),
917917
);
918918
if (folderIndex >= 0) {
919-
void logger.log(`Removing workspace folder at index ${folderIndex}`);
919+
void extLogger.log(`Removing workspace folder at index ${folderIndex}`);
920920
vscode.workspace.updateWorkspaceFolders(folderIndex, 1);
921921
}
922922

@@ -925,11 +925,11 @@ export class DatabaseManager extends DisposableObject {
925925

926926
// Delete folder from file system only if it is controlled by the extension
927927
if (this.isExtensionControlledLocation(item.databaseUri)) {
928-
void logger.log("Deleting database from filesystem.");
928+
void extLogger.log("Deleting database from filesystem.");
929929
fs.remove(item.databaseUri.fsPath).then(
930-
() => void logger.log(`Deleted '${item.databaseUri.fsPath}'`),
930+
() => void extLogger.log(`Deleted '${item.databaseUri.fsPath}'`),
931931
(e) =>
932-
void logger.log(
932+
void extLogger.log(
933933
`Failed to delete '${
934934
item.databaseUri.fsPath
935935
}'. Reason: ${getErrorMessage(e)}`,

0 commit comments

Comments
 (0)