Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display length of shortest path in MRVA UI #3671

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions extensions/ql-vscode/src/view/common/CodePaths/CodePaths.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,6 +52,7 @@ export const CodePaths = ({
return (
<>
<ShowPathsLink onClick={onShowPathsClick}>Show paths</ShowPathsLink>
<Label>(Shortest: {getShortestPathLength(codeFlows)})</Label>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading