Skip to content

Commit 4c33c06

Browse files
committed
Allow compare view to work with quick-eval
The compare view typically works by matching the results sets of queries. It only allows the results sets of queries with identical names to be compared. Manually run queries use `#select` as the default result set. However, quick eval queries use a different, generated, name. Therefore, these two kinds of queries cannot be compared. This commit changes the heuristics so that if there are no identical;y named results sets, the first result set of each query that is prefixed with `#` is used (this is the default result set). It also makes a slightly nicer error message if there are no comparable results sets.
1 parent e9552df commit 4c33c06

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,40 @@ export class CompareView extends AbstractWebview<
175175
const commonResultSetNames = fromSchemaNames.filter((name) =>
176176
toSchemaNames.includes(name),
177177
);
178+
179+
// Fall back on the default result set names if there are no common ones.
180+
const defaultFromResultSetName = fromSchemaNames.find((name) =>
181+
name.startsWith("#"),
182+
);
183+
const defaultToResultSetName = toSchemaNames.find((name) =>
184+
name.startsWith("#"),
185+
);
186+
187+
if (
188+
commonResultSetNames.length === 0 &&
189+
!(defaultFromResultSetName || defaultToResultSetName)
190+
) {
191+
throw new Error(
192+
"No common result sets found between the two queries. Please check that the queries are compatible.",
193+
);
194+
}
195+
178196
const currentResultSetName =
179197
selectedResultSetName || commonResultSetNames[0];
180198
const fromResultSet = await this.getResultSet(
181199
fromSchemas,
182-
currentResultSetName,
200+
currentResultSetName || defaultFromResultSetName!,
183201
from.completedQuery.query.resultsPaths.resultsPath,
184202
);
185203
const toResultSet = await this.getResultSet(
186204
toSchemas,
187-
currentResultSetName,
205+
currentResultSetName || defaultToResultSetName!,
188206
to.completedQuery.query.resultsPaths.resultsPath,
189207
);
190208
return [
191209
commonResultSetNames,
192-
currentResultSetName,
210+
currentResultSetName ||
211+
`${defaultFromResultSetName} <-> ${defaultToResultSetName}`,
193212
fromResultSet,
194213
toResultSet,
195214
];

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ export function Compare(_: Record<string, never>): JSX.Element {
5959
return (
6060
<>
6161
<div className="vscode-codeql__compare-header">
62-
<div className="vscode-codeql__compare-header-item">
63-
Table to compare:
64-
</div>
62+
<div className="vscode-codeql__compare-header-item">Comparing:</div>
6563
<CompareSelector
6664
availableResultSets={comparison.commonResultSetNames}
6765
currentResultSetName={comparison.currentResultSetName}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ interface Props {
77
}
88

99
export default function CompareSelector(props: Props) {
10-
return (
10+
return props.availableResultSets.length ? (
11+
// Handle case where there are shared result sets
1112
<select
1213
value={props.currentResultSetName}
1314
onChange={(e) => props.updateResultSet(e.target.value)}
@@ -18,5 +19,8 @@ export default function CompareSelector(props: Props) {
1819
</option>
1920
))}
2021
</select>
22+
) : (
23+
// Handle case where there are no shared result sets
24+
<div>{props.currentResultSetName}</div>
2125
);
2226
}

0 commit comments

Comments
 (0)