MCPcopy Index your code
hub / github.com/anomalyco/opencode / load

Function load

packages/app/src/context/file.tsx:167–204  ·  view source on GitHub ↗
(input: string, options?: { force?: boolean })

Source from the content-addressed store, hash-verified

165 }
166
167 const load = (input: string, options?: { force?: boolean }) => {
168 const file = path.normalize(input)
169 if (!file) return Promise.resolve()
170
171 const directory = scope()
172 const key = `${directory}\n${file}`
173 ensure(file)
174
175 const current = store.file[file]
176 if (!options?.force && current?.loaded) return Promise.resolve()
177
178 const pending = inflight.get(key)
179 if (pending) return pending
180
181 setLoading(file)
182
183 const promise = sdk()
184 .client.file.read({ path: file })
185 .then((x) => {
186 if (scope() !== directory) return
187 const content = x.data
188 setLoaded(file, content)
189
190 if (!content) return
191 touchFileContent(file, approxBytes(content))
192 evictContent(new Set([file]))
193 })
194 .catch((e) => {
195 if (scope() !== directory) return
196 setLoadError(file, errorMessage(e, language.t("error.chain.unknown")))
197 })
198 .finally(() => {
199 inflight.delete(key)
200 })
201
202 inflight.set(key, promise)
203 return promise
204 }
205
206 const search = (query: string, dirs: "true" | "false") =>
207 sdk()

Callers 3

file.tsxFile · 0.70
loadDictFunction · 0.70
openDialogFunction · 0.50

Calls 14

touchFileContentFunction · 0.90
approxBytesFunction · 0.90
setLoadingFunction · 0.85
sdkFunction · 0.85
setLoadedFunction · 0.85
evictContentFunction · 0.85
setLoadErrorFunction · 0.85
scopeFunction · 0.70
ensureFunction · 0.70
errorMessageFunction · 0.70
getMethod · 0.65
readMethod · 0.65

Tested by

no test coverage detected