Commit e5c6b3f
fix(inline-suggestion): replace vscode.cancellation with waitUntil for timeout (aws#6256)
## Problem
related issue: aws#6079,
aws#6252
caller
```
function main () {
// init vscode cancellation token
const cancellationToken
setTimeout(100, () => {
cancellationToken.cancel()
})
highlevelWrapperFetchSupplementalContext(editor, cancellationToken)
}
```
```
export function highlevelWrapperFetchSupplementalContext(editor, cancellationToken) {
const supplementalContext = waitUntil(100, () => {
// here always timeout and throw TimeoutException
const opentabs = await fetchOpenTabsContext(...)
const projectContext = await fetchProjectContext()
const result = []
if (projectContext not empty) {
// push project context
}
if (opentabs not empty) {}
// push openttabs
})
return result
}
async function fetchOpenTabsContext(editor, cancellationToken) {
....
// VSC api call
}
async function fetchProjectContext() {
....
// LSP call
}
```
After investigation, it looks like mix use of `vscode.CancellationToken`
and `waitUntil()` will likely cause cancellation token to be cancelled
prematurely (might be because another layer of waitUntil will run the
fetchOpenTabsContext asynchronously thus causing it to timeout
prematurely) therefore `fetchOpebtabsContext(..)` will return null in
this case and hence causing test cases failing.
Therefore, the issue here is actually not the test case itself and
they're failing due to race condition
## Solution
remove usage of cancellation token and only use waitUntil for timeout
purpose
## Functional testing
retrieved sup context as expected
### Case 1: repomap is available (there are local imports)
```
2024-12-16 13:10:15.616 [debug] CodeWhispererSupplementalContext:
isUtg: false,
isProcessTimeout: false,
contentsLength: 14436,
latency: 16.67179101705551
strategy: codemap
Chunk 0:
Path: q-inline
Length: 10209
Score: 0
Chunk 1:
Path: /Volumes/workplace/ide/aws-toolkit-vscode-staging/packages/core/src/codewhisperer/service/serviceContainer.ts
Length: 1486
Score: 22.60257328587725
Chunk 2:
Path: /Volumes/workplace/ide/aws-toolkit-vscode-staging/packages/core/src/codewhisperer/tracker/lineTracker.ts
Length: 1649
Score: 19.106700952807103
Chunk 3:
Path: /Volumes/workplace/ide/aws-toolkit-vscode-staging/packages/core/src/codewhisperer/tracker/lineTracker.ts
Length: 1092
Score: 10.334690655691002
```
### Case 2: No repomap, should fallback to opentabs only

```
2024-12-16 13:11:29.738 [debug] CodeWhispererSupplementalContext:
isUtg: false,
isProcessTimeout: false,
contentsLength: 5046,
latency: 16.311500012874603
strategy: opentabs
Chunk 0:
Path: /Volumes/workplace/ide/aws-toolkit-vscode-staging/packages/core/src/codewhisperer/tracker/lineTracker.ts
Length: 1564
Score: 0
Chunk 1:
Path: /Volumes/workplace/ide/aws-toolkit-vscode-staging/packages/core/src/codewhisperer/tracker/lineTracker.ts
Length: 1649
Score: 0
Chunk 2:
Path: /Volumes/workplace/ide/aws-toolkit-vscode-staging/packages/core/src/codewhisperer/tracker/lineTracker.ts
Length: 1833
Score: 0
```
---
- Treat all work as PUBLIC. Private `feature/x` branches will not be
squash-merged at release time.
- Your code changes must meet the guidelines in
[CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines).
License: I confirm that my contribution is made under the terms of the
Apache 2.0 license.1 parent 4692f93 commit e5c6b3f
File tree
4 files changed
+42
-32
lines changed- packages
- amazonq
- .changes/next-release
- test/unit/codewhisperer/util
- core/src/codewhisperer/util/supplementalContext
4 files changed
+42
-32
lines changedLines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
Lines changed: 16 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
312 | 312 | | |
313 | 313 | | |
314 | 314 | | |
315 | | - | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
316 | 318 | | |
317 | 319 | | |
318 | 320 | | |
| |||
328 | 330 | | |
329 | 331 | | |
330 | 332 | | |
331 | | - | |
| 333 | + | |
332 | 334 | | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
333 | 345 | | |
334 | 346 | | |
335 | 347 | | |
| |||
Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
34 | 45 | | |
35 | 46 | | |
36 | 47 | | |
| |||
42 | 53 | | |
43 | 54 | | |
44 | 55 | | |
45 | | - | |
| 56 | + | |
46 | 57 | | |
47 | 58 | | |
48 | 59 | | |
| |||
Lines changed: 10 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 10 | + | |
17 | 11 | | |
18 | 12 | | |
19 | 13 | | |
| |||
77 | 71 | | |
78 | 72 | | |
79 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
80 | 82 | | |
81 | 83 | | |
82 | | - | |
| 84 | + | |
83 | 85 | | |
84 | 86 | | |
85 | 87 | | |
| |||
126 | 128 | | |
127 | 129 | | |
128 | 130 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | 131 | | |
138 | 132 | | |
139 | 133 | | |
| |||
207 | 201 | | |
208 | 202 | | |
209 | 203 | | |
210 | | - | |
211 | 204 | | |
212 | 205 | | |
213 | 206 | | |
214 | 207 | | |
215 | 208 | | |
216 | 209 | | |
217 | | - | |
218 | 210 | | |
219 | 211 | | |
220 | 212 | | |
| |||
230 | 222 | | |
231 | 223 | | |
232 | 224 | | |
233 | | - | |
234 | 225 | | |
235 | 226 | | |
236 | 227 | | |
237 | 228 | | |
238 | 229 | | |
239 | | - | |
240 | | - | |
241 | 230 | | |
242 | 231 | | |
243 | 232 | | |
| |||
390 | 379 | | |
391 | 380 | | |
392 | 381 | | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
0 commit comments