@@ -145,27 +145,26 @@ async function scanFile(
145145 state : ScanState ,
146146 out : WorkspaceGrepMatch [ ] ,
147147) : Promise < boolean > {
148- const before : NumberedLine [ ] = [ ] ;
148+ const before : WorkspaceGrepContextLine [ ] = [ ] ;
149149 const pending : PendingMatch [ ] = [ ] ;
150150
151151 for await ( const current of readLines ( db , path ) ) {
152+ const isMatch = matcher . test ( current . text ) ;
153+ const contextLine = { ...current , isMatch } ;
152154 for ( const item of pending ) {
153- item . match . context ?. push ( { ...current , isMatch : false } ) ;
155+ item . match . context ?. push ( { ...contextLine } ) ;
154156 item . remaining -= 1 ;
155157 }
156158 flushReady ( pending , out ) ;
157159 if ( state . accepted >= limit && pending . length === 0 ) return true ;
158160
159- if ( matcher . test ( current . text ) ) {
161+ if ( isMatch ) {
160162 const matchIndex = state . seen ;
161163 state . seen += 1 ;
162164 if ( matchIndex >= offset && state . accepted < limit ) {
163- const match : WorkspaceGrepMatch = { path, ... current } ;
165+ const match : WorkspaceGrepMatch = { path, line : current . line , text : current . text } ;
164166 if ( contextLines > 0 ) {
165- match . context = [
166- ...before . map ( ( line ) => ( { ...line , isMatch : false } ) ) ,
167- { ...current , isMatch : true } ,
168- ] ;
167+ match . context = [ ...before . map ( ( line ) => ( { ...line } ) ) , { ...contextLine } ] ;
169168 pending . push ( { match, remaining : contextLines } ) ;
170169 } else {
171170 out . push ( match ) ;
@@ -174,7 +173,7 @@ async function scanFile(
174173 }
175174 }
176175
177- before . push ( current ) ;
176+ before . push ( contextLine ) ;
178177 if ( before . length > contextLines ) before . shift ( ) ;
179178 if ( state . accepted >= limit && pending . length === 0 ) return true ;
180179 }
0 commit comments