@@ -4,6 +4,7 @@ import { CodeSnippet, FileLink, HighlightedRegion, AnalysisMessage, ResultSeveri
44import { Box , Link } from '@primer/react' ;
55import VerticalSpace from './VerticalSpace' ;
66import { createRemoteFileRef } from '../../pure/location-link-utils' ;
7+ import { parseHighlightedLine , shouldHighlightLine } from '../../pure/sarif-utils' ;
78
89const borderColor = 'var(--vscode-editor-snippetFinalTabstopHighlightBorder)' ;
910const warningColor = '#966C23' ;
@@ -22,18 +23,6 @@ const getSeverityColor = (severity: ResultSeverity) => {
2223
2324const replaceSpaceChar = ( text : string ) => text . replaceAll ( ' ' , '\u00a0' ) ;
2425
25- const shouldHighlightLine = ( lineNumber : number , highlightedRegion : HighlightedRegion ) => {
26- if ( lineNumber < highlightedRegion . startLine ) {
27- return false ;
28- }
29-
30- if ( highlightedRegion . endLine == undefined ) {
31- return lineNumber == highlightedRegion . startLine ;
32- }
33-
34- return lineNumber <= highlightedRegion . endLine ;
35- } ;
36-
3726const Container = styled . div `
3827 font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
3928 font-size: x-small;
@@ -142,31 +131,13 @@ const CodeLine = ({
142131 return < PlainLine text = { line } /> ;
143132 }
144133
145- const isSingleLineHighlight = highlightedRegion . endLine === undefined ;
146- const isFirstHighlightedLine = lineNumber === highlightedRegion . startLine ;
147- const isLastHighlightedLine = lineNumber === highlightedRegion . endLine ;
148-
149- const highlightStartColumn = isSingleLineHighlight
150- ? highlightedRegion . startColumn
151- : isFirstHighlightedLine
152- ? highlightedRegion . startColumn
153- : 0 ;
154-
155- const highlightEndColumn = isSingleLineHighlight
156- ? highlightedRegion . endColumn
157- : isLastHighlightedLine
158- ? highlightedRegion . endColumn
159- : line . length + 1 ;
160-
161- const section1 = line . substring ( 0 , highlightStartColumn - 1 ) ;
162- const section2 = line . substring ( highlightStartColumn - 1 , highlightEndColumn - 1 ) ;
163- const section3 = line . substring ( highlightEndColumn - 1 , line . length ) ;
134+ const partiallyHighlightedLine = parseHighlightedLine ( line , lineNumber , highlightedRegion ) ;
164135
165136 return (
166137 < >
167- < PlainLine text = { section1 } />
168- < HighlightedLine text = { section2 } />
169- < PlainLine text = { section3 } />
138+ < PlainLine text = { partiallyHighlightedLine . plainSection1 } />
139+ < HighlightedLine text = { partiallyHighlightedLine . highlightedSection } />
140+ < PlainLine text = { partiallyHighlightedLine . plainSection2 } />
170141 </ >
171142 ) ;
172143} ;
0 commit comments