fix: stale suggestion appearing after command execution (#185)

Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
Chapman Pendery
2024-03-05 21:30:35 -08:00
committed by GitHub
parent 8fecb01064
commit ec841bba31
2 changed files with 8 additions and 2 deletions
+5
View File
@@ -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<SuggestionsSequence> {
await this._loadSuggestions();
if (!this.#suggestBlob) {
+3 -2
View File
@@ -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) {