diff --git a/src/ui/suggestionManager.ts b/src/ui/suggestionManager.ts index 7676fe6..74c5d38 100644 --- a/src/ui/suggestionManager.ts +++ b/src/ui/suggestionManager.ts @@ -87,6 +87,11 @@ export class SuggestionManager { ); } + validate(suggestion: SuggestionsSequence): SuggestionsSequence { + const commandText = this.#term.getCommandState().commandText; + return !commandText ? { data: "", rows: 0 } : suggestion; + } + async render(remainingLines: number): Promise { await this._loadSuggestions(); if (!this.#suggestBlob) { diff --git a/src/ui/ui-root.ts b/src/ui/ui-root.ts index fc1adc6..ae669d8 100644 --- a/src/ui/ui-root.ts +++ b/src/ui/ui-root.ts @@ -57,8 +57,9 @@ export const render = async (shell: Shell, underTest: boolean) => { writeOutput(data); } - setImmediate(async () => { - const suggestion = await suggestionManager.render(term.getCursorState().remainingLines); + process.nextTick(async () => { + // validate result to prevent stale suggestion being provided + const suggestion = suggestionManager.validate(await suggestionManager.render(term.getCursorState().remainingLines)); const commandState = term.getCommandState(); if (suggestion.data != "" && commandState.cursorTerminated && !commandState.hasOutput) {