-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathquery-results-watcher.ts
More file actions
61 lines (56 loc) · 2.02 KB
/
query-results-watcher.ts
File metadata and controls
61 lines (56 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import * as vscode from 'vscode';
import { DisposableObject } from '../common/disposable';
import type { Logger } from '../common/logger';
import type { StoragePaths } from './storage-paths';
/**
* Watches for query results (BQRS and SARIF files) created by the
* `vscode-codeql` extension.
*
* Detection strategy:
* - `workspace.createFileSystemWatcher` for `*.bqrs` and `*-interpreted.sarif`
* - `tasks.onDidEndTask` as a signal that a query may have completed
*/
export class QueryResultsWatcher extends DisposableObject {
private readonly _onDidChange = new vscode.EventEmitter<void>();
readonly onDidChange = this._onDidChange.event;
constructor(
private readonly storagePaths: StoragePaths,
private readonly logger: Logger,
) {
super();
this.push(this._onDidChange);
// Watch for BQRS files
const bqrsWatcher = vscode.workspace.createFileSystemWatcher('**/*.bqrs');
this.push(bqrsWatcher);
bqrsWatcher.onDidCreate((uri) => {
this.logger.info(`Query result (BQRS) created: ${vscode.workspace.asRelativePath(uri)}`);
this._onDidChange.fire();
});
// Watch for interpreted SARIF files
const sarifWatcher = vscode.workspace.createFileSystemWatcher(
'**/*-interpreted.sarif',
);
this.push(sarifWatcher);
sarifWatcher.onDidCreate((uri) => {
this.logger.info(`Query result (SARIF) created: ${vscode.workspace.asRelativePath(uri)}`);
this._onDidChange.fire();
});
// Listen for task completions as a signal that queries may have finished
const taskSub = vscode.tasks.onDidEndTask((e) => {
const taskName = e.execution.task.name.toLowerCase();
if (
taskName.includes('codeql') ||
taskName.includes('query') ||
taskName.includes('test')
) {
this.logger.debug(
`CodeQL-related task ended: ${e.execution.task.name}`,
);
this._onDidChange.fire();
}
});
if (taskSub && typeof taskSub.dispose === 'function') {
this.push(taskSub as vscode.Disposable);
}
}
}