Skip to content

Commit eabbd48

Browse files
committed
Use bqrs diff for all cases in the compare view when --result-sets is supported
1 parent 1e08968 commit eabbd48

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type { CodeQLCliServer } from "../codeql-cli/cli";
1919
import type { DatabaseManager } from "../databases/local-databases";
2020
import { jumpToLocation } from "../databases/local-databases/locations";
2121
import type { BqrsInfo, BqrsResultSetSchema } from "../common/bqrs-cli-types";
22+
// eslint-disable-next-line import/no-deprecated
2223
import resultsDiff from "./resultsDiff";
2324
import type { CompletedLocalQueryInfo } from "../query-results";
2425
import { assertNever, getErrorMessage } from "../common/helpers-pure";
@@ -403,13 +404,18 @@ export class CompareView extends AbstractWebview<
403404
toResultSetName,
404405
);
405406

406-
// If the result set names are the same, we use `bqrs diff`. This is more
407-
// efficient, but we can't use it in general as it does not support
408-
// comparing different result sets.
409-
if (fromResultSetName === toResultSetName) {
407+
// We use `bqrs diff` when the `--result-sets` option is supported, or when
408+
// the result set names are the same (in which case we don't need the
409+
// option).
410+
const supportsBqrsDiffResultSets =
411+
await this.cliServer.supportsFeature("bqrsDiffResultSets");
412+
if (supportsBqrsDiffResultSets || fromResultSetName === toResultSetName) {
410413
const { uniquePath1, uniquePath2, cleanup } =
411414
await this.cliServer.bqrsDiff(fromPath, toPath, {
412415
retainResultSets: [],
416+
resultSets: supportsBqrsDiffResultSets
417+
? [[fromResultSetName, toResultSetName]]
418+
: [],
413419
});
414420
try {
415421
const uniqueInfo1 = await this.cliServer.bqrsInfo(uniquePath1);
@@ -443,10 +449,13 @@ export class CompareView extends AbstractWebview<
443449
await cleanup();
444450
}
445451
} else {
452+
// Legacy code path: Perform the diff directly in the extension when we
453+
// can't use `bqrs diff`.
446454
const [fromResultSet, toResultSet] = await Promise.all([
447455
this.getResultSet(fromInfo.schemas, fromResultSetName, fromPath),
448456
this.getResultSet(toInfo.schemas, toResultSetName, toPath),
449457
]);
458+
// eslint-disable-next-line import/no-deprecated
450459
return resultsDiff(fromResultSet, toResultSet);
451460
}
452461
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import type { RawResultSet } from "../common/raw-result-types";
1818
* 1. number of columns do not match
1919
* 2. If either query is empty
2020
* 3. If the queries are 100% disjoint
21+
*
22+
* @deprecated This function is only used when the `bqrs diff` command does not
23+
* support `--result-sets`. It should be removed when all supported CLI versions
24+
* support this option.
2125
*/
2226
export default function resultsDiff(
2327
fromResults: RawResultSet,

0 commit comments

Comments
 (0)