From d2c70056960a2994633c209ad0926fb43c6989b4 Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Mon, 31 Jul 2023 16:38:55 +0200 Subject: [PATCH] Autocomplete: Fix loading indicator and deletion opt-out (#456) Two quick fixes for regressions I introduced in #412 - Loading indicator felt flaky so this this PR makes sure we start the indicator a bit earlier and terminate in any case. - The opt-out for a deletion case was wrong, causing it to skip the condition if the last action was a deletion and there was no cache response. This was not intended to be changed for now. The correct behavior should still be: If there is a deletion, ONLY continue if twe have an exact cache response. Otherwise return no completions. ## Test plan - tested locally, --- vscode/src/completions/index.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/vscode/src/completions/index.ts b/vscode/src/completions/index.ts index c41be09d203d..4dcec96821b2 100644 --- a/vscode/src/completions/index.ts +++ b/vscode/src/completions/index.ts @@ -154,8 +154,8 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr tracer?.({ params: { document, position, context } }) const abortController = new AbortController() + this.abortOpenCompletions() if (token) { - this.abortOpenCompletions() token.onCancellationRequested(() => abortController.abort()) this.abortOpenCompletions = () => abortController.abort() } @@ -225,7 +225,7 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr // render if you insert whitespace but not on the original place when you delete it // again cachedCompletions = this.config.cache?.get(prefix, false) - if (cachedCompletions && !cachedCompletions.isExactPrefix) { + if (!cachedCompletions?.isExactPrefix) { return emptyCompletions() } } @@ -348,6 +348,15 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr CompletionLogger.start(logId) + const stopLoading = this.config.statusBar.startLoading('Completions are being generated') + this.stopLoading = stopLoading + // Overwrite the abort handler to also update the loading state + const previousAbort = this.abortOpenCompletions + this.abortOpenCompletions = () => { + previousAbort() + stopLoading() + } + const contextResult = await this.config.contextFetcher({ document, prefix, @@ -365,16 +374,6 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr CompletionLogger.networkRequestStarted(logId, contextResult.logSummary) - const stopLoading = this.config.statusBar.startLoading('Completions are being generated') - this.stopLoading = stopLoading - - // Overwrite the abort handler to also update the loading state - const previousAbort = this.abortOpenCompletions - this.abortOpenCompletions = () => { - previousAbort() - stopLoading() - } - const completions = await this.requestManager.request( document.uri.toString(), logId,