Skip to content

Commit

Permalink
remove cancellation token in test/
Browse files Browse the repository at this point in the history
  • Loading branch information
Will-ShaoHua committed Feb 1, 2025
1 parent d10c2de commit eb07545
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ import { LspController } from 'aws-core-vscode/amazonq'
let tempFolder: string

describe('crossFileContextUtil', function () {
const fakeCancellationToken: vscode.CancellationToken = {
isCancellationRequested: false,
onCancellationRequested: sinon.spy(),
}

let mockEditor: vscode.TextEditor
let clock: FakeTimers.InstalledClock

Expand Down Expand Up @@ -68,7 +63,7 @@ describe('crossFileContextUtil', function () {

await assertTabCount(2)

const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor, fakeCancellationToken)
const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor)
assert.ok(actual)
assert.strictEqual(actual.supplementalContextItems.length, 3)
assert.strictEqual(actual.supplementalContextItems[0].content.split('\n').length, 50)
Expand Down Expand Up @@ -96,7 +91,7 @@ describe('crossFileContextUtil', function () {
},
])

const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor, fakeCancellationToken)
const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor)
assert.ok(actual)
assert.strictEqual(actual.supplementalContextItems.length, 3)
assert.strictEqual(actual?.strategy, 'codemap')
Expand Down Expand Up @@ -149,7 +144,7 @@ describe('crossFileContextUtil', function () {
},
])

const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor, fakeCancellationToken)
const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor)
assert.ok(actual)
assert.strictEqual(actual.supplementalContextItems.length, 5)
assert.strictEqual(actual?.strategy, 'bm25')
Expand Down Expand Up @@ -188,14 +183,14 @@ describe('crossFileContextUtil', function () {
describe('non supported language should return undefined', function () {
it('c++', async function () {
mockEditor = createMockTextEditor('content', 'fileName', 'cpp')
const actual = await crossFile.fetchSupplementalContextForSrc(mockEditor, fakeCancellationToken)
const actual = await crossFile.fetchSupplementalContextForSrc(mockEditor)
assert.strictEqual(actual, undefined)
})

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

const actual = await crossFile.fetchSupplementalContextForSrc(mockEditor, fakeCancellationToken)
const actual = await crossFile.fetchSupplementalContextForSrc(mockEditor)

assert.strictEqual(actual, undefined)
})
Expand Down Expand Up @@ -286,7 +281,7 @@ describe('crossFileContextUtil', function () {

await assertTabCount(4)

const actual = await crossFile.fetchSupplementalContextForSrc(editor, fakeCancellationToken)
const actual = await crossFile.fetchSupplementalContextForSrc(editor)

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

await assertTabCount(4)

const actual = await crossFile.fetchSupplementalContextForSrc(editor, fakeCancellationToken)
const actual = await crossFile.fetchSupplementalContextForSrc(editor)

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

await assertTabCount(4)

const actual = await crossFile.fetchSupplementalContextForSrc(editor, fakeCancellationToken)
const actual = await crossFile.fetchSupplementalContextForSrc(editor)

assert.ok(actual && actual.supplementalContextItems.length !== 0)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import assert from 'assert'
import * as FakeTimers from '@sinonjs/fake-timers'
import * as vscode from 'vscode'
import * as sinon from 'sinon'
import * as crossFile from 'aws-core-vscode/codewhisperer'
import { TestFolder, assertTabCount, installFakeClock } from 'aws-core-vscode/test'
Expand All @@ -17,11 +16,6 @@ describe('supplementalContextUtil', function () {
let testFolder: TestFolder
let clock: FakeTimers.InstalledClock

const fakeCancellationToken: vscode.CancellationToken = {
isCancellationRequested: false,
onCancellationRequested: sinon.spy(),
}

before(function () {
clock = installFakeClock()
})
Expand Down Expand Up @@ -62,7 +56,7 @@ describe('supplementalContextUtil', function () {

await assertTabCount(4)

const actual = await crossFile.fetchSupplementalContext(editor, fakeCancellationToken)
const actual = await crossFile.fetchSupplementalContext(editor)
assert.ok(actual?.supplementalContextItems.length === 4)
})

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

await assertTabCount(4)

const actual = await crossFile.fetchSupplementalContext(editor, fakeCancellationToken)
const actual = await crossFile.fetchSupplementalContext(editor)
assert.ok(actual?.supplementalContextItems.length === 0)
})
})
Expand Down
18 changes: 2 additions & 16 deletions packages/core/src/codewhisperer/util/editorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
import { getLogger } from '../../shared/logger/logger'
import { runtimeLanguageContext } from './runtimeLanguageContext'
import { fetchSupplementalContext } from './supplementalContext/supplementalContextUtil'
import { supplementalContextTimeoutInMs } from '../models/constants'
import { getSelectedCustomization } from './customizationUtil'
import { selectFrom } from '../../shared/utilities/tsUtils'
import { checkLeftContextKeywordsForJson } from './commonUtil'
Expand Down Expand Up @@ -91,13 +90,7 @@ export async function buildGenerateCompletionRequest(
supplementalMetadata: CodeWhispererSupplementalContext | undefined
}> {
const fileContext = extractContextForCodeWhisperer(editor)

const tokenSource = new vscode.CancellationTokenSource()
setTimeout(() => {
tokenSource.cancel()
}, supplementalContextTimeoutInMs)

const supplementalContexts = await fetchSupplementalContext(editor, tokenSource.token)
const supplementalContexts = await fetchSupplementalContext(editor)

logSupplementalContext(supplementalContexts)

Expand Down Expand Up @@ -128,14 +121,7 @@ export async function buildGenerateRecommendationRequest(editor: vscode.TextEdit
supplementalMetadata: CodeWhispererSupplementalContext | undefined
}> {
const fileContext = extractContextForCodeWhisperer(editor)

const tokenSource = new vscode.CancellationTokenSource()
// the supplement context fetch mechanisms each has a timeout of supplementalContextTimeoutInMs
// adding 10 ms for overall timeout as buffer
setTimeout(() => {
tokenSource.cancel()
}, supplementalContextTimeoutInMs + 10)
const supplementalContexts = await fetchSupplementalContext(editor, tokenSource.token)
const supplementalContexts = await fetchSupplementalContext(editor)

logSupplementalContext(supplementalContexts)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import { getLogger } from '../../../shared/logger/logger'
import { CodeWhispererSupplementalContext } from '../../models/model'

export async function fetchSupplementalContext(
editor: vscode.TextEditor,
cancellationToken: vscode.CancellationToken
editor: vscode.TextEditor
): Promise<CodeWhispererSupplementalContext | undefined> {
const timesBeforeFetching = performance.now()

Expand Down

0 comments on commit eb07545

Please sign in to comment.