From 9c3b0b24c9cd0f9d99abea0eac5bee0e3e18a12d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20St=C3=B6ckli?= Date: Thu, 25 Jul 2024 11:15:22 +0200 Subject: [PATCH] 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 --- extensions/ql-vscode/CHANGELOG.md | 2 ++ .../src/view/common/CodePaths/CodePaths.tsx | 13 +++++++++++++ .../common/CodePaths/__tests__/CodePaths.spec.tsx | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index f3aafcb439f..2e12d388f5c 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -2,6 +2,8 @@ ## [UNRELEASED] +- Update variant analysis view to display the length of the shortest path for path queries. [#3671](https://github.com/github/vscode-codeql/pull/3671) + ## 1.13.1 - 29 May 2024 - Fix a bug when re-importing test databases that erroneously showed old source code. [#3616](https://github.com/github/vscode-codeql/pull/3616) diff --git a/extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx b/extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx index 56809523781..301107afcc5 100644 --- a/extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx +++ b/extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx @@ -12,6 +12,18 @@ const ShowPathsLink = styled(VSCodeLink)` cursor: pointer; `; +const Label = styled.span` + color: var(--vscode-descriptionForeground); + margin-left: 10px; +`; + +function getShortestPathLength(codeFlows: CodeFlow[]): number { + const allPathLengths = codeFlows + .map((codeFlow) => codeFlow.threadFlows.length) + .flat(); + return Math.min(...allPathLengths); +} + export type CodePathsProps = { codeFlows: CodeFlow[]; ruleDescription: string; @@ -40,6 +52,7 @@ export const CodePaths = ({ return ( <> Show paths + ); }; diff --git a/extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx b/extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx index bfea6df23bf..60896c1b618 100644 --- a/extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx +++ b/extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx @@ -24,6 +24,12 @@ describe(CodePaths.name, () => { expect(screen.getByText("Show paths")).toBeInTheDocument(); }); + it("renders shortest path for code flows", () => { + render(); + + expect(screen.getByText("(Shortest: 1)")).toBeInTheDocument(); + }); + it("posts extension message when 'show paths' link clicked", async () => { render();