Skip to content

Commit e0d2cbf

Browse files
authored
fix(amazonq): not allow generate completion request go through if Q is editing (NEP) (#7640)
… ## Problem - not allow generate completion request to go through if the edit is made by Q (only affecting NEP path) - add logging - ## Solution --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 89a455c commit e0d2cbf

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

packages/amazonq/src/app/inline/EditRendering/displayImage.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { InlineCompletionItemWithReferences } from '@aws/language-server-runtime
1313
import path from 'path'
1414
import { imageVerticalOffset } from './svgGenerator'
1515
import { AmazonQInlineCompletionItemProvider } from '../completion'
16+
import { vsCodeState } from 'aws-core-vscode/codewhisperer'
1617

1718
export class EditDecorationManager {
1819
private imageDecorationType: vscode.TextEditorDecorationType
@@ -211,7 +212,7 @@ export const decorationManager = EditDecorationManager.getDecorationManager()
211212
/**
212213
* Function to replace editor's content with new code
213214
*/
214-
function replaceEditorContent(editor: vscode.TextEditor, newCode: string): void {
215+
async function replaceEditorContent(editor: vscode.TextEditor, newCode: string): Promise<void> {
215216
const document = editor.document
216217
const fullRange = new vscode.Range(
217218
0,
@@ -220,7 +221,7 @@ function replaceEditorContent(editor: vscode.TextEditor, newCode: string): void
220221
document.lineAt(document.lineCount - 1).text.length
221222
)
222223

223-
void editor.edit((editBuilder) => {
224+
await editor.edit((editBuilder) => {
224225
editBuilder.replace(fullRange, newCode)
225226
})
226227
}
@@ -294,7 +295,12 @@ export async function displaySvgDecoration(
294295
getLogger().info('Edit suggestion accepted')
295296

296297
// Replace content
297-
replaceEditorContent(editor, newCode)
298+
try {
299+
vsCodeState.isCodeWhispererEditing = true
300+
await replaceEditorContent(editor, newCode)
301+
} finally {
302+
vsCodeState.isCodeWhispererEditing = false
303+
}
298304

299305
// Move cursor to end of the actual changed content
300306
const endPosition = getEndOfEditPosition(originalCode, newCode)

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,20 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
233233
position,
234234
context,
235235
triggerKind: context.triggerKind === InlineCompletionTriggerKind.Automatic ? 'Automatic' : 'Invoke',
236+
options: JSON.stringify(getAllRecommendationsOptions),
236237
})
237238

238239
// prevent concurrent API calls and write to shared state variables
239240
if (vsCodeState.isRecommendationsActive) {
240241
getLogger().info('Recommendations already active, returning empty')
241242
return []
242243
}
244+
245+
if (vsCodeState.isCodeWhispererEditing) {
246+
getLogger().info('Q is editing, returning empty')
247+
return []
248+
}
249+
243250
// yield event loop to let the document listen catch updates
244251
await sleep(1)
245252
// prevent user deletion invoking auto trigger
@@ -341,6 +348,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
341348
const t2 = performance.now()
342349

343350
logstr = logstr += `- number of suggestions: ${items.length}
351+
- sessionId: ${this.sessionManager.getActiveSession()?.sessionId}
344352
- first suggestion content (next line):
345353
${itemLog}
346354
- duration since trigger to before sending Flare call: ${t1 - t0}ms
@@ -388,11 +396,10 @@ ${itemLog}
388396
if (item.isInlineEdit) {
389397
// Check if Next Edit Prediction feature flag is enabled
390398
if (Experiments.instance.isExperimentEnabled('amazonqLSPNEP')) {
391-
void showEdits(item, editor, session, this.languageClient, this).then(() => {
392-
const t3 = performance.now()
393-
logstr = logstr + `- duration since trigger to NEP suggestion is displayed: ${t3 - t0}ms`
394-
this.logger.info(logstr)
395-
})
399+
await showEdits(item, editor, session, this.languageClient, this)
400+
const t3 = performance.now()
401+
logstr = logstr + `- duration since trigger to NEP suggestion is displayed: ${t3 - t0}ms`
402+
this.logger.info(logstr)
396403
}
397404
return []
398405
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export class RecommendationService {
7777
textDocument: request.textDocument,
7878
position: request.position,
7979
context: request.context,
80+
nextToken: request.partialResultToken,
8081
},
8182
})
8283
let result: InlineCompletionListWithReferences = await languageClient.sendRequest(

0 commit comments

Comments
 (0)