Skip to content

Commit ee22dff

Browse files
feat: add refreshResults
1 parent cc1470e commit ee22dff

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/extension/preview.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ import {
1818
TextEditorRevealType,
1919
TabInputTextDiff,
2020
} from 'vscode'
21-
import type { ChildToParent, SearchQuery, SgSearch } from '../types'
21+
import type {
22+
ChildToParent,
23+
DisplayResult,
24+
SearchQuery,
25+
SgSearch,
26+
} from '../types'
2227
import { parentPort, streamedPromise } from './common'
2328
import { buildCommand, splitByHighLightToken } from './search'
2429
import path from 'path'
@@ -182,20 +187,20 @@ async function refreshSearchResult(
182187
})
183188
const bytes = await workspace.fs.readFile(fileUri)
184189
const { receiveResult, conclude } = bufferMaker(bytes)
190+
const updatedResults: DisplayResult[] = []
185191
await streamedPromise(command!, (results: SgSearch[]) => {
186-
// TODO, change this
187-
parentPort.postMessage('searchResultStreaming', {
188-
id,
189-
...query,
190-
searchResult: results.map(splitByHighLightToken),
191-
})
192192
for (const r of results) {
193193
receiveResult(r.replacement!, r.range.byteOffset)
194+
updatedResults.push(splitByHighLightToken(r))
194195
}
195196
})
196197
const final = conclude()
197198
const replaced = new TextDecoder('utf-8').decode(final)
198199
previewContents.set(fileUri.path, replaced)
200+
parentPort.postMessage('refreshSearchResult', {
201+
id,
202+
updatedResults,
203+
})
199204
}
200205

201206
/**

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export interface ParentToChild {
5454
setIncludeFile: {
5555
includeFile: string
5656
}
57+
refreshSearchResult: {
58+
id: number
59+
updatedResults: DisplayResult[]
60+
}
5761
}
5862

5963
export interface ChildToParent {

0 commit comments

Comments
 (0)