Skip to content

Commit c9fd8d4

Browse files
committed
Remove unprincipled sort-by-location
Leave it so that clicking on the Location column goes back to sorting by location, but reflecting this as looking as the same as the default 'unsorted' view.
1 parent 6eb873d commit c9fd8d4

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export interface RawResultsSortState {
121121
}
122122

123123
export type InterpretedResultsSortColumn =
124-
'file-position' | 'alert-message';
124+
'alert-message';
125125

126126
export interface InterpretedResultsSortState {
127127
sortBy: InterpretedResultsSortColumn;

extensions/ql-vscode/src/interface.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ export function webviewUriToFileUri(webviewUri: string): Uri {
8787
}
8888

8989
function sortInterpretedResults(results: Sarif.Result[], sortState: InterpretedResultsSortState | undefined): void {
90-
function locToString(locs: Sarif.Location[] | undefined): string {
91-
if (locs === undefined) return '';
92-
return JSON.stringify(locs[0]) || '';
93-
}
94-
9590
if (sortState !== undefined) {
9691
const direction = sortState.sortDirection === SortDirection.asc ? 1 : -1;
9792
switch (sortState.sortBy) {
@@ -101,10 +96,6 @@ function sortInterpretedResults(results: Sarif.Result[], sortState: InterpretedR
10196
b.message.text === undefined ? 0 :
10297
direction * (a.message.text?.localeCompare(b.message.text)));
10398
break;
104-
case 'file-position':
105-
results.sort((a, b) =>
106-
direction * locToString(a.locations).localeCompare(locToString(b.locations)));
107-
break;
10899
default:
109100
assertNever(sortState.sortBy);
110101
}

extensions/ql-vscode/src/query-results.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ export class CompletedQuery implements QueryWithResults {
118118
}
119119

120120
async updateInterpretedSortState(_server: cli.CodeQLCliServer, sortState: InterpretedResultsSortState | undefined): Promise<void> {
121-
if (sortState !== undefined) {
122-
this.interpretedResultsSortState = sortState;
123-
}
121+
this.interpretedResultsSortState = sortState;
124122
}
125123
}
126124

extensions/ql-vscode/src/view/alert-table.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export interface PathTableState {
1515
selectedPathNode: undefined | Keys.PathNode;
1616
}
1717

18+
type InterpretedResultsColumn = InterpretedResultsSortColumn | 'file-position';
19+
1820
export class PathTable extends React.Component<PathTableProps, PathTableState> {
1921
constructor(props: PathTableProps) {
2022
super(props);
@@ -54,16 +56,21 @@ export class PathTable extends React.Component<PathTableProps, PathTableState> {
5456
}
5557
}
5658

57-
toggleSortStateForColumn(column: InterpretedResultsSortColumn): void {
59+
getNextSortState(column: InterpretedResultsColumn): InterpretedResultsSortState | undefined {
60+
if (column === 'file-position') {
61+
return undefined;
62+
}
5863
const oldSortState = this.props.resultSet.sortState;
5964
const prevDirection = oldSortState && oldSortState.sortBy === column ? oldSortState.sortDirection : undefined;
6065
const nextDirection = nextSortDirection(prevDirection);
61-
const sortState: InterpretedResultsSortState | undefined =
62-
nextDirection === undefined ? undefined :
63-
{ sortBy: column, sortDirection: nextDirection };
66+
return nextDirection === undefined ? undefined :
67+
{ sortBy: column, sortDirection: nextDirection };
68+
}
69+
70+
toggleSortStateForColumn(column: InterpretedResultsSortColumn | 'file-position'): void {
6471
vscode.postMessage({
6572
t: 'changeInterpretedSort',
66-
sortState,
73+
sortState: this.getNextSortState(column),
6774
});
6875
}
6976

@@ -74,7 +81,7 @@ export class PathTable extends React.Component<PathTableProps, PathTableState> {
7481
<tr>
7582
<th colSpan={2}></th>
7683
<th className={this.sortClass('alert-message') + ' vscode-codeql__alert-message-cell'} colSpan={2} onClick={() => this.toggleSortStateForColumn('alert-message')}>Message</th>
77-
<th className={this.sortClass('file-position') + ' vscode-codeql__location-cell'} onClick={() => this.toggleSortStateForColumn('file-position')}>Location</th>
84+
<th className={'sort-none vscode-codeql__location-cell'} onClick={() => this.toggleSortStateForColumn('file-position')}>Location</th>
7885
</tr>
7986
</thead>;
8087

0 commit comments

Comments
 (0)