fix(tui): await async slash command completions closes #2719
This commit is contained in:
@@ -218,12 +218,14 @@ export interface AutocompleteItem {
|
||||
description?: string;
|
||||
}
|
||||
|
||||
type Awaitable<T> = T | Promise<T>;
|
||||
|
||||
export interface SlashCommand {
|
||||
name: string;
|
||||
description?: string;
|
||||
// Function to get argument completions for this command
|
||||
// Returns null if no argument completion is available
|
||||
getArgumentCompletions?(argumentPrefix: string): AutocompleteItem[] | null;
|
||||
getArgumentCompletions?(argumentPrefix: string): Awaitable<AutocompleteItem[] | null>;
|
||||
}
|
||||
|
||||
export interface AutocompleteSuggestions {
|
||||
@@ -332,8 +334,8 @@ export class CombinedAutocompleteProvider implements AutocompleteProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
const argumentSuggestions = command.getArgumentCompletions(argumentText);
|
||||
if (!argumentSuggestions || argumentSuggestions.length === 0) {
|
||||
const argumentSuggestions = await command.getArgumentCompletions(argumentText);
|
||||
if (!Array.isArray(argumentSuggestions) || argumentSuggestions.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2141,7 +2141,7 @@ export class Editor implements Component, Focusable {
|
||||
|
||||
this.autocompleteAbort = undefined;
|
||||
|
||||
if (!suggestions || suggestions.items.length === 0) {
|
||||
if (!suggestions || !Array.isArray(suggestions.items) || suggestions.items.length === 0) {
|
||||
this.cancelAutocomplete();
|
||||
this.tui.requestRender();
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user