Skip to content

Commit 9c3b0b2

Browse files
authored
Display length of shortest path in MRVA UI (#3671)
* feature: display length of shortest path in MRVA UI #3659 * add entry to changelog * replace link in changelog + remove test-id
1 parent df06c75 commit 9c3b0b2

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

extensions/ql-vscode/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [UNRELEASED]
44

5+
- Update variant analysis view to display the length of the shortest path for path queries. [#3671](https://github.com/github/vscode-codeql/pull/3671)
6+
57
## 1.13.1 - 29 May 2024
68

79
- Fix a bug when re-importing test databases that erroneously showed old source code. [#3616](https://github.com/github/vscode-codeql/pull/3616)

extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ const ShowPathsLink = styled(VSCodeLink)`
1212
cursor: pointer;
1313
`;
1414

15+
const Label = styled.span`
16+
color: var(--vscode-descriptionForeground);
17+
margin-left: 10px;
18+
`;
19+
20+
function getShortestPathLength(codeFlows: CodeFlow[]): number {
21+
const allPathLengths = codeFlows
22+
.map((codeFlow) => codeFlow.threadFlows.length)
23+
.flat();
24+
return Math.min(...allPathLengths);
25+
}
26+
1527
export type CodePathsProps = {
1628
codeFlows: CodeFlow[];
1729
ruleDescription: string;
@@ -40,6 +52,7 @@ export const CodePaths = ({
4052
return (
4153
<>
4254
<ShowPathsLink onClick={onShowPathsClick}>Show paths</ShowPathsLink>
55+
<Label>(Shortest: {getShortestPathLength(codeFlows)})</Label>
4356
</>
4457
);
4558
};

extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ describe(CodePaths.name, () => {
2424
expect(screen.getByText("Show paths")).toBeInTheDocument();
2525
});
2626

27+
it("renders shortest path for code flows", () => {
28+
render();
29+
30+
expect(screen.getByText("(Shortest: 1)")).toBeInTheDocument();
31+
});
32+
2733
it("posts extension message when 'show paths' link clicked", async () => {
2834
render();
2935

0 commit comments

Comments
 (0)