Skip to content

Commit fc2e6d0

Browse files
committed
Use new raw result types in result and compare views
1 parent cb707ae commit fc2e6d0

17 files changed

Lines changed: 145 additions & 102 deletions

File tree

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import * as sarif from "sarif";
22
import {
3-
RawResultSet,
4-
ResultRow,
53
ResultSetSchema,
6-
Column,
74
ResolvableLocationValue,
85
} from "../common/bqrs-cli-types";
96
import {
@@ -25,7 +22,12 @@ import {
2522
} from "../model-editor/shared/view-state";
2623
import { Mode } from "../model-editor/shared/mode";
2724
import { QueryLanguage } from "./query-language";
28-
import { UrlValueResolvable } from "./raw-result-types";
25+
import {
26+
Column,
27+
RawResultSet,
28+
Row,
29+
UrlValueResolvable,
30+
} from "./raw-result-types";
2931

3032
/**
3133
* This module contains types and code that are shared between
@@ -36,7 +38,11 @@ export const SELECT_TABLE_NAME = "#select";
3638
export const ALERTS_TABLE_NAME = "alerts";
3739
export const GRAPH_TABLE_NAME = "graph";
3840

39-
export type RawTableResultSet = { t: "RawResultSet" } & RawResultSet;
41+
export type RawTableResultSet = {
42+
t: "RawResultSet";
43+
resultSet: RawResultSet;
44+
};
45+
4046
export type InterpretedResultSet<T> = {
4147
t: "InterpretedResultSet";
4248
readonly schema: ResultSetSchema;
@@ -372,8 +378,8 @@ export interface SetComparisonsMessage {
372378
* (or added) in the comparison.
373379
*/
374380
export type QueryCompareResult = {
375-
from: ResultRow[];
376-
to: ResultRow[];
381+
from: Row[];
382+
to: Row[];
377383
};
378384

379385
/**

extensions/ql-vscode/src/common/sarif-utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Sarif from "sarif";
22
import type { HighlightedRegion } from "../variant-analysis/shared/analysis-result";
3-
import { ResolvableLocationValue } from "../common/bqrs-cli-types";
3+
import { UrlValueResolvable } from "./raw-result-types";
44
import { isEmptyPath } from "./bqrs-utils";
55

66
export interface SarifLink {
@@ -16,7 +16,7 @@ interface NoLocation {
1616
}
1717

1818
type ParsedSarifLocation =
19-
| (ResolvableLocationValue & {
19+
| (UrlValueResolvable & {
2020
userVisibleFile: string;
2121
})
2222
// Resolvable locations have a `uri` field, but it will sometimes include
@@ -137,13 +137,15 @@ export function parseSarifLocation(
137137
// If the region property is absent, the physicalLocation object refers to the entire file.
138138
// Source: https://docs.oasis-open.org/sarif/sarif/v2.1.0/cs01/sarif-v2.1.0-cs01.html#_Toc16012638.
139139
return {
140+
type: "wholeFileLocation",
140141
uri: effectiveLocation,
141142
userVisibleFile,
142143
} as ParsedSarifLocation;
143144
} else {
144145
const region = parseSarifRegion(physicalLocation.region);
145146

146147
return {
148+
type: "lineColumnLocation",
147149
uri: effectiveLocation,
148150
userVisibleFile,
149151
...region,

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import { extLogger } from "../common/logging/vscode";
1010
import { CodeQLCliServer } from "../codeql-cli/cli";
1111
import { DatabaseManager } from "../databases/local-databases";
1212
import { jumpToLocation } from "../databases/local-databases/locations";
13-
import {
14-
transformBqrsResultSet,
15-
RawResultSet,
16-
BQRSInfo,
17-
} from "../common/bqrs-cli-types";
13+
import { BQRSInfo } from "../common/bqrs-cli-types";
1814
import resultsDiff from "./resultsDiff";
1915
import { CompletedLocalQueryInfo } from "../query-results";
2016
import { assertNever, getErrorMessage } from "../common/helpers-pure";
@@ -26,6 +22,8 @@ import {
2622
import { telemetryListener } from "../common/vscode/telemetry";
2723
import { redactableError } from "../common/errors";
2824
import { App } from "../common/app";
25+
import { bqrsToResultSet } from "../common/bqrs-result";
26+
import { RawResultSet } from "../common/raw-result-types";
2927

3028
interface ComparePair {
3129
from: CompletedLocalQueryInfo;
@@ -93,7 +91,7 @@ export class CompareView extends AbstractWebview<
9391
time: to.startTime,
9492
},
9593
},
96-
columns: fromResultSet.schema.columns,
94+
columns: fromResultSet.columns,
9795
commonResultSetNames,
9896
currentResultSetName,
9997
rows,
@@ -245,7 +243,7 @@ export class CompareView extends AbstractWebview<
245243
throw new Error(`Schema ${resultSetName} not found.`);
246244
}
247245
const chunk = await this.cliServer.bqrsDecode(resultsPath, resultSetName);
248-
return transformBqrsResultSet(schema, chunk);
246+
return bqrsToResultSet(schema, chunk);
249247
}
250248

251249
private compareResults(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { RawResultSet } from "../common/bqrs-cli-types";
21
import { QueryCompareResult } from "../common/interface-types";
2+
import { RawResultSet } from "../common/raw-result-types";
33

44
/**
55
* Compare the rows of two queries. Use deep equality to determine if
@@ -23,7 +23,7 @@ export default function resultsDiff(
2323
fromResults: RawResultSet,
2424
toResults: RawResultSet,
2525
): QueryCompareResult {
26-
if (fromResults.schema.columns.length !== toResults.schema.columns.length) {
26+
if (fromResults.columns.length !== toResults.columns.length) {
2727
throw new Error("CodeQL Compare: Columns do not match.");
2828
}
2929

extensions/ql-vscode/src/local-queries/results-view.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ import {
6060
shownLocationLineDecoration,
6161
jumpToLocation,
6262
} from "../databases/local-databases/locations";
63-
import {
64-
RawResultSet,
65-
transformBqrsResultSet,
66-
ResultSetSchema,
67-
} from "../common/bqrs-cli-types";
63+
import { bqrsToResultSet } from "../common/bqrs-result";
6864
import {
6965
AbstractWebview,
7066
WebviewPanelConfig,
@@ -76,6 +72,8 @@ import { redactableError } from "../common/errors";
7672
import { ResultsViewCommands } from "../common/commands";
7773
import { App } from "../common/app";
7874
import { Disposable } from "../common/disposable-object";
75+
import { RawResultSet } from "../common/raw-result-types";
76+
import { ResultSetSchema } from "../common/bqrs-cli-types";
7977

8078
/**
8179
* results-view.ts
@@ -136,7 +134,7 @@ function numPagesOfResultSet(
136134
const n =
137135
interpretation?.data.t === "GraphInterpretationData"
138136
? interpretation.data.dot.length
139-
: resultSet.schema.rows;
137+
: resultSet.totalRowCount;
140138

141139
return Math.ceil(n / pageSize);
142140
}
@@ -524,16 +522,16 @@ export class ResultsView extends AbstractWebview<
524522
offset: schema.pagination?.offsets[0],
525523
pageSize,
526524
});
527-
const resultSet = transformBqrsResultSet(schema, chunk);
525+
const resultSet = bqrsToResultSet(schema, chunk);
528526
fullQuery.completedQuery.setResultCount(
529-
interpretationPage?.numTotalResults || resultSet.schema.rows,
527+
interpretationPage?.numTotalResults || resultSet.totalRowCount,
530528
);
531529
const parsedResultSets: ParsedResultSets = {
532530
pageNumber: 0,
533531
pageSize,
534532
numPages: numPagesOfResultSet(resultSet, this._interpretation),
535533
numInterpretedPages: numInterpretedPages(this._interpretation),
536-
resultSet: { ...resultSet, t: "RawResultSet" },
534+
resultSet: { t: "RawResultSet", resultSet },
537535
selectedTable: undefined,
538536
resultSetNames,
539537
};
@@ -668,12 +666,12 @@ export class ResultsView extends AbstractWebview<
668666
pageSize,
669667
},
670668
);
671-
const resultSet = transformBqrsResultSet(schema, chunk);
669+
const resultSet = bqrsToResultSet(schema, chunk);
672670

673671
const parsedResultSets: ParsedResultSets = {
674672
pageNumber,
675673
pageSize,
676-
resultSet: { t: "RawResultSet", ...resultSet },
674+
resultSet: { t: "RawResultSet", resultSet },
677675
numPages: numPagesOfResultSet(resultSet),
678676
numInterpretedPages: numInterpretedPages(this._interpretation),
679677
selectedTable,

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

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Meta, StoryFn } from "@storybook/react";
55
import CompareTableComponent from "../../view/compare/CompareTable";
66

77
import "../../view/results/resultsView.css";
8+
import { ColumnKind } from "../../common/raw-result-types";
89

910
export default {
1011
title: "Compare/Compare Table",
@@ -32,8 +33,8 @@ CompareTable.args = {
3233
},
3334
},
3435
columns: [
35-
{ name: "a", kind: "e" },
36-
{ name: "b", kind: "e" },
36+
{ name: "a", kind: ColumnKind.Entity },
37+
{ name: "b", kind: ColumnKind.Entity },
3738
],
3839
commonResultSetNames: ["edges", "nodes", "subpaths", "#select"],
3940
currentResultSetName: "edges",
@@ -42,23 +43,31 @@ CompareTable.args = {
4243
to: [
4344
[
4445
{
45-
label: "url : String",
46-
url: {
47-
uri: "file:/home/runner/work/sql2o-example/sql2o-example/src/main/java/org/example/HelloController.java",
48-
startLine: 22,
49-
startColumn: 27,
50-
endLine: 22,
51-
endColumn: 57,
46+
type: "entity",
47+
value: {
48+
label: "url : String",
49+
url: {
50+
type: "lineColumnLocation",
51+
uri: "file:/home/runner/work/sql2o-example/sql2o-example/src/main/java/org/example/HelloController.java",
52+
startLine: 22,
53+
startColumn: 27,
54+
endLine: 22,
55+
endColumn: 57,
56+
},
5257
},
5358
},
5459
{
55-
label: "url",
56-
url: {
57-
uri: "file:/home/runner/work/sql2o-example/sql2o-example/src/main/java/org/example/HelloController.java",
58-
startLine: 23,
59-
startColumn: 33,
60-
endLine: 23,
61-
endColumn: 35,
60+
type: "entity",
61+
value: {
62+
label: "url",
63+
url: {
64+
type: "lineColumnLocation",
65+
uri: "file:/home/runner/work/sql2o-example/sql2o-example/src/main/java/org/example/HelloController.java",
66+
startLine: 23,
67+
startColumn: 33,
68+
endLine: 23,
69+
endColumn: 35,
70+
},
6271
},
6372
},
6473
],

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import * as React from "react";
33
import { SetComparisonsMessage } from "../../common/interface-types";
44
import RawTableHeader from "../results/RawTableHeader";
55
import { className } from "../results/result-table-utils";
6-
import { ResultRow } from "../../common/bqrs-cli-types";
76
import RawTableRow from "../results/RawTableRow";
87
import { vscode } from "../vscode-api";
98
import { sendTelemetry } from "../common/telemetry";
109
import TextButton from "../common/TextButton";
1110
import { styled } from "styled-components";
11+
import { Row } from "../../common/raw-result-types";
1212

1313
interface Props {
1414
comparison: SetComparisonsMessage;
@@ -31,7 +31,7 @@ export default function CompareTable(props: Props) {
3131
});
3232
}
3333

34-
function createRows(rows: ResultRow[], databaseUri: string) {
34+
function createRows(rows: Row[], databaseUri: string) {
3535
return (
3636
<tbody>
3737
{rows.map((row, rowIndex) => (

extensions/ql-vscode/src/view/results/RawTable.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@ import {
66
RawResultsSortState,
77
NavigateMsg,
88
NavigationDirection,
9-
RawTableResultSet,
109
} from "../../common/interface-types";
1110
import RawTableHeader from "./RawTableHeader";
1211
import RawTableRow from "./RawTableRow";
13-
import { ResultRow } from "../../common/bqrs-cli-types";
1412
import { onNavigation } from "./ResultsApp";
15-
import { tryGetResolvableLocation } from "../../common/bqrs-utils";
1613
import { sendTelemetry } from "../common/telemetry";
1714
import { assertNever } from "../../common/helpers-pure";
1815
import { EmptyQueryResultsMessage } from "./EmptyQueryResultsMessage";
1916
import { useScrollIntoView } from "./useScrollIntoView";
17+
import {
18+
isUrlValueResolvable,
19+
RawResultSet,
20+
} from "../../common/raw-result-types";
2021

2122
type RawTableProps = {
2223
databaseUri: string;
23-
resultSet: RawTableResultSet;
24+
resultSet: RawResultSet;
2425
sortState?: RawResultsSortState;
2526
offset: number;
2627
};
@@ -67,11 +68,12 @@ export function RawTable({
6768
return prevSelectedItem;
6869
}
6970
const cellData = rowData[nextColumn];
70-
if (cellData != null && typeof cellData === "object") {
71-
const location = tryGetResolvableLocation(cellData.url);
72-
if (location !== undefined) {
73-
jumpToLocation(location, databaseUri);
74-
}
71+
if (
72+
cellData?.type === "entity" &&
73+
cellData.value.url &&
74+
isUrlValueResolvable(cellData.value.url)
75+
) {
76+
jumpToLocation(cellData.value.url, databaseUri);
7577
}
7678
return { row: nextRow, column: nextColumn };
7779
});
@@ -126,7 +128,7 @@ export function RawTable({
126128
return <EmptyQueryResultsMessage />;
127129
}
128130

129-
const tableRows = dataRows.map((row: ResultRow, rowIndex: number) => (
131+
const tableRows = dataRows.map((row, rowIndex) => (
130132
<RawTableRow
131133
key={rowIndex}
132134
rowIndex={rowIndex + offset}
@@ -159,8 +161,8 @@ export function RawTable({
159161
return (
160162
<table className={className}>
161163
<RawTableHeader
162-
columns={resultSet.schema.columns}
163-
schemaName={resultSet.schema.name}
164+
columns={resultSet.columns}
165+
schemaName={resultSet.name}
164166
sortState={sortState}
165167
/>
166168
<tbody>{tableRows}</tbody>

extensions/ql-vscode/src/view/results/RawTableHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
SortDirection,
77
} from "../../common/interface-types";
88
import { nextSortDirection } from "./result-table-utils";
9-
import { Column } from "../../common/bqrs-cli-types";
9+
import { Column } from "../../common/raw-result-types";
1010

1111
interface Props {
1212
readonly columns: readonly Column[];

extensions/ql-vscode/src/view/results/RawTableRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as React from "react";
2-
import { ResultRow } from "../../common/bqrs-cli-types";
32
import { selectedRowClassName, zebraStripe } from "./result-table-utils";
43
import RawTableValue from "./RawTableValue";
4+
import { Row } from "../../common/raw-result-types";
55

66
interface Props {
77
rowIndex: number;
8-
row: ResultRow;
8+
row: Row;
99
databaseUri: string;
1010
className?: string;
1111
selectedColumn?: number;

0 commit comments

Comments
 (0)