From c104e804865fb453c2116f349d78e79b6325f4ba Mon Sep 17 00:00:00 2001 From: Lei Gao Date: Tue, 17 Jun 2025 15:14:22 -0700 Subject: [PATCH 1/2] improve typeahead experience --- packages/amazonq/src/app/inline/completion.ts | 38 +++++++++++++++++-- .../src/app/inline/recommendationService.ts | 1 + .../amazonq/src/app/inline/sessionManager.ts | 5 ++- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/packages/amazonq/src/app/inline/completion.ts b/packages/amazonq/src/app/inline/completion.ts index a4297cb4f53..69a525801f3 100644 --- a/packages/amazonq/src/app/inline/completion.ts +++ b/packages/amazonq/src/app/inline/completion.ts @@ -208,10 +208,41 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem return [] } - // report suggestion state for previous suggestions if they exist - const prevSessionId = this.sessionManager.getActiveSession()?.sessionId + // handling previous session + const prevSession = this.sessionManager.getActiveSession() + const prevSessionId = prevSession?.sessionId const prevItemId = this.sessionManager.getActiveRecommendation()?.[0]?.itemId - if (prevSessionId && prevItemId) { + const prevStartPosition = prevSession?.startPosition + const editor = window.activeTextEditor + if (prevSession && prevSessionId && prevItemId && prevStartPosition) { + const prefix = document.getText(new Range(prevStartPosition, position)) + const prevItemMatchingPrefix = [] + for (const item of this.sessionManager.getActiveRecommendation()) { + const text = typeof item.insertText === 'string' ? item.insertText : item.insertText.value + if (text.startsWith(prefix) && position.isAfterOrEqual(prevStartPosition)) { + item.command = { + command: 'aws.amazonq.acceptInline', + title: 'On acceptance', + arguments: [ + prevSessionId, + item, + editor, + prevSession?.requestStartTime, + position.line, + prevSession?.firstCompletionDisplayLatency, + ], + } + item.range = new Range(prevStartPosition, position) + prevItemMatchingPrefix.push(item as InlineCompletionItem) + } + } + // re-use previous suggestions as long as new typed prefix matches + if (prevItemMatchingPrefix.length > 0) { + getLogger().debug(`Re-using suggestions that match user typed characters`) + return prevItemMatchingPrefix + } + getLogger().debug(`Auto rejecting previous suggestion in session`) + // if no such suggestions, report the previous suggestion as Reject const params: LogInlineCompletionSessionResultsParams = { sessionId: prevSessionId, completionSessionResult: { @@ -242,7 +273,6 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem const items = this.sessionManager.getActiveRecommendation() const itemId = this.sessionManager.getActiveRecommendation()?.[0]?.itemId const session = this.sessionManager.getActiveSession() - const editor = window.activeTextEditor // Show message to user when manual invoke fails to produce results. if (items.length === 0 && context.triggerKind === InlineCompletionTriggerKind.Invoke) { diff --git a/packages/amazonq/src/app/inline/recommendationService.ts b/packages/amazonq/src/app/inline/recommendationService.ts index ac0b16f140c..eab2fc874b8 100644 --- a/packages/amazonq/src/app/inline/recommendationService.ts +++ b/packages/amazonq/src/app/inline/recommendationService.ts @@ -66,6 +66,7 @@ export class RecommendationService { firstResult.sessionId, firstResult.items, requestStartTime, + position, firstCompletionDisplayLatency ) diff --git a/packages/amazonq/src/app/inline/sessionManager.ts b/packages/amazonq/src/app/inline/sessionManager.ts index 10f436344bc..6e052ddbfbe 100644 --- a/packages/amazonq/src/app/inline/sessionManager.ts +++ b/packages/amazonq/src/app/inline/sessionManager.ts @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - +import * as vscode from 'vscode' import { InlineCompletionItemWithReferences } from '@aws/language-server-runtimes-types' // TODO: add more needed data to the session interface @@ -13,6 +13,7 @@ interface CodeWhispererSession { isRequestInProgress: boolean requestStartTime: number firstCompletionDisplayLatency?: number + startPosition: vscode.Position } export class SessionManager { @@ -25,6 +26,7 @@ export class SessionManager { sessionId: string, suggestions: InlineCompletionItemWithReferences[], requestStartTime: number, + startPosition: vscode.Position, firstCompletionDisplayLatency?: number ) { this.activeSession = { @@ -32,6 +34,7 @@ export class SessionManager { suggestions, isRequestInProgress: true, requestStartTime, + startPosition, firstCompletionDisplayLatency, } } From 5bbe022049d0c7b4f5d8d7d1a718b818df4b955b Mon Sep 17 00:00:00 2001 From: Lei Gao Date: Tue, 17 Jun 2025 15:18:00 -0700 Subject: [PATCH 2/2] update --- packages/amazonq/src/app/inline/completion.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/amazonq/src/app/inline/completion.ts b/packages/amazonq/src/app/inline/completion.ts index 69a525801f3..1e0716097bb 100644 --- a/packages/amazonq/src/app/inline/completion.ts +++ b/packages/amazonq/src/app/inline/completion.ts @@ -241,7 +241,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem getLogger().debug(`Re-using suggestions that match user typed characters`) return prevItemMatchingPrefix } - getLogger().debug(`Auto rejecting previous suggestion in session`) + getLogger().debug(`Auto rejecting suggestions from previous session`) // if no such suggestions, report the previous suggestion as Reject const params: LogInlineCompletionSessionResultsParams = { sessionId: prevSessionId,