@@ -204,54 +204,64 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
204204 context : InlineCompletionContext ,
205205 token : CancellationToken
206206 ) : Promise < InlineCompletionItem [ ] | InlineCompletionList > {
207- vsCodeState . isRecommendationsActive = true
208- if ( this . isNewSession ) {
209- const isAutoTrigger = context . triggerKind === InlineCompletionTriggerKind . Automatic
210- if ( isAutoTrigger && ! CodeSuggestionsState . instance . isSuggestionsEnabled ( ) ) {
211- // return early when suggestions are disabled with auto trigger
212- return [ ]
213- }
207+ try {
208+ // exposed only for testing
209+ vsCodeState . isRecommendationsActive = true
210+ if ( this . isNewSession ) {
211+ const isAutoTrigger = context . triggerKind === InlineCompletionTriggerKind . Automatic
212+ if ( isAutoTrigger && ! CodeSuggestionsState . instance . isSuggestionsEnabled ( ) ) {
213+ // return early when suggestions are disabled with auto trigger
214+ return [ ]
215+ }
214216
215- // tell the tutorial that completions has been triggered
216- await this . inlineTutorialAnnotation . triggered ( context . triggerKind )
217+ // tell the tutorial that completions has been triggered
218+ await this . inlineTutorialAnnotation . triggered ( context . triggerKind )
217219
218- // make service requests if it's a new session
219- await this . recommendationService . getAllRecommendations (
220- this . languageClient ,
221- document ,
222- position ,
223- context ,
224- token
225- )
226- }
227- // get active item from session for displaying
228- const items = this . sessionManager . getActiveRecommendation ( )
229- const session = this . sessionManager . getActiveSession ( )
230- if ( ! session || ! items . length ) {
231- return [ ]
232- }
233- const editor = window . activeTextEditor
234- for ( const item of items ) {
235- item . command = {
236- command : 'aws.amazonq.acceptInline' ,
237- title : 'On acceptance' ,
238- arguments : [
239- session . sessionId ,
240- item ,
241- editor ,
242- session . requestStartTime ,
220+ // make service requests if it's a new session
221+ await this . recommendationService . getAllRecommendations (
222+ this . languageClient ,
223+ document ,
224+ position ,
225+ context ,
226+ token
227+ )
228+ }
229+ // get active item from session for displaying
230+ const items = this . sessionManager . getActiveRecommendation ( )
231+ const session = this . sessionManager . getActiveSession ( )
232+ if ( ! session || ! items . length ) {
233+ return [ ]
234+ }
235+ const editor = window . activeTextEditor
236+ for ( const item of items ) {
237+ item . command = {
238+ command : 'aws.amazonq.acceptInline' ,
239+ title : 'On acceptance' ,
240+ arguments : [
241+ session . sessionId ,
242+ item ,
243+ editor ,
244+ session . requestStartTime ,
245+ position . line ,
246+ session . firstCompletionDisplayLatency ,
247+ ] ,
248+ }
249+ ReferenceInlineProvider . instance . setInlineReference (
243250 position . line ,
244- session . firstCompletionDisplayLatency ,
245- ] ,
251+ item . insertText as string ,
252+ item . references
253+ )
254+ ImportAdderProvider . instance . onShowRecommendation ( document , position . line , item )
246255 }
247- ReferenceInlineProvider . instance . setInlineReference (
248- position . line ,
249- item . insertText as string ,
250- item . references
251- )
252- ImportAdderProvider . instance . onShowRecommendation ( document , position . line , item )
256+ // exposed only for testing
257+ vsCodeState . isRecommendationsActive = false
258+
259+ return items as InlineCompletionItem [ ]
260+ } catch {
261+ return [ ]
262+ } finally {
263+ // exposed only for testing
264+ vsCodeState . isRecommendationsActive = false
253265 }
254- vsCodeState . isRecommendationsActive = false
255- return items as InlineCompletionItem [ ]
256266 }
257267}
0 commit comments