Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions packages/amazonq/src/app/inline/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 suggestions from previous session`)
// if no such suggestions, report the previous suggestion as Reject
const params: LogInlineCompletionSessionResultsParams = {
sessionId: prevSessionId,
completionSessionResult: {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions packages/amazonq/src/app/inline/recommendationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class RecommendationService {
firstResult.sessionId,
firstResult.items,
requestStartTime,
position,
firstCompletionDisplayLatency
)

Expand Down
5 changes: 4 additions & 1 deletion packages/amazonq/src/app/inline/sessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,6 +13,7 @@ interface CodeWhispererSession {
isRequestInProgress: boolean
requestStartTime: number
firstCompletionDisplayLatency?: number
startPosition: vscode.Position
}

export class SessionManager {
Expand All @@ -25,13 +26,15 @@ export class SessionManager {
sessionId: string,
suggestions: InlineCompletionItemWithReferences[],
requestStartTime: number,
startPosition: vscode.Position,
firstCompletionDisplayLatency?: number
) {
this.activeSession = {
sessionId,
suggestions,
isRequestInProgress: true,
requestStartTime,
startPosition,
firstCompletionDisplayLatency,
}
}
Expand Down
Loading