Skip to content

Commit 0d4cf7e

Browse files
committed
fix unit test
1 parent ca98f9c commit 0d4cf7e

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

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

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -136,27 +136,35 @@ export class SessionManager {
136136
// Ideally use this API handleDidShowCompletionItem
137137
// https://github.com/microsoft/vscode/blob/main/src/vscode-dts/vscode.proposed.inlineCompletionsAdditions.d.ts#L83
138138
updateCodeReferenceAndImports() {
139-
this.clearReferenceInlineHintsAndImportHints()
140-
if (this.activeSession?.suggestions && this.activeSession.suggestions.length > 0) {
141-
const reference = this.activeSession.suggestions[this._currentSuggestionIndex].references
142-
if (reference && reference.length > 0) {
139+
try {
140+
this.clearReferenceInlineHintsAndImportHints()
141+
if (
142+
this.activeSession?.suggestions &&
143+
this.activeSession.suggestions[this._currentSuggestionIndex] &&
144+
this.activeSession.suggestions.length > 0
145+
) {
146+
const reference = this.activeSession.suggestions[this._currentSuggestionIndex].references
143147
const insertText = this.activeSession.suggestions[this._currentSuggestionIndex].insertText
144-
const insertTextStr =
145-
typeof insertText === 'string' ? insertText : (insertText.value ?? String(insertText))
146-
147-
ReferenceInlineProvider.instance.setInlineReference(
148-
this.activeSession.startPosition.line,
149-
insertTextStr,
150-
reference
151-
)
152-
}
153-
if (vscode.window.activeTextEditor) {
154-
ImportAdderProvider.instance.onShowRecommendation(
155-
vscode.window.activeTextEditor.document,
156-
this.activeSession.startPosition.line,
157-
this.activeSession.suggestions[this._currentSuggestionIndex]
158-
)
148+
if (reference && reference.length > 0) {
149+
const insertTextStr =
150+
typeof insertText === 'string' ? insertText : (insertText.value ?? String(insertText))
151+
152+
ReferenceInlineProvider.instance.setInlineReference(
153+
this.activeSession.startPosition.line,
154+
insertTextStr,
155+
reference
156+
)
157+
}
158+
if (vscode.window.activeTextEditor) {
159+
ImportAdderProvider.instance.onShowRecommendation(
160+
vscode.window.activeTextEditor.document,
161+
this.activeSession.startPosition.line,
162+
this.activeSession.suggestions[this._currentSuggestionIndex]
163+
)
164+
}
159165
}
166+
} catch {
167+
// do nothing as this is not critical path
160168
}
161169
}
162170
}

packages/amazonq/test/unit/amazonq/apps/inline/completion.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ describe('InlineCompletionManager', () => {
256256
getActiveSession: getActiveSessionStub,
257257
getActiveRecommendation: getActiveRecommendationStub,
258258
clear: () => {},
259+
updateCodeReferenceAndImports: () => {},
259260
} as unknown as SessionManager
260261

261262
getActiveSessionStub.returns({

0 commit comments

Comments
 (0)