Skip to content

Commit d05316a

Browse files
committed
fix comments
1 parent e8c1e89 commit d05316a

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

packages/core/src/amazonq/lsp/lspClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ export class LspClient {
109109
query: query,
110110
filePath: path,
111111
})
112-
const encrpted = await this.encrypt(request)
113-
const resp: any = await this.client?.sendRequest(QueryInlineProjectContextRequestType, encrpted)
112+
const encrypted = await this.encrypt(request)
113+
const resp: any = await this.client?.sendRequest(QueryInlineProjectContextRequestType, encrypted)
114114
return resp
115115
} catch (e) {
116116
getLogger().error(`LspClient: queryInlineProjectContext error: ${e}`)

packages/core/src/amazonq/lsp/lspController.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export interface Manifest {
6666
}
6767
const manifestUrl = 'https://aws-toolkit-language-servers.amazonaws.com/q-context/manifest.json'
6868
// this LSP client in Q extension is only going to work with these LSP server versions
69-
const supportedLspServerVersions = ['0.1.20', '0.1.19']
69+
const supportedLspServerVersions = ['0.1.22', '0.1.19']
7070

7171
const nodeBinName = process.platform === 'win32' ? 'node.exe' : 'node'
7272

@@ -364,14 +364,15 @@ export class LspController {
364364
// reason: `Unknown`,
365365
// })
366366
}
367-
} catch (e) {
367+
} catch (error) {
368+
//TODO: use telemetry.run()q
368369
getLogger().error(`LspController: Failed to build index of project`)
369370
telemetry.amazonq_indexWorkspace.emit({
370371
duration: performance.now() - start,
371372
result: 'Failed',
372373
amazonqIndexFileCount: 0,
373374
amazonqIndexFileSizeInMB: 0,
374-
reason: `${e}`,
375+
reason: `Error when building index. ${error instanceof Error ? error.message : error}`,
375376
})
376377
} finally {
377378
this._isIndexingInProgress = false

packages/core/src/codewhisperer/util/commonUtil.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@ export function asyncCallWithTimeout<T>(asyncPromise: Promise<T>, message: strin
3030
})
3131
}
3232

33-
export function asyncCallWithTimeoutSwallowErrors<T>(asyncPromise: Promise<T>, timeLimit: number): Promise<T> {
34-
let timeoutHandle: NodeJS.Timeout
35-
const timeoutPromise = new Promise((resolve) => {
36-
timeoutHandle = setTimeout(() => resolve(undefined), timeLimit)
37-
})
38-
return Promise.race([asyncPromise, timeoutPromise]).then((result) => {
39-
clearTimeout(timeoutHandle)
40-
return result as T
41-
})
42-
}
43-
4433
export function isInlineCompletionEnabled() {
4534
return getInlineSuggestEnabled() && !isCloud9()
4635
}

packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ import {
1313
supplementalContextTimeoutInMs,
1414
supplemetalContextFetchingTimeoutMsg,
1515
} from '../../models/constants'
16-
import { CancellationError } from '../../../shared/utilities/timeoutUtils'
16+
import { tryTimeout, CancellationError } from '../../../shared/utilities/timeoutUtils'
1717
import { isTestFile } from './codeParsingUtil'
1818
import { getFileDistance } from '../../../shared/filesystemUtilities'
1919
import { getOpenFilesInWindow } from '../../../shared/utilities/editorUtilities'
2020
import { getLogger } from '../../../shared/logger/logger'
2121
import { CodeWhispererSupplementalContext, CodeWhispererSupplementalContextItem } from '../../models/model'
2222
import { LspController } from '../../../amazonq/lsp/lspController'
23-
import { asyncCallWithTimeoutSwallowErrors } from '../commonUtil'
2423

2524
type CrossFileSupportedLanguage =
2625
| 'java'
@@ -67,14 +66,11 @@ export async function fetchSupplementalContextForSrc(
6766
if (supplementalContextConfig === 'v1') {
6867
return fetchSupplementalContextForSrcV1(editor, cancellationToken)
6968
}
70-
const promiseV1 = asyncCallWithTimeoutSwallowErrors(
69+
const promiseV1 = tryTimeout(
7170
fetchSupplementalContextForSrcV1(editor, cancellationToken),
7271
supplementalContextTimeoutInMs
7372
)
74-
const promiseV2 = asyncCallWithTimeoutSwallowErrors(
75-
fetchSupplementalContextForSrcV2(editor),
76-
supplementalContextTimeoutInMs
77-
)
73+
const promiseV2 = tryTimeout(fetchSupplementalContextForSrcV2(editor), supplementalContextTimeoutInMs)
7874
const [resultV1, resultV2] = await Promise.all([promiseV1, promiseV2])
7975
return resultV2 ?? resultV1
8076
}

packages/core/src/shared/utilities/timeoutUtils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,21 @@ export class TimeLag {
387387
globals.clock.clearInterval(this.intervalRef)
388388
}
389389
}
390+
/**
391+
* Tries to execute an asynchronous Promise with a specified time limit.
392+
* If the Promise is not resolved within the time limit, it returns `undefined`.
393+
*
394+
* @param {Promise<T>} asyncPromise - The asynchronous Promise to execute.
395+
* @param {number} timeLimit - The time limit in milliseconds.
396+
* @returns {Promise<T | undefined>} A Promise that resolves with the result of the original Promise if it completes within the time limit, or `undefined` if the time limit is exceeded.
397+
*/
398+
export function tryTimeout<T>(asyncPromise: Promise<T>, timeLimit: number): Promise<T> {
399+
let timeoutHandle: NodeJS.Timeout
400+
const timeoutPromise = new Promise((resolve) => {
401+
timeoutHandle = setTimeout(() => resolve(undefined), timeLimit)
402+
})
403+
return Promise.race([asyncPromise, timeoutPromise]).then((result) => {
404+
clearTimeout(timeoutHandle)
405+
return result as T
406+
})
407+
}

0 commit comments

Comments
 (0)