Skip to content

Commit

Permalink
feature: display shortest path for local query
Browse files Browse the repository at this point in the history
  • Loading branch information
p- committed Jul 29, 2024
1 parent 20617d2 commit 69a2677
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import type {
Result as ResultKeysResult,
ResultKey,
} from "./result-keys";
import { getAllPaths, keyToString } from "./result-keys";
import { getAllPaths, getShortestPath, keyToString } from "./result-keys";
import { info, listUnordered } from "./octicons";
import { selectableZebraStripe } from "./result-table-utils";
import { AlertTableDropdownIndicatorCell } from "./AlertTableDropdownIndicatorCell";
import { useCallback, useMemo } from "react";
import { SarifLocation } from "./locations/SarifLocation";
import { SarifMessageWithLocations } from "./locations/SarifMessageWithLocations";
import { AlertTablePathRow } from "./AlertTablePathRow";
import { VSCodeBadge } from "@vscode/webview-ui-toolkit/react";

interface Props {
result: Result;
Expand Down Expand Up @@ -99,6 +100,9 @@ export function AlertTableResultRow(props: Props) {
onClick={handleDropdownClick}
/>
<td className="vscode-codeql__icon-cell">{listUnordered}</td>
<td className="vscode-codeql__icon-cell">
<VSCodeBadge>{getShortestPath(result)}</VSCodeBadge>
</td>
<td colSpan={2}>{msg}</td>
</>
)}
Expand Down
6 changes: 6 additions & 0 deletions extensions/ql-vscode/src/view/results/result-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export function equalsNotUndefined(
);
}

export function getShortestPath(result: SarifResult): number {
const paths = getAllPaths(result);
const allPathLengths = paths.map((path) => path.locations.length);
return Math.min(...allPathLengths);
}

/**
* Returns the list of paths in the given SARIF result.
*
Expand Down

0 comments on commit 69a2677

Please sign in to comment.