fix(tui): avoid blocking reference autocomplete
This commit is contained in:
@@ -33,25 +33,23 @@ export class ReferenceAutocompleteProvider implements AutocompleteProvider {
|
|||||||
cursorCol: number,
|
cursorCol: number,
|
||||||
options: { signal: AbortSignal; force?: boolean },
|
options: { signal: AbortSignal; force?: boolean },
|
||||||
): Promise<AutocompleteSuggestions | null> {
|
): Promise<AutocompleteSuggestions | null> {
|
||||||
const basePromise = this.base.getSuggestions(lines, cursorLine, cursorCol, options)
|
|
||||||
const currentLine = lines[cursorLine]
|
const currentLine = lines[cursorLine]
|
||||||
/* v8 ignore next -- Editor always supplies its current state line. */
|
/* v8 ignore next -- Editor always supplies its current state line. */
|
||||||
if (currentLine === undefined) return basePromise
|
if (currentLine === undefined) return this.base.getSuggestions(lines, cursorLine, cursorCol, options)
|
||||||
const token = activeAtToken(currentLine, cursorCol)
|
const token = activeAtToken(currentLine, cursorCol)
|
||||||
if (token === undefined) {
|
if (token === undefined) {
|
||||||
this.files.invalidate()
|
this.files.invalidate()
|
||||||
return basePromise
|
return this.base.getSuggestions(lines, cursorLine, cursorCol, options)
|
||||||
}
|
}
|
||||||
const filePromise = this.files.list(token.query, options.signal).catch(() => [])
|
const filePromise = this.files.list(token.query, options.signal).catch(() => [])
|
||||||
const sessionPromise = this.sessions === undefined || token.quoted
|
const sessionPromise = this.sessions === undefined || token.quoted
|
||||||
? Promise.resolve([])
|
? Promise.resolve([])
|
||||||
: this.sessions.listCandidates(this.agent, token.query, undefined, options.signal).catch(() => [])
|
: this.sessions.listCandidates(this.agent, token.query, undefined, options.signal).catch(() => [])
|
||||||
const [base, fileCandidates, sessionCandidates] = await Promise.all([
|
// The command provider has no candidates for an active `@` token. Do not
|
||||||
basePromise,
|
// await it here: upstream may defer its empty result while the editor waits
|
||||||
filePromise,
|
// for this provider, which would suppress otherwise ready references.
|
||||||
sessionPromise,
|
const [fileCandidates, sessionCandidates] = await Promise.all([filePromise, sessionPromise])
|
||||||
])
|
if (options.signal.aborted) return null
|
||||||
if (options.signal.aborted) return base
|
|
||||||
const fileItems: AutocompleteItem[] = fileCandidates.flatMap((candidate) => {
|
const fileItems: AutocompleteItem[] = fileCandidates.flatMap((candidate) => {
|
||||||
const value = formatFileMention(candidate, token.quoted)
|
const value = formatFileMention(candidate, token.quoted)
|
||||||
if (value === undefined) return []
|
if (value === undefined) return []
|
||||||
@@ -75,8 +73,8 @@ export class ReferenceAutocompleteProvider implements AutocompleteProvider {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
const items = [...fileItems, ...sessionItems]
|
const items = [...fileItems, ...sessionItems]
|
||||||
if (items.length === 0) return base
|
if (items.length === 0) return null
|
||||||
return { items: [...items, ...(base?.items ?? [])], prefix: token.prefix }
|
return { items, prefix: token.prefix }
|
||||||
}
|
}
|
||||||
|
|
||||||
applyCompletion(
|
applyCompletion(
|
||||||
|
|||||||
Reference in New Issue
Block a user