Remove QLPackDiscovery
We no longer rely on qlpacks for our ql test structure. For this reason, we no longer need to do qlpack discovery.
This commit is contained in:
@@ -1,58 +0,0 @@
|
|||||||
import { EventEmitter, Event, Uri, WorkspaceFolder, RelativePattern } from 'vscode';
|
|
||||||
import { MultiFileSystemWatcher } from './vscode-utils/multi-file-system-watcher';
|
|
||||||
import { CodeQLCliServer, QlpacksInfo } from './cli';
|
|
||||||
import { Discovery } from './discovery';
|
|
||||||
|
|
||||||
export interface QLPack {
|
|
||||||
name: string;
|
|
||||||
uri: Uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service to discover all available QL packs in a workspace folder.
|
|
||||||
*/
|
|
||||||
export class QLPackDiscovery extends Discovery<QlpacksInfo> {
|
|
||||||
private readonly _onDidChangeQLPacks = this.push(new EventEmitter<void>());
|
|
||||||
private readonly watcher = this.push(new MultiFileSystemWatcher());
|
|
||||||
private _qlPacks: readonly QLPack[] = [];
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
private readonly workspaceFolder: WorkspaceFolder,
|
|
||||||
private readonly cliServer: CodeQLCliServer
|
|
||||||
) {
|
|
||||||
super('QL Pack Discovery');
|
|
||||||
|
|
||||||
// Watch for any changes to `qlpack.yml` files in this workspace folder.
|
|
||||||
// TODO: The CLI server should tell us what paths to watch for.
|
|
||||||
this.watcher.addWatch(new RelativePattern(this.workspaceFolder, '**/qlpack.yml'));
|
|
||||||
this.watcher.addWatch(new RelativePattern(this.workspaceFolder, '**/.codeqlmanifest.json'));
|
|
||||||
this.push(this.watcher.onDidChange(this.handleQLPackFileChanged, this));
|
|
||||||
}
|
|
||||||
|
|
||||||
public get onDidChangeQLPacks(): Event<void> { return this._onDidChangeQLPacks.event; }
|
|
||||||
|
|
||||||
public get qlPacks(): readonly QLPack[] { return this._qlPacks; }
|
|
||||||
|
|
||||||
private handleQLPackFileChanged(_uri: Uri): void {
|
|
||||||
this.refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected discover(): Promise<QlpacksInfo> {
|
|
||||||
// Only look for QL packs in this workspace folder.
|
|
||||||
return this.cliServer.resolveQlpacks([this.workspaceFolder.uri.fsPath], []);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected update(results: QlpacksInfo): void {
|
|
||||||
const qlPacks: QLPack[] = [];
|
|
||||||
for (const id in results) {
|
|
||||||
qlPacks.push(...results[id].map(fsPath => {
|
|
||||||
return {
|
|
||||||
name: id,
|
|
||||||
uri: Uri.file(fsPath)
|
|
||||||
};
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
this._qlPacks = qlPacks;
|
|
||||||
this._onDidChangeQLPacks.fire();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { QLPackDiscovery } from './qlpack-discovery';
|
|
||||||
import { Discovery } from './discovery';
|
import { Discovery } from './discovery';
|
||||||
import { EventEmitter, Event, Uri, RelativePattern, WorkspaceFolder, env } from 'vscode';
|
import { EventEmitter, Event, Uri, RelativePattern, WorkspaceFolder, env } from 'vscode';
|
||||||
import { MultiFileSystemWatcher } from './vscode-utils/multi-file-system-watcher';
|
import { MultiFileSystemWatcher } from './vscode-utils/multi-file-system-watcher';
|
||||||
@@ -128,13 +127,11 @@ export class QLTestDiscovery extends Discovery<QLTestDiscoveryResults> {
|
|||||||
private _testDirectory: QLTestDirectory | undefined;
|
private _testDirectory: QLTestDirectory | undefined;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly qlPackDiscovery: QLPackDiscovery,
|
|
||||||
private readonly workspaceFolder: WorkspaceFolder,
|
private readonly workspaceFolder: WorkspaceFolder,
|
||||||
private readonly cliServer: CodeQLCliServer
|
private readonly cliServer: CodeQLCliServer
|
||||||
) {
|
) {
|
||||||
super('QL Test Discovery');
|
super('QL Test Discovery');
|
||||||
|
|
||||||
this.push(this.qlPackDiscovery.onDidChangeQLPacks(this.handleDidChangeQLPacks, this));
|
|
||||||
this.push(this.watcher.onDidChange(this.handleDidChange, this));
|
this.push(this.watcher.onDidChange(this.handleDidChange, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,21 +150,13 @@ export class QLTestDiscovery extends Discovery<QLTestDiscoveryResults> {
|
|||||||
return this._testDirectory;
|
return this._testDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleDidChangeQLPacks(): void {
|
|
||||||
this.refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleDidChange(uri: Uri): void {
|
private handleDidChange(uri: Uri): void {
|
||||||
if (!QLTestDiscovery.ignoreTestPath(uri.fsPath)) {
|
if (!QLTestDiscovery.ignoreTestPath(uri.fsPath)) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static cnt = 0;
|
|
||||||
protected async discover(): Promise<QLTestDiscoveryResults> {
|
protected async discover(): Promise<QLTestDiscoveryResults> {
|
||||||
const timer = 'testDirectory-' + this.workspaceFolder.uri.fsPath + '-' + QLTestDiscovery.cnt++;
|
|
||||||
console.time(timer);
|
|
||||||
const testDirectory = await this.discoverTests();
|
const testDirectory = await this.discoverTests();
|
||||||
console.timeEnd(timer);
|
|
||||||
return {
|
return {
|
||||||
testDirectory,
|
testDirectory,
|
||||||
watchPath: this.workspaceFolder.uri.fsPath
|
watchPath: this.workspaceFolder.uri.fsPath
|
||||||
|
|||||||
@@ -545,9 +545,7 @@ export class QueryHistoryManager extends DisposableObject {
|
|||||||
private async tryOpenExternalFile(fileLocation: string) {
|
private async tryOpenExternalFile(fileLocation: string) {
|
||||||
const uri = vscode.Uri.file(fileLocation);
|
const uri = vscode.Uri.file(fileLocation);
|
||||||
try {
|
try {
|
||||||
await vscode.window.showTextDocument(uri, {
|
await vscode.window.showTextDocument(uri, { preview: false });
|
||||||
preview: false
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (
|
if (
|
||||||
e.message.includes(
|
e.message.includes(
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import { TestAdapterRegistrar } from 'vscode-test-adapter-util';
|
|||||||
import { QLTestFile, QLTestNode, QLTestDirectory, QLTestDiscovery } from './qltest-discovery';
|
import { QLTestFile, QLTestNode, QLTestDirectory, QLTestDiscovery } from './qltest-discovery';
|
||||||
import { Event, EventEmitter, CancellationTokenSource, CancellationToken } from 'vscode';
|
import { Event, EventEmitter, CancellationTokenSource, CancellationToken } from 'vscode';
|
||||||
import { DisposableObject } from './vscode-utils/disposable-object';
|
import { DisposableObject } from './vscode-utils/disposable-object';
|
||||||
import { QLPackDiscovery } from './qlpack-discovery';
|
|
||||||
import { CodeQLCliServer } from './cli';
|
import { CodeQLCliServer } from './cli';
|
||||||
import { getOnDiskWorkspaceFolders } from './helpers';
|
import { getOnDiskWorkspaceFolders } from './helpers';
|
||||||
import { testLogger } from './logging';
|
import { testLogger } from './logging';
|
||||||
@@ -82,7 +81,6 @@ function changeExtension(p: string, ext: string): string {
|
|||||||
* Test adapter for QL tests.
|
* Test adapter for QL tests.
|
||||||
*/
|
*/
|
||||||
export class QLTestAdapter extends DisposableObject implements TestAdapter {
|
export class QLTestAdapter extends DisposableObject implements TestAdapter {
|
||||||
private readonly qlPackDiscovery: QLPackDiscovery;
|
|
||||||
private readonly qlTestDiscovery: QLTestDiscovery;
|
private readonly qlTestDiscovery: QLTestDiscovery;
|
||||||
private readonly _tests = this.push(
|
private readonly _tests = this.push(
|
||||||
new EventEmitter<TestLoadStartedEvent | TestLoadFinishedEvent>());
|
new EventEmitter<TestLoadStartedEvent | TestLoadFinishedEvent>());
|
||||||
@@ -97,10 +95,7 @@ export class QLTestAdapter extends DisposableObject implements TestAdapter {
|
|||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.qlPackDiscovery = this.push(new QLPackDiscovery(workspaceFolder, cliServer));
|
this.qlTestDiscovery = this.push(new QLTestDiscovery(workspaceFolder, cliServer));
|
||||||
this.qlTestDiscovery = this.push(new QLTestDiscovery(this.qlPackDiscovery, workspaceFolder, cliServer));
|
|
||||||
// TODO: Don't run test discovery until pack discovery finishes
|
|
||||||
this.qlPackDiscovery.refresh();
|
|
||||||
this.qlTestDiscovery.refresh();
|
this.qlTestDiscovery.refresh();
|
||||||
|
|
||||||
this.push(this.qlTestDiscovery.onDidChangeTests(this.discoverTests, this));
|
this.push(this.qlTestDiscovery.onDidChangeTests(this.discoverTests, this));
|
||||||
@@ -176,7 +171,7 @@ export class QLTestAdapter extends DisposableObject implements TestAdapter {
|
|||||||
type: 'finished',
|
type: 'finished',
|
||||||
suite: testSuite
|
suite: testSuite
|
||||||
} as TestLoadFinishedEvent);
|
} as TestLoadFinishedEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async run(tests: string[]): Promise<void> {
|
public async run(tests: string[]): Promise<void> {
|
||||||
if (this.runningTask !== undefined) {
|
if (this.runningTask !== undefined) {
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ describe('qltest-discovery', () => {
|
|||||||
const hDir = Uri.parse('file:/a/b/c/f/g/h').fsPath;
|
const hDir = Uri.parse('file:/a/b/c/f/g/h').fsPath;
|
||||||
const iFile = Uri.parse('file:/a/b/c/f/g/h/i.ql').fsPath;
|
const iFile = Uri.parse('file:/a/b/c/f/g/h/i.ql').fsPath;
|
||||||
const qlTestDiscover = new QLTestDiscovery(
|
const qlTestDiscover = new QLTestDiscovery(
|
||||||
{ onDidChangeQLPacks: () => ({}) } as any,
|
|
||||||
{
|
{
|
||||||
uri: baseUri,
|
uri: baseUri,
|
||||||
name: 'My tests'
|
name: 'My tests'
|
||||||
|
|||||||
Reference in New Issue
Block a user