@@ -152,8 +152,7 @@ async function onCommitChange(payload: ChildToParent['commitChange']) {
152152 }
153153 await doChange ( fileUri , payload )
154154 // TODO: we can use Promise.all after preview has onChange event
155- await generatePreview ( fileUri , inputValue , rewrite )
156- await refreshSearchResult ( payload . id , {
155+ await refreshSearchResult ( payload . id , fileUri , {
157156 inputValue,
158157 rewrite,
159158 includeFile : filePath ,
@@ -176,20 +175,32 @@ async function doChange(
176175 await workspace . fs . writeFile ( fileUri , newBytes )
177176}
178177
179- async function refreshSearchResult ( id : number , query : SearchQuery ) {
178+ async function refreshSearchResult (
179+ id : number ,
180+ fileUri : Uri ,
181+ query : SearchQuery ,
182+ ) {
180183 const command = buildCommand ( {
181184 pattern : query . inputValue ,
182185 rewrite : query . rewrite ,
183186 includeFiles : [ query . includeFile ] ,
184187 } )
188+ const bytes = await workspace . fs . readFile ( fileUri )
189+ const { receiveResult, conclude } = bufferMaker ( bytes )
185190 await streamedPromise ( command ! , ( results : SgSearch [ ] ) => {
186191 // TODO, change this
187192 parentPort . postMessage ( 'searchResultStreaming' , {
188193 id,
189194 ...query ,
190195 searchResult : results . map ( splitByHighLightToken ) ,
191196 } )
197+ for ( const r of results ) {
198+ receiveResult ( r )
199+ }
192200 } )
201+ const final = conclude ( )
202+ const replaced = new TextDecoder ( 'utf-8' ) . decode ( final )
203+ previewContents . set ( fileUri . path , replaced )
193204}
194205
195206/**
0 commit comments