Skip to content

Commit c347320

Browse files
committed
fix race condition when accepting inline completion
1 parent 5e256b9 commit c347320

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

packages/amazonq/src/app/inline/completion.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
vsCodeState,
3535
inlineCompletionsDebounceDelay,
3636
noInlineSuggestionsMsg,
37-
ReferenceInlineProvider,
3837
getDiagnosticsDifferences,
3938
getDiagnosticsOfCurrentFile,
4039
toIdeDiagnostics,
@@ -114,12 +113,7 @@ export class InlineCompletionManager implements Disposable {
114113
// TODO: also log the seen state for other suggestions in session
115114
// Calculate timing metrics before diagnostic delay
116115
const totalSessionDisplayTime = performance.now() - requestStartTime
117-
await sleep(1000)
118-
const diagnosticDiff = getDiagnosticsDifferences(
119-
this.sessionManager.getActiveSession()?.diagnosticsBeforeAccept,
120-
getDiagnosticsOfCurrentFile()
121-
)
122-
const params: LogInlineCompletionSessionResultsParams = {
116+
let params: LogInlineCompletionSessionResultsParams = {
123117
sessionId: sessionId,
124118
completionSessionResult: {
125119
[item.itemId]: {
@@ -130,10 +124,9 @@ export class InlineCompletionManager implements Disposable {
130124
},
131125
totalSessionDisplayTime: totalSessionDisplayTime,
132126
firstCompletionDisplayLatency: firstCompletionDisplayLatency,
133-
addedDiagnostics: diagnosticDiff.added.map((it) => toIdeDiagnostics(it)),
134-
removedDiagnostics: diagnosticDiff.removed.map((it) => toIdeDiagnostics(it)),
127+
addedDiagnostics: [],
128+
removedDiagnostics: [],
135129
}
136-
this.languageClient.sendNotification(this.logSessionResultMessageName, params)
137130
this.disposable.dispose()
138131
this.disposable = languages.registerInlineCompletionItemProvider(
139132
CodeWhispererConstants.platformLanguageIds,
@@ -147,23 +140,23 @@ export class InlineCompletionManager implements Disposable {
147140
)
148141
ReferenceLogViewProvider.instance.addReferenceLog(referenceLog)
149142
ReferenceHoverProvider.instance.addCodeReferences(item.insertText as string, item.references)
150-
151-
// Show codelense for 5 seconds.
152-
ReferenceInlineProvider.instance.setInlineReference(
153-
startLine,
154-
item.insertText as string,
155-
item.references
156-
)
157-
setTimeout(() => {
158-
ReferenceInlineProvider.instance.removeInlineReference()
159-
}, 5000)
160143
}
161144
if (item.mostRelevantMissingImports?.length) {
162145
await ImportAdderProvider.instance.onAcceptRecommendation(editor, item, startLine)
163146
}
164147
this.sessionManager.incrementSuggestionCount()
165-
// clear session manager states once accepted
148+
// clear session manager states immediately once accepted
166149
this.sessionManager.clear()
150+
151+
// compute diagnostics differences AFTER the session is cleared.
152+
await sleep(1000)
153+
const diagnosticDiff = getDiagnosticsDifferences(
154+
this.sessionManager.getActiveSession()?.diagnosticsBeforeAccept,
155+
getDiagnosticsOfCurrentFile()
156+
)
157+
params.addedDiagnostics = diagnosticDiff.added.map((it) => toIdeDiagnostics(it))
158+
params.removedDiagnostics = diagnosticDiff.removed.map((it) => toIdeDiagnostics(it))
159+
this.languageClient.sendNotification(this.logSessionResultMessageName, params)
167160
}
168161
commands.registerCommand('aws.amazonq.acceptInline', onInlineAcceptance)
169162

0 commit comments

Comments
 (0)