-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathCodeSnippetMessage.tsx
More file actions
95 lines (86 loc) · 2.65 KB
/
CodeSnippetMessage.tsx
File metadata and controls
95 lines (86 loc) · 2.65 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { styled } from "styled-components";
import { Link } from "../Link";
import type {
AnalysisMessage,
ResultSeverity,
} from "../../../variant-analysis/shared/analysis-result";
import { createRemoteFileRef } from "../../../common/location-link-utils";
import { VerticalSpace } from "../VerticalSpace";
import { sendTelemetry } from "../telemetry";
const getSeverityColor = (severity: ResultSeverity) => {
switch (severity) {
case "Recommendation":
return "var(--vscode-editorInfo-foreground)";
case "Warning":
return "var(--vscode-editorWarning-foreground)";
case "Error":
return "var(--vscode-editorError-foreground)";
}
};
const MessageText = styled.div`
font-size: small;
padding-left: 0.5em;
`;
type CodeSnippetMessageContainerProps = {
$severity: ResultSeverity;
};
const CodeSnippetMessageContainer = styled.div<CodeSnippetMessageContainerProps>`
border-color: var(--vscode-editor-snippetFinalTabstopHighlightBorder);
border-width: 0.1em;
border-style: solid;
border-left-color: ${(props) => getSeverityColor(props.$severity)};
border-left-width: 0.3em;
padding-top: 1em;
padding-bottom: 1em;
`;
const LocationLink = styled(Link)`
font-family: var(--vscode-editor-font-family);
`;
type CodeSnippetMessageProps = {
message: AnalysisMessage;
severity: ResultSeverity;
children: React.ReactNode;
};
const sendAlertMessageLinkTelemetry = () => sendTelemetry("alert-message-link");
export const CodeSnippetMessage = ({
message,
severity,
children,
}: CodeSnippetMessageProps) => {
return (
<CodeSnippetMessageContainer $severity={severity}>
<MessageText>
{message.tokens.map((token, index) => {
switch (token.t) {
case "text":
return <span key={index}>{token.text}</span>;
case "location":
return (
<LocationLink
key={index}
onClick={sendAlertMessageLinkTelemetry}
href={createRemoteFileRef(
token.location.fileLink,
token.location.highlightedRegion?.startLine,
token.location.highlightedRegion?.endLine,
token.location.highlightedRegion?.startColumn,
token.location.highlightedRegion?.endColumn,
)}
>
{token.text}
</LocationLink>
);
default:
return <></>;
}
})}
{children && (
<>
<VerticalSpace $size={2} />
{children}
</>
)}
</MessageText>
</CodeSnippetMessageContainer>
);
};