[workbench] Improve asynchronous tool use (#30184)

GitOrigin-RevId: d1bd33469b557c29968049af99b9c3c85731151d
This commit is contained in:
Alf Eaton
2025-12-09 13:23:21 +00:00
committed by Copybot
parent 851f0c92b1
commit b811da0695
13 changed files with 40 additions and 25 deletions
@@ -54,11 +54,14 @@ export type EditorManager = {
getCurrentDocValue: () => string | null
getCurrentDocumentId: () => DocId | null
setIgnoringExternalUpdates: (value: boolean) => void
openDocWithId: (docId: string, options?: OpenDocOptions) => void
openDocWithId: (
docId: string,
options?: OpenDocOptions
) => Promise<Doc | undefined>
openDoc: (document: Doc, options?: OpenDocOptions) => Promise<Doc | undefined>
openDocs: OpenDocuments
openFileWithId: (fileId: string) => void
openInitialDoc: (docId?: string) => void
openInitialDoc: (docId?: string) => Promise<Doc | undefined>
isLoading: boolean
jumpToLine: (options: GotoLineOptions) => void
debugTimers: React.MutableRefObject<Record<string, number>>
@@ -486,12 +489,12 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
)
const openDocWithId = useCallback(
(docId: string, options: OpenDocOptions = {}) => {
async (docId: string, options: OpenDocOptions = {}) => {
const doc = findDocEntityById(fileTreeData, docId)
if (!doc) {
return
}
openDoc(doc, options)
return await openDoc(doc, options)
},
[fileTreeData, openDoc]
)
@@ -513,11 +516,11 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
)
const openInitialDoc = useCallback(
(fallbackDocId?: string) => {
async (fallbackDocId?: string) => {
const docId =
customLocalStorage.getItem(currentDocumentIdStorageKey) || fallbackDocId
if (docId) {
openDocWithId(docId)
return await openDocWithId(docId)
}
},
[currentDocumentIdStorageKey, openDocWithId]
@@ -580,7 +583,7 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
}
const handleProjectJoined = () => {
openDoc(doc, { forceReopen: true })
return openDoc(doc, { forceReopen: true })
}
eventEmitter.once('project:joined', handleProjectJoined)