Skip to content

Commit

Permalink
Autocomplete: Fix loading indicator and deletion opt-out (#456)
Browse files Browse the repository at this point in the history
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,

<!-- Required. See
https://docs.sourcegraph.com/dev/background-information/testing_principles.
-->
  • Loading branch information
philipp-spiess authored Jul 31, 2023
1 parent 2d8fc61 commit d2c7005
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions vscode/src/completions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit d2c7005

Please sign in to comment.