-
Notifications
You must be signed in to change notification settings - Fork 746
fix(amazonq): Don't show inline completions when a edit is displayed #7839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
ac4c778
ade8208
fdf6178
c1f9a0e
e4c0cbc
aabf20f
beff023
f06ad9f
7ed2d30
a155f08
ae6cdfc
78ddc0a
ddefe0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ import { TelemetryHelper } from './telemetryHelper' | |
| import { Experiments, getLogger, sleep } from 'aws-core-vscode/shared' | ||
| import { messageUtils } from 'aws-core-vscode/utils' | ||
| import { showEdits } from './EditRendering/imageRenderer' | ||
| import { EditSuggestionState } from './editSuggestionState' | ||
| import { ICursorUpdateRecorder } from './cursorUpdateManager' | ||
| import { DocumentEventListener } from './documentEventListener' | ||
|
|
||
|
|
@@ -237,6 +238,63 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem | |
| await vscode.commands.executeCommand(`aws.amazonq.checkInlineSuggestionVisibility`) | ||
| } | ||
|
|
||
| /** | ||
| * Check if a completion suggestion is currently active/displayed | ||
| */ | ||
| public async isCompletionActive(): Promise<boolean> { | ||
| const session = this.sessionManager.getActiveSession() | ||
| if (session === undefined || !session.displayed || session.suggestions.some((item) => item.isInlineEdit)) { | ||
| return false | ||
| } | ||
|
|
||
| // Use VS Code command to check if inline suggestion is actually visible on screen | ||
| // This command only executes when inlineSuggestionVisible context is true | ||
| try { | ||
| await vscode.commands.executeCommand('aws.amazonq.checkInlineSuggestionVisibility') | ||
| return true | ||
| } catch { | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Batch discard telemetry for completion suggestions when edit suggestion is active | ||
| */ | ||
| public batchDiscardTelemetryForEditSuggestion(items: any[], session: any): void { | ||
| // Emit DISCARD telemetry for completion suggestions that can't be shown due to active edit | ||
| const completionSessionResult: { | ||
| [key: string]: { seen: boolean; accepted: boolean; discarded: boolean } | ||
| } = {} | ||
|
|
||
| for (const item of items) { | ||
| if (!item.isInlineEdit && item.itemId) { | ||
| completionSessionResult[item.itemId] = { | ||
| seen: false, | ||
| accepted: false, | ||
| discarded: true, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Send single telemetry event for all discarded items | ||
| if (Object.keys(completionSessionResult).length > 0) { | ||
| const params: LogInlineCompletionSessionResultsParams = { | ||
| sessionId: session.sessionId, | ||
| completionSessionResult, | ||
| firstCompletionDisplayLatency: session.firstCompletionDisplayLatency, | ||
| totalSessionDisplayTime: performance.now() - session.requestStartTime, | ||
| } | ||
| this.languageClient.sendNotification(this.logSessionResultMessageName, params) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Check if an edit suggestion is currently active | ||
| */ | ||
| private isEditSuggestionActive(): boolean { | ||
| return EditSuggestionState.isEditSuggestionActive() | ||
| } | ||
|
|
||
| // this method is automatically invoked by VS Code as user types | ||
| async provideInlineCompletionItems( | ||
| document: TextDocument, | ||
|
|
@@ -435,6 +493,14 @@ ${itemLog} | |
| // the user typed characters from invoking suggestion cursor position to receiving suggestion position | ||
| const typeahead = document.getText(new Range(position, editor.selection.active)) | ||
|
|
||
| // Check if an edit suggestion is currently active - if so, discard completion suggestions | ||
| if (this.isEditSuggestionActive()) { | ||
| this.batchDiscardTelemetryForEditSuggestion(items, session) | ||
| this.sessionManager.clear() | ||
| logstr += `- completion suggestions discarded due to active edit suggestion` | ||
| return [] | ||
| } | ||
|
|
||
|
||
| const itemsMatchingTypeahead = [] | ||
|
|
||
| for (const item of items) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /** | ||
| * Manages the state of edit suggestions to avoid circular dependencies | ||
| */ | ||
| export class EditSuggestionState { | ||
| private static isEditSuggestionCurrentlyActive = false | ||
|
|
||
| static setEditSuggestionActive(active: boolean): void { | ||
| this.isEditSuggestionCurrentlyActive = active | ||
| } | ||
|
|
||
| static isEditSuggestionActive(): boolean { | ||
| return this.isEditSuggestionCurrentlyActive | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you managed to get into this catch block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've implemented your timestamp-based solution using performance.now() in the checkInlineSuggestionVisibility()
method and checking if it was called within the last 50ms.