forked from github/vscode-codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodePaths.tsx
58 lines (51 loc) · 1.25 KB
/
CodePaths.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { styled } from "styled-components";
import { VSCodeLink } from "@vscode/webview-ui-toolkit/react";
import type {
AnalysisMessage,
CodeFlow,
ResultSeverity,
} from "../../../variant-analysis/shared/analysis-result";
import { vscode } from "../../vscode-api";
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;
message: AnalysisMessage;
severity: ResultSeverity;
};
export const CodePaths = ({
codeFlows,
ruleDescription,
message,
severity,
}: CodePathsProps) => {
const onShowPathsClick = () => {
vscode.postMessage({
t: "showDataFlowPaths",
dataFlowPaths: {
codeFlows,
ruleDescription,
message,
severity,
},
});
};
return (
<>
<ShowPathsLink onClick={onShowPathsClick}>Show paths</ShowPathsLink>
<Label>(Shortest: {getShortestPathLength(codeFlows)})</Label>
</>
);
};