Skip to content

Commit 856dc1b

Browse files
authored
fix(codewhisperer): more inline suggestion "hover config" updates (#2914)
1 parent 742a19c commit 856dc1b

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

src/codewhisperer/commands/onInlineAcceptance.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ export const acceptSuggestion = Commands.declare(
5959
references,
6060
},
6161
context.extensionContext.globalState
62-
)
62+
).finally(async () => {
63+
if (isInlineCompletionEnabled()) {
64+
// at the end of recommendation acceptance, clear recommendations.
65+
await InlineCompletionService.instance.clearInlineCompletionStates(editor)
66+
}
67+
})
6368
}
6469
)
6570
/**
@@ -149,7 +154,4 @@ export async function onInlineAcceptance(
149154
)
150155
}
151156
}
152-
153-
// at the end of recommendation acceptance, clear recommendations.
154-
await InlineCompletionService.instance.clearInlineCompletionStates(acceptanceEntry.editor)
155157
}

src/codewhisperer/service/inlineCompletionService.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,19 @@ export class InlineCompletionService {
240240
}
241241

242242
async clearInlineCompletionStates(editor: vscode.TextEditor | undefined) {
243-
await HoverConfigUtil.instance.restoreHoverConfig()
244-
vsCodeState.isCodeWhispererEditing = false
245-
ReferenceInlineProvider.instance.removeInlineReference()
246-
RecommendationHandler.instance.cancelPaginatedRequest()
247-
RecommendationHandler.instance.reportUserDecisionOfCurrentRecommendation(editor, -1)
248-
RecommendationHandler.instance.clearRecommendations()
249-
this.disposeInlineCompletion()
250-
this.setCodeWhispererStatusBarOk()
251-
this.disposeCommandOverrides()
252-
this.clearRejectionTimer()
243+
try {
244+
vsCodeState.isCodeWhispererEditing = false
245+
ReferenceInlineProvider.instance.removeInlineReference()
246+
RecommendationHandler.instance.cancelPaginatedRequest()
247+
RecommendationHandler.instance.reportUserDecisionOfCurrentRecommendation(editor, -1)
248+
RecommendationHandler.instance.clearRecommendations()
249+
this.disposeInlineCompletion()
250+
this.setCodeWhispererStatusBarOk()
251+
this.disposeCommandOverrides()
252+
} finally {
253+
this.clearRejectionTimer()
254+
await HoverConfigUtil.instance.restoreHoverConfig()
255+
}
253256
}
254257

255258
async tryShowRecommendation() {
@@ -267,9 +270,8 @@ export class InlineCompletionService {
267270
RecommendationHandler.instance.clearRecommendations()
268271
} else if (RecommendationHandler.instance.recommendations.length > 0) {
269272
RecommendationHandler.instance.moveStartPositionToSkipSpaces(editor)
270-
await HoverConfigUtil.instance.overwriteHoverConfig()
271273
this.subscribeSuggestionCommands()
272-
this.startRejectionTimer(editor)
274+
await this.startRejectionTimer(editor)
273275
await this.showRecommendation(0, true)
274276
}
275277
}
@@ -325,9 +327,6 @@ export class InlineCompletionService {
325327
this.inlineCompletionProvider?.getActiveItemIndex,
326328
indexShift
327329
)
328-
this.inlineCompletionProvider.onDidShow(e => {
329-
this._timer?.refresh()
330-
})
331330
this.inlineCompletionProviderDisposable?.dispose()
332331
// when suggestion is active, registering a new provider will let VS Code invoke inline API automatically
333332
this.inlineCompletionProviderDisposable = vscode.languages.registerInlineCompletionItemProvider(
@@ -375,24 +374,25 @@ export class InlineCompletionService {
375374

376375
private clearRejectionTimer() {
377376
if (this._timer !== undefined) {
378-
clearTimeout(this._timer)
377+
clearInterval(this._timer)
379378
this._timer = undefined
380379
}
381380
}
382381

383382
/*
384383
* This startRejectionTimer function is to mark recommendation as rejected
385-
* when the suggestions are no longer been shown to users for more than 10 seconds
384+
* when the suggestions are no longer been shown to users for more than 5 seconds
386385
*/
387386
private async startRejectionTimer(editor: vscode.TextEditor): Promise<void> {
388387
if (this._timer !== undefined) {
389388
return
390389
}
391-
this._timer = globals.clock.setTimeout(async () => {
390+
await HoverConfigUtil.instance.overwriteHoverConfig()
391+
this._timer = globals.clock.setInterval(async () => {
392392
if (!this.isSuggestionVisible()) {
393393
getLogger().info(`Clearing cached suggestion`)
394394
await this.clearInlineCompletionStates(editor)
395395
}
396-
}, 10 * 1000)
396+
}, 5 * 1000)
397397
}
398398
}

src/test/codewhisperer/service/completionProvider.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ describe('completionProviderService', function () {
6060
new vscode.Range(0, 0, 0, 0),
6161
1,
6262
"\n\t\tconsole.log('Hello world!');\n\t}",
63-
'',
64-
'',
63+
'test',
64+
'test',
6565
'OnDemand',
6666
'Line',
6767
'javascript',

0 commit comments

Comments
 (0)