Skip to content

Commit 7b6b303

Browse files
authored
Merge pull request #3111 from github/koesie10/compare-raw
Add interpreted results type to compare view
2 parents 86aa4ff + 1235172 commit 7b6b303

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,26 +355,35 @@ export interface SetComparisonsMessage {
355355
};
356356
readonly commonResultSetNames: string[];
357357
readonly currentResultSetName: string;
358-
readonly result: RawQueryCompareResult | undefined;
358+
readonly result: QueryCompareResult | undefined;
359359
readonly message: string | undefined;
360360
readonly databaseUri: string;
361361
}
362362

363+
type QueryCompareResult = RawQueryCompareResult | InterpretedQueryCompareResult;
364+
363365
/**
364366
* from is the set of rows that have changes in the "from" query.
365367
* to is the set of rows that have changes in the "to" query.
366-
* They are in the same order, so element 1 in "from" corresponds to
367-
* element 1 in "to".
368-
*
369-
* If an array element is null, that means that the element was removed
370-
* (or added) in the comparison.
371368
*/
372369
export type RawQueryCompareResult = {
370+
kind: "raw";
373371
columns: readonly BqrsColumn[];
374372
from: ResultRow[];
375373
to: ResultRow[];
376374
};
377375

376+
/**
377+
* from is the set of results that have changes in the "from" query.
378+
* to is the set of results that have changes in the "to" query.
379+
*/
380+
type InterpretedQueryCompareResult = {
381+
kind: "interpreted";
382+
sourceLocationPrefix: string;
383+
from: sarif.Result[];
384+
to: sarif.Result[];
385+
};
386+
378387
/**
379388
* Extract the name of the default result. Prefer returning
380389
* 'alerts', or '#select'. Otherwise return the first in the list.

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
@@ -34,6 +34,7 @@ CompareTable.args = {
3434
commonResultSetNames: ["edges", "nodes", "subpaths", "#select"],
3535
currentResultSetName: "edges",
3636
result: {
37+
kind: "raw",
3738
columns: [
3839
{ name: "a", kind: "Entity" },
3940
{ 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
@@ -64,22 +64,26 @@ export default function CompareTable(props: Props) {
6464
<tbody>
6565
<tr>
6666
<td>
67-
<RawCompareResultTable
68-
columns={result.columns}
69-
schemaName={comparison.currentResultSetName}
70-
rows={result.from}
71-
databaseUri={comparison.databaseUri}
72-
className={className}
73-
/>
67+
{result.kind === "raw" && (
68+
<RawCompareResultTable
69+
columns={result.columns}
70+
schemaName={comparison.currentResultSetName}
71+
rows={result.from}
72+
databaseUri={comparison.databaseUri}
73+
className={className}
74+
/>
75+
)}
7476
</td>
7577
<td>
76-
<RawCompareResultTable
77-
columns={result.columns}
78-
schemaName={comparison.currentResultSetName}
79-
rows={result.to}
80-
databaseUri={comparison.databaseUri}
81-
className={className}
82-
/>
78+
{result.kind === "raw" && (
79+
<RawCompareResultTable
80+
columns={result.columns}
81+
schemaName={comparison.currentResultSetName}
82+
rows={result.to}
83+
databaseUri={comparison.databaseUri}
84+
className={className}
85+
/>
86+
)}
8387
</td>
8488
</tr>
8589
</tbody>

0 commit comments

Comments
 (0)