@@ -12,11 +12,17 @@ import {
1212import { CancellationToken , InlineCompletionContext , Position , TextDocument } from 'vscode'
1313import { LanguageClient } from 'vscode-languageclient'
1414import { SessionManager } from './sessionManager'
15- import { AuthUtil , CodeWhispererStatusBarManager , vsCodeState } from 'aws-core-vscode/codewhisperer'
15+ import {
16+ AuthUtil ,
17+ CodeWhispererConstants ,
18+ CodeWhispererStatusBarManager ,
19+ vsCodeState ,
20+ } from 'aws-core-vscode/codewhisperer'
1621import { TelemetryHelper } from './telemetryHelper'
1722import { ICursorUpdateRecorder } from './cursorUpdateManager'
1823import { getLogger } from 'aws-core-vscode/shared'
1924import { getOpenFilesInWindow } from 'aws-core-vscode/utils'
25+ import { asyncCallWithTimeout } from '../../util/timeoutUtil'
2026
2127export interface GetAllRecommendationsOptions {
2228 emitTelemetry ?: boolean
@@ -36,6 +42,23 @@ export class RecommendationService {
3642 this . cursorUpdateRecorder = recorder
3743 }
3844
45+ async getRecommendationsWithTimeout (
46+ languageClient : LanguageClient ,
47+ request : InlineCompletionWithReferencesParams ,
48+ token : CancellationToken
49+ ) {
50+ const resultPromise : Promise < InlineCompletionListWithReferences > = languageClient . sendRequest (
51+ inlineCompletionWithReferencesRequestType . method ,
52+ request ,
53+ token
54+ )
55+ return await asyncCallWithTimeout < InlineCompletionListWithReferences > (
56+ resultPromise ,
57+ `${ inlineCompletionWithReferencesRequestType . method } time out` ,
58+ CodeWhispererConstants . promiseTimeoutLimit * 1000
59+ )
60+ }
61+
3962 async getAllRecommendations (
4063 languageClient : LanguageClient ,
4164 document : TextDocument ,
@@ -95,11 +118,9 @@ export class RecommendationService {
95118 } ,
96119 } )
97120 const t0 = performance . now ( )
98- const result : InlineCompletionListWithReferences = await languageClient . sendRequest (
99- inlineCompletionWithReferencesRequestType . method ,
100- request ,
101- token
102- )
121+
122+ const result = await this . getRecommendationsWithTimeout ( languageClient , request , token )
123+
103124 getLogger ( ) . info ( 'Received inline completion response from LSP: %O' , {
104125 sessionId : result . sessionId ,
105126 latency : performance . now ( ) - t0 ,
@@ -183,11 +204,7 @@ export class RecommendationService {
183204 while ( nextToken ) {
184205 const request = { ...initialRequest , partialResultToken : nextToken }
185206
186- const result : InlineCompletionListWithReferences = await languageClient . sendRequest (
187- inlineCompletionWithReferencesRequestType . method ,
188- request ,
189- token
190- )
207+ const result = await this . getRecommendationsWithTimeout ( languageClient , request , token )
191208 // when pagination is in progress, but user has already accepted or rejected an inline completion
192209 // then stop pagination
193210 if ( this . sessionManager . getActiveSession ( ) === undefined || vsCodeState . isCodeWhispererEditing ) {
0 commit comments