Skip to content

Commit 7ed2d30

Browse files
committed
fix: use timestamp-based approach for inline suggestion visibility check
- Add lastVisibleTime property to CodeWhispererSession - Update checkInlineSuggestionVisibility to record timestamp - Replace try/catch with timestamp comparison in isCompletionActive - Addresses Lei's concern about catch block never executing
1 parent f06ad9f commit 7ed2d30

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,9 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
249249

250250
// Use VS Code command to check if inline suggestion is actually visible on screen
251251
// This command only executes when inlineSuggestionVisible context is true
252-
try {
253-
await vscode.commands.executeCommand('aws.amazonq.checkInlineSuggestionVisibility')
254-
return true
255-
} catch {
256-
return false
257-
}
252+
await vscode.commands.executeCommand('aws.amazonq.checkInlineSuggestionVisibility')
253+
const isInlineSuggestionVisible = performance.now() - session.lastVisibleTime < 50
254+
return isInlineSuggestionVisible
258255
}
259256

260257
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export interface CodeWhispererSession {
2626
triggerOnAcceptance?: boolean
2727
// whether any suggestion in this session was displayed on screen
2828
displayed: boolean
29+
// timestamp when the suggestion was last visible
30+
lastVisibleTime: number
2931
}
3032

3133
export class SessionManager {
@@ -52,6 +54,7 @@ export class SessionManager {
5254
firstCompletionDisplayLatency,
5355
diagnosticsBeforeAccept,
5456
displayed: false,
57+
lastVisibleTime: 0,
5558
}
5659
this._currentSuggestionIndex = 0
5760
}
@@ -134,6 +137,7 @@ export class SessionManager {
134137
public checkInlineSuggestionVisibility() {
135138
if (this.activeSession) {
136139
this.activeSession.displayed = true
140+
this.activeSession.lastVisibleTime = performance.now()
137141
}
138142
}
139143

0 commit comments

Comments
 (0)