Skip to content

Commit eb07545

Browse files
committed
remove cancellation token in test/
1 parent d10c2de commit eb07545

File tree

4 files changed

+13
-39
lines changed

4 files changed

+13
-39
lines changed

packages/amazonq/test/unit/codewhisperer/util/crossFileContextUtil.test.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ import { LspController } from 'aws-core-vscode/amazonq'
3030
let tempFolder: string
3131

3232
describe('crossFileContextUtil', function () {
33-
const fakeCancellationToken: vscode.CancellationToken = {
34-
isCancellationRequested: false,
35-
onCancellationRequested: sinon.spy(),
36-
}
37-
3833
let mockEditor: vscode.TextEditor
3934
let clock: FakeTimers.InstalledClock
4035

@@ -68,7 +63,7 @@ describe('crossFileContextUtil', function () {
6863

6964
await assertTabCount(2)
7065

71-
const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor, fakeCancellationToken)
66+
const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor)
7267
assert.ok(actual)
7368
assert.strictEqual(actual.supplementalContextItems.length, 3)
7469
assert.strictEqual(actual.supplementalContextItems[0].content.split('\n').length, 50)
@@ -96,7 +91,7 @@ describe('crossFileContextUtil', function () {
9691
},
9792
])
9893

99-
const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor, fakeCancellationToken)
94+
const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor)
10095
assert.ok(actual)
10196
assert.strictEqual(actual.supplementalContextItems.length, 3)
10297
assert.strictEqual(actual?.strategy, 'codemap')
@@ -149,7 +144,7 @@ describe('crossFileContextUtil', function () {
149144
},
150145
])
151146

152-
const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor, fakeCancellationToken)
147+
const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor)
153148
assert.ok(actual)
154149
assert.strictEqual(actual.supplementalContextItems.length, 5)
155150
assert.strictEqual(actual?.strategy, 'bm25')
@@ -188,14 +183,14 @@ describe('crossFileContextUtil', function () {
188183
describe('non supported language should return undefined', function () {
189184
it('c++', async function () {
190185
mockEditor = createMockTextEditor('content', 'fileName', 'cpp')
191-
const actual = await crossFile.fetchSupplementalContextForSrc(mockEditor, fakeCancellationToken)
186+
const actual = await crossFile.fetchSupplementalContextForSrc(mockEditor)
192187
assert.strictEqual(actual, undefined)
193188
})
194189

195190
it('ruby', async function () {
196191
mockEditor = createMockTextEditor('content', 'fileName', 'ruby')
197192

198-
const actual = await crossFile.fetchSupplementalContextForSrc(mockEditor, fakeCancellationToken)
193+
const actual = await crossFile.fetchSupplementalContextForSrc(mockEditor)
199194

200195
assert.strictEqual(actual, undefined)
201196
})
@@ -286,7 +281,7 @@ describe('crossFileContextUtil', function () {
286281

287282
await assertTabCount(4)
288283

289-
const actual = await crossFile.fetchSupplementalContextForSrc(editor, fakeCancellationToken)
284+
const actual = await crossFile.fetchSupplementalContextForSrc(editor)
290285

291286
assert.ok(actual && actual.supplementalContextItems.length === 0)
292287
})
@@ -317,7 +312,7 @@ describe('crossFileContextUtil', function () {
317312

318313
await assertTabCount(4)
319314

320-
const actual = await crossFile.fetchSupplementalContextForSrc(editor, fakeCancellationToken)
315+
const actual = await crossFile.fetchSupplementalContextForSrc(editor)
321316

322317
assert.ok(actual && actual.supplementalContextItems.length !== 0)
323318
})
@@ -360,7 +355,7 @@ describe('crossFileContextUtil', function () {
360355

361356
await assertTabCount(4)
362357

363-
const actual = await crossFile.fetchSupplementalContextForSrc(editor, fakeCancellationToken)
358+
const actual = await crossFile.fetchSupplementalContextForSrc(editor)
364359

365360
assert.ok(actual && actual.supplementalContextItems.length !== 0)
366361
})

packages/amazonq/test/unit/codewhisperer/util/supplemetalContextUtil.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import assert from 'assert'
77
import * as FakeTimers from '@sinonjs/fake-timers'
8-
import * as vscode from 'vscode'
98
import * as sinon from 'sinon'
109
import * as crossFile from 'aws-core-vscode/codewhisperer'
1110
import { TestFolder, assertTabCount, installFakeClock } from 'aws-core-vscode/test'
@@ -17,11 +16,6 @@ describe('supplementalContextUtil', function () {
1716
let testFolder: TestFolder
1817
let clock: FakeTimers.InstalledClock
1918

20-
const fakeCancellationToken: vscode.CancellationToken = {
21-
isCancellationRequested: false,
22-
onCancellationRequested: sinon.spy(),
23-
}
24-
2519
before(function () {
2620
clock = installFakeClock()
2721
})
@@ -62,7 +56,7 @@ describe('supplementalContextUtil', function () {
6256

6357
await assertTabCount(4)
6458

65-
const actual = await crossFile.fetchSupplementalContext(editor, fakeCancellationToken)
59+
const actual = await crossFile.fetchSupplementalContext(editor)
6660
assert.ok(actual?.supplementalContextItems.length === 4)
6761
})
6862

@@ -78,7 +72,7 @@ describe('supplementalContextUtil', function () {
7872

7973
await assertTabCount(4)
8074

81-
const actual = await crossFile.fetchSupplementalContext(editor, fakeCancellationToken)
75+
const actual = await crossFile.fetchSupplementalContext(editor)
8276
assert.ok(actual?.supplementalContextItems.length === 0)
8377
})
8478
})

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
1111
import { getLogger } from '../../shared/logger/logger'
1212
import { runtimeLanguageContext } from './runtimeLanguageContext'
1313
import { fetchSupplementalContext } from './supplementalContext/supplementalContextUtil'
14-
import { supplementalContextTimeoutInMs } from '../models/constants'
1514
import { getSelectedCustomization } from './customizationUtil'
1615
import { selectFrom } from '../../shared/utilities/tsUtils'
1716
import { checkLeftContextKeywordsForJson } from './commonUtil'
@@ -91,13 +90,7 @@ export async function buildGenerateCompletionRequest(
9190
supplementalMetadata: CodeWhispererSupplementalContext | undefined
9291
}> {
9392
const fileContext = extractContextForCodeWhisperer(editor)
94-
95-
const tokenSource = new vscode.CancellationTokenSource()
96-
setTimeout(() => {
97-
tokenSource.cancel()
98-
}, supplementalContextTimeoutInMs)
99-
100-
const supplementalContexts = await fetchSupplementalContext(editor, tokenSource.token)
93+
const supplementalContexts = await fetchSupplementalContext(editor)
10194

10295
logSupplementalContext(supplementalContexts)
10396

@@ -128,14 +121,7 @@ export async function buildGenerateRecommendationRequest(editor: vscode.TextEdit
128121
supplementalMetadata: CodeWhispererSupplementalContext | undefined
129122
}> {
130123
const fileContext = extractContextForCodeWhisperer(editor)
131-
132-
const tokenSource = new vscode.CancellationTokenSource()
133-
// the supplement context fetch mechanisms each has a timeout of supplementalContextTimeoutInMs
134-
// adding 10 ms for overall timeout as buffer
135-
setTimeout(() => {
136-
tokenSource.cancel()
137-
}, supplementalContextTimeoutInMs + 10)
138-
const supplementalContexts = await fetchSupplementalContext(editor, tokenSource.token)
124+
const supplementalContexts = await fetchSupplementalContext(editor)
139125

140126
logSupplementalContext(supplementalContexts)
141127

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import { getLogger } from '../../../shared/logger/logger'
1313
import { CodeWhispererSupplementalContext } from '../../models/model'
1414

1515
export async function fetchSupplementalContext(
16-
editor: vscode.TextEditor,
17-
cancellationToken: vscode.CancellationToken
16+
editor: vscode.TextEditor
1817
): Promise<CodeWhispererSupplementalContext | undefined> {
1918
const timesBeforeFetching = performance.now()
2019

0 commit comments

Comments
 (0)