MCPcopy Create free account
hub / github.com/anthropics/claude-code / refresh

Function refresh

mods/diff/hooks/register.ts:363–470  ·  view source on GitHub ↗

* One read of the diff, covering every change seen before it starts. A call * made during a read is kept as one later read. So is a call made during * the wait after a slow read (refreshRestOf), unless `isAsked`. * * @param engine the bound host * @param isAsked skips that wait: true

(engine: Host, isAsked = false)

Source from the content-addressed store, hash-verified

361 * such as an opening pane
362 */
363 async function refresh(engine: Host, isAsked = false): Promise<void> {
364 const isHeld = isRefreshing || (timers.has('rest') && !isAsked)
365
366 if (isHeld) {
367 isRefreshQueued = true
368 isQueuedAsked ||= isAsked
369
370 if (!isRefreshing) {
371 void endOverdueRest(engine)
372 }
373
374 return
375 }
376
377 isRefreshing = true
378
379 let settle = (): void => undefined
380
381 reading = new Promise(resolve => {
382 settle = resolve
383 })
384
385 isRefreshQueued = false
386 isQueuedAsked = false
387 timers.get('refresh')?.cancel()
388 timers.delete('refresh')
389
390 const record = Record.recorderOf(engine)
391 const pinned = backend
392 const { epoch } = pin
393 const startedMs = await engine.now().catch(() => null)
394
395 let readKind: Git.FetchOutcome['kind'] | null = null
396 let fetchedMs: number | null = null
397
398 const fetched = async () => {
399 const outcome: Git.FetchOutcome = pinned
400 ? await pinned.fetchDiff(model.requestedMode)
401 : { kind: 'no-repository' }
402
403 return { outcome, endedMs: await engine.now().catch(() => null) }
404 }
405
406 try {
407 model = { ...model, isLoading: model.data === null }
408
409 const [read, messages] = await Promise.all([
410 fetched(),
411 engine.messages().catch((): SessionMessage[] => []),
412 ])
413
414 const { outcome } = read
415
416 fetchedMs = read.endedMs
417 model = PaneState.afterFetch(model, { outcome, messages })
418 readKind = outcome.kind
419
420 switch (outcome.kind) {

Callers 5

runQueuedFunction · 0.85
scheduleRefreshFunction · 0.85
showKeptFunction · 0.85
openPaneFunction · 0.85
actionsOfFunction · 0.85

Calls 10

endOverdueRestFunction · 0.85
fetchedFunction · 0.85
loadBodiesFunction · 0.85
settleFunction · 0.85
restFunction · 0.85
redrawFunction · 0.85
runQueuedFunction · 0.85
hasMethod · 0.80
deleteMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected