diff --git a/extensions/ql-vscode/src/remote-queries/view/FileCodeSnippet.tsx b/extensions/ql-vscode/src/remote-queries/view/FileCodeSnippet.tsx index 23978acd3c7..33e049c9048 100644 --- a/extensions/ql-vscode/src/remote-queries/view/FileCodeSnippet.tsx +++ b/extensions/ql-vscode/src/remote-queries/view/FileCodeSnippet.tsx @@ -55,71 +55,61 @@ const MessageContainer = styled.div` padding-bottom: 0.5em; `; -const PlainLine = ({ text }: { text: string }) => { +const PlainCode = ({ text }: { text: string }) => { return {replaceSpaceAndTabChar(text)}; }; -const HighlightedLine = ({ text }: { text: string }) => { +const HighlightedCode = ({ text }: { text: string }) => { return {replaceSpaceAndTabChar(text)}; }; const Message = ({ message, - currentLineNumber, - highlightedRegion, borderLeftColor, children }: { message: AnalysisMessage, - currentLineNumber: number, - highlightedRegion?: HighlightedRegion, borderLeftColor: string, children: React.ReactNode }) => { - if (!highlightedRegion || highlightedRegion.endLine !== currentLineNumber) { - return <>>; - } - - return - - - {message.tokens.map((token, index) => { - switch (token.t) { - case 'text': - return {token.text}; - case 'location': - return - {token.text} - ; - default: - return <>>; - } - })} - {children && <> - - {children} - > + return + + {message.tokens.map((token, index) => { + switch (token.t) { + case 'text': + return {token.text}; + case 'location': + return + {token.text} + ; + default: + return <>>; } - - - ; + })} + {children && <> + + {children} + > + } + + ; }; -const CodeLine = ({ +const Code = ({ line, lineNumber, highlightedRegion @@ -129,20 +119,80 @@ const CodeLine = ({ highlightedRegion?: HighlightedRegion }) => { if (!highlightedRegion || !shouldHighlightLine(lineNumber, highlightedRegion)) { - return ; + return ; } const partiallyHighlightedLine = parseHighlightedLine(line, lineNumber, highlightedRegion); return ( <> - - - + + + > ); }; +const Line = ({ + line, + lineIndex, + startingLineIndex, + highlightedRegion, + severity, + message, + messageChildren +}: { + line: string, + lineIndex: number, + startingLineIndex: number, + highlightedRegion?: HighlightedRegion, + severity?: ResultSeverity, + message?: AnalysisMessage, + messageChildren?: React.ReactNode, +}) => { + const shouldShowMessage = message && + severity && + highlightedRegion && + highlightedRegion.endLine == startingLineIndex + lineIndex; + + return + + + {startingLineIndex + lineIndex} + + + + + + {shouldShowMessage && + + + {messageChildren} + + + } + ; +}; + const FileCodeSnippet = ({ fileLink, codeSnippet, @@ -173,6 +223,12 @@ const FileCodeSnippet = ({ {fileLink.filePath} + {message && severity && + + {messageChildren} + } ); } @@ -186,40 +242,16 @@ const FileCodeSnippet = ({ {code.map((line, index) => ( - - - - {startingLine + index} - - - - - - {message && severity && - {messageChildren} - } - + ))}