Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions extensions/ql-vscode/src/compare/compare-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,40 @@ export class CompareView extends AbstractWebview<
const commonResultSetNames = fromSchemaNames.filter((name) =>
toSchemaNames.includes(name),
);

// Fall back on the default result set names if there are no common ones.
const defaultFromResultSetName = fromSchemaNames.find((name) =>
name.startsWith("#"),
);
const defaultToResultSetName = toSchemaNames.find((name) =>
name.startsWith("#"),
);

if (
commonResultSetNames.length === 0 &&
!(defaultFromResultSetName || defaultToResultSetName)
) {
throw new Error(
"No common result sets found between the two queries. Please check that the queries are compatible.",
);
}

const currentResultSetName =
selectedResultSetName || commonResultSetNames[0];
const fromResultSet = await this.getResultSet(
fromSchemas,
currentResultSetName,
currentResultSetName || defaultFromResultSetName!,
from.completedQuery.query.resultsPaths.resultsPath,
);
const toResultSet = await this.getResultSet(
toSchemas,
currentResultSetName,
currentResultSetName || defaultToResultSetName!,
to.completedQuery.query.resultsPaths.resultsPath,
);
return [
commonResultSetNames,
currentResultSetName,
currentResultSetName ||
`${defaultFromResultSetName} <-> ${defaultToResultSetName}`,
fromResultSet,
toResultSet,
];
Expand Down
4 changes: 1 addition & 3 deletions extensions/ql-vscode/src/view/compare/Compare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ export function Compare(_: Record<string, never>): JSX.Element {
return (
<>
<div className="vscode-codeql__compare-header">
<div className="vscode-codeql__compare-header-item">
Table to compare:
</div>
<div className="vscode-codeql__compare-header-item">Comparing:</div>
<CompareSelector
availableResultSets={comparison.commonResultSetNames}
currentResultSetName={comparison.currentResultSetName}
Expand Down
6 changes: 5 additions & 1 deletion extensions/ql-vscode/src/view/compare/CompareSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ interface Props {
}

export default function CompareSelector(props: Props) {
return (
return props.availableResultSets.length ? (
// Handle case where there are shared result sets
<select
value={props.currentResultSetName}
onChange={(e) => props.updateResultSet(e.target.value)}
Expand All @@ -18,5 +19,8 @@ export default function CompareSelector(props: Props) {
</option>
))}
</select>
) : (
// Handle case where there are no shared result sets
<div>{props.currentResultSetName}</div>
);
}