Skip to content

Commit 4804220

Browse files
author
Dave Bartolomeo
committed
Use native VS Code test UI in canary
1 parent e1dae0b commit 4804220

9 files changed

Lines changed: 688 additions & 252 deletions

File tree

extensions/ql-vscode/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ql-vscode/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,13 @@
973973
"when": "viewItem == testWithSource"
974974
}
975975
],
976+
"testing/item/context": [
977+
{
978+
"command": "codeQLTests.acceptOutput",
979+
"group": "qltest@1",
980+
"when": "controllerId == codeql && testId =~ /^test /"
981+
}
982+
],
976983
"explorer/context": [
977984
{
978985
"command": "codeQL.setCurrentDatabase",
@@ -1523,7 +1530,7 @@
15231530
"@types/through2": "^2.0.36",
15241531
"@types/tmp": "^0.1.0",
15251532
"@types/unzipper": "~0.10.1",
1526-
"@types/vscode": "^1.59.0",
1533+
"@types/vscode": "^1.67.0",
15271534
"@types/webpack": "^5.28.0",
15281535
"@types/webpack-env": "^1.18.0",
15291536
"@types/xml2js": "~0.4.4",

extensions/ql-vscode/src/cli.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
getErrorStack,
2424
} from "./pure/helpers-pure";
2525
import { QueryMetadata, SortDirection } from "./pure/interface-types";
26-
import { Logger, ProgressReporter } from "./common";
26+
import { BaseLogger, Logger, ProgressReporter } from "./common";
2727
import { CompilationMessage } from "./pure/legacy-messages";
2828
import { sarifParser } from "./sarif-parser";
2929
import { walkDirectory } from "./helpers";
@@ -134,6 +134,7 @@ export interface TestCompleted {
134134
compilationMs: number;
135135
evaluationMs: number;
136136
expected: string;
137+
actual?: string;
137138
diff: string[] | undefined;
138139
failureDescription?: string;
139140
failureStage?: string;
@@ -424,7 +425,7 @@ export class CodeQLCliServer implements Disposable {
424425
command: string[],
425426
commandArgs: string[],
426427
cancellationToken?: CancellationToken,
427-
logger?: Logger,
428+
logger?: BaseLogger,
428429
): AsyncGenerator<string, void, unknown> {
429430
// Add format argument first, in case commandArgs contains positional parameters.
430431
const args = [...command, "--format", "jsonz", ...commandArgs];
@@ -453,9 +454,13 @@ export class CodeQLCliServer implements Disposable {
453454
])) {
454455
yield event;
455456
}
456-
457-
await childPromise;
458457
} finally {
458+
try {
459+
await childPromise;
460+
} catch (_e) {
461+
// We need to await this to avoid an unhandled rejection, but we want to propagate the
462+
// original exception.
463+
}
459464
if (cancellationRegistration !== undefined) {
460465
cancellationRegistration.dispose();
461466
}
@@ -482,7 +487,7 @@ export class CodeQLCliServer implements Disposable {
482487
logger,
483488
}: {
484489
cancellationToken?: CancellationToken;
485-
logger?: Logger;
490+
logger?: BaseLogger;
486491
} = {},
487492
): AsyncGenerator<EventType, void, unknown> {
488493
for await (const event of this.runAsyncCodeQlCliCommandInternal(
@@ -761,7 +766,7 @@ export class CodeQLCliServer implements Disposable {
761766
logger,
762767
}: {
763768
cancellationToken?: CancellationToken;
764-
logger?: Logger;
769+
logger?: BaseLogger;
765770
},
766771
): AsyncGenerator<TestCompleted, void, unknown> {
767772
const subcommandArgs = this.cliConfig.additionalTestArguments.concat([
@@ -1623,7 +1628,7 @@ const lineEndings = ["\r\n", "\r", "\n"];
16231628
* @param stream The stream to log.
16241629
* @param logger The logger that will consume the stream output.
16251630
*/
1626-
async function logStream(stream: Readable, logger: Logger): Promise<void> {
1631+
async function logStream(stream: Readable, logger: BaseLogger): Promise<void> {
16271632
for await (const line of splitStreamAtSeparators(stream, lineEndings)) {
16281633
// Await the result of log here in order to ensure the logs are written in the correct order.
16291634
await logger.log(line);

extensions/ql-vscode/src/extension.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { CodeQLCliServer } from "./cli";
3030
import {
3131
CliConfigListener,
3232
DistributionConfigListener,
33+
isCanary,
3334
joinOrderWarningThreshold,
3435
QueryHistoryConfigListener,
3536
QueryServerConfigListener,
@@ -113,14 +114,16 @@ import {
113114
BaseCommands,
114115
PreActivationCommands,
115116
QueryServerCommands,
116-
TestUICommands,
117117
} from "./common/commands";
118118
import { LocalQueries } from "./local-queries";
119119
import { getAstCfgCommands } from "./ast-cfg-commands";
120120
import { getQueryEditorCommands } from "./query-editor";
121121
import { App } from "./common/app";
122122
import { registerCommandWithErrorHandling } from "./common/vscode/commands";
123123
import { DataExtensionsEditorModule } from "./data-extensions-editor/data-extensions-editor-module";
124+
import { TestManager } from "./test-manager";
125+
import { TestRunner } from "./test-runner";
126+
import { TestManagerBase } from "./test-manager-base";
124127

125128
/**
126129
* extension.ts
@@ -876,25 +879,34 @@ async function activateWithInstalledDistribution(
876879
);
877880

878881
void extLogger.log("Initializing QLTest interface.");
879-
const testExplorerExtension = extensions.getExtension<TestHub>(
880-
testExplorerExtensionId,
881-
);
882-
let testUiCommands: Partial<TestUICommands> = {};
883-
if (testExplorerExtension) {
884-
const testHub = testExplorerExtension.exports;
885-
const testAdapterFactory = new QLTestAdapterFactory(
886-
testHub,
887-
cliServer,
888-
dbm,
889-
);
890-
ctx.subscriptions.push(testAdapterFactory);
891882

892-
const testUIService = new TestUIService(app, testHub);
893-
ctx.subscriptions.push(testUIService);
883+
const testRunner = new TestRunner(dbm, cliServer);
884+
ctx.subscriptions.push(testRunner);
885+
886+
let testManager: TestManagerBase | undefined = undefined;
887+
if (isCanary()) {
888+
testManager = new TestManager(app, testRunner, cliServer);
889+
ctx.subscriptions.push(testManager);
890+
} else {
891+
const testExplorerExtension = extensions.getExtension<TestHub>(
892+
testExplorerExtensionId,
893+
);
894+
if (testExplorerExtension) {
895+
const testHub = testExplorerExtension.exports;
896+
const testAdapterFactory = new QLTestAdapterFactory(
897+
testHub,
898+
testRunner,
899+
cliServer,
900+
);
901+
ctx.subscriptions.push(testAdapterFactory);
894902

895-
testUiCommands = testUIService.getCommands();
903+
testManager = new TestUIService(app, testHub);
904+
ctx.subscriptions.push(testManager);
905+
}
896906
}
897907

908+
const testUiCommands = testManager?.getCommands() ?? {};
909+
898910
const astViewer = new AstViewer();
899911
const astTemplateProvider = new TemplatePrintAstProvider(
900912
cliServer,

0 commit comments

Comments
 (0)