Skip to content

Commit 5ace0af

Browse files
authored
Merge branch 'master' into open_tab
2 parents 9540ebb + 187f27a commit 5ace0af

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

buildspec/linuxTests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ phases:
4848
- VCS_COMMIT_ID="${CODEBUILD_RESOLVED_SOURCE_VERSION}"
4949
- CI_BUILD_URL=$(echo $CODEBUILD_BUILD_URL | sed 's/#/%23/g') # Encode `#` in the URL because otherwise the url is clipped in the Codecov.io site
5050
- CI_BUILD_ID="${CODEBUILD_BUILD_ID}"
51-
- test -n "${CODECOV_TOKEN}" && [ "$TARGET_BRANCH" = "master" ] && ./codecov --token=${CODECOV_TOKEN} --branch=${CODEBUILD_RESOLVED_SOURCE_VERSION} --repository=${CODEBUILD_SOURCE_REPO_URL} --file=./coverage/amazonq/lcov.info --file=./coverage/toolkit/lcov.info
51+
- test -n "${CODECOV_TOKEN}" && [ "$TARGET_BRANCH" = "master" ] && ./codecov --token=${CODECOV_TOKEN} --branch=${CODEBUILD_RESOLVED_SOURCE_VERSION} --repository=${CODEBUILD_SOURCE_REPO_URL} --file=./coverage/amazonq/lcov.info --file=./coverage/toolkit/lcov.info || true
5252

5353
reports:
5454
unit-test:

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

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ import {
1212
import { CancellationToken, InlineCompletionContext, Position, TextDocument } from 'vscode'
1313
import { LanguageClient } from 'vscode-languageclient'
1414
import { 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'
1621
import { TelemetryHelper } from './telemetryHelper'
1722
import { ICursorUpdateRecorder } from './cursorUpdateManager'
1823
import { getLogger } from 'aws-core-vscode/shared'
1924
import { getOpenFilesInWindow } from 'aws-core-vscode/utils'
25+
import { asyncCallWithTimeout } from '../../util/timeoutUtil'
2026

2127
export 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) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
export function asyncCallWithTimeout<T>(asyncPromise: Promise<T>, message: string, timeLimit: number): Promise<T> {
7+
let timeoutHandle: NodeJS.Timeout
8+
const timeoutPromise = new Promise((_resolve, reject) => {
9+
timeoutHandle = setTimeout(() => reject(new Error(message)), timeLimit)
10+
})
11+
return Promise.race([asyncPromise, timeoutPromise]).then((result) => {
12+
clearTimeout(timeoutHandle)
13+
return result as T
14+
})
15+
}

0 commit comments

Comments
 (0)