Skip to content

Commit 8d71162

Browse files
committed
Merge remote-tracking branch 'origin/main' into koesie10/compare-messages
2 parents 4873d7e + 7b6b303 commit 8d71162

File tree

5 files changed

+39
-22
lines changed

5 files changed

+39
-22
lines changed

extensions/ql-vscode/src/common/interface-types.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,25 +365,34 @@ export interface SetComparisonQueryInfoMessage {
365365
export interface SetComparisonsMessage {
366366
readonly t: "setComparisons";
367367
readonly currentResultSetName: string;
368-
readonly result: RawQueryCompareResult | undefined;
368+
readonly result: QueryCompareResult | undefined;
369369
readonly message: string | undefined;
370370
}
371371

372+
type QueryCompareResult = RawQueryCompareResult | InterpretedQueryCompareResult;
373+
372374
/**
373375
* from is the set of rows that have changes in the "from" query.
374376
* to is the set of rows that have changes in the "to" query.
375-
* They are in the same order, so element 1 in "from" corresponds to
376-
* element 1 in "to".
377-
*
378-
* If an array element is null, that means that the element was removed
379-
* (or added) in the comparison.
380377
*/
381378
export type RawQueryCompareResult = {
379+
kind: "raw";
382380
columns: readonly BqrsColumn[];
383381
from: ResultRow[];
384382
to: ResultRow[];
385383
};
386384

385+
/**
386+
* from is the set of results that have changes in the "from" query.
387+
* to is the set of results that have changes in the "to" query.
388+
*/
389+
type InterpretedQueryCompareResult = {
390+
kind: "interpreted";
391+
sourceLocationPrefix: string;
392+
from: sarif.Result[];
393+
to: sarif.Result[];
394+
};
395+
387396
/**
388397
* Extract the name of the default result. Prefer returning
389398
* 'alerts', or '#select'. Otherwise return the first in the list.

extensions/ql-vscode/src/compare/result-set-names.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { BQRSInfo } from "../common/bqrs-cli-types";
2+
import { getDefaultResultSetName } from "../common/interface-types";
23

34
export async function findCommonResultSetNames(
45
fromSchemas: BQRSInfo,
@@ -40,7 +41,8 @@ export async function findResultSetNames(
4041
);
4142
}
4243

43-
const currentResultSetName = selectedResultSetName || commonResultSetNames[0];
44+
const currentResultSetName =
45+
selectedResultSetName ?? getDefaultResultSetName(commonResultSetNames);
4446
const fromResultSetName = currentResultSetName || defaultFromResultSetName!;
4547
const toResultSetName = currentResultSetName || defaultToResultSetName!;
4648

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export default function resultsDiff(
3535
throw new Error("CodeQL Compare: Target query has no results.");
3636
}
3737

38-
const results = {
38+
const results: RawQueryCompareResult = {
39+
kind: "raw",
3940
columns: fromResults.columns,
4041
from: arrayDiff(fromResults.tuples, toResults.tuples),
4142
to: arrayDiff(toResults.tuples, fromResults.tuples),

extensions/ql-vscode/src/stories/compare/CompareTable.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ CompareTable.args = {
3838
t: "setComparisons",
3939
currentResultSetName: "edges",
4040
result: {
41+
kind: "raw",
4142
columns: [
4243
{ name: "a", kind: "Entity" },
4344
{ name: "b", kind: "Entity" },

extensions/ql-vscode/src/view/compare/CompareTable.tsx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,26 @@ export default function CompareTable({ queryInfo, comparison }: Props) {
6767
<tbody>
6868
<tr>
6969
<td>
70-
<RawCompareResultTable
71-
columns={result.columns}
72-
schemaName={comparison.currentResultSetName}
73-
rows={result.from}
74-
databaseUri={queryInfo.databaseUri}
75-
className={className}
76-
/>
70+
{result.kind === "raw" && (
71+
<RawCompareResultTable
72+
columns={result.columns}
73+
schemaName={comparison.currentResultSetName}
74+
rows={result.from}
75+
databaseUri={queryInfo.databaseUri}
76+
className={className}
77+
/>
78+
)}
7779
</td>
7880
<td>
79-
<RawCompareResultTable
80-
columns={result.columns}
81-
schemaName={comparison.currentResultSetName}
82-
rows={result.to}
83-
databaseUri={queryInfo.databaseUri}
84-
className={className}
85-
/>
81+
{result.kind === "raw" && (
82+
<RawCompareResultTable
83+
columns={result.columns}
84+
schemaName={comparison.currentResultSetName}
85+
rows={result.to}
86+
databaseUri={queryInfo.databaseUri}
87+
className={className}
88+
/>
89+
)}
8690
</td>
8791
</tr>
8892
</tbody>

0 commit comments

Comments
 (0)