Skip to content

Commit 417fa4d

Browse files
Merge master into feature/emr
2 parents dc9ac68 + f781fc9 commit 417fa4d

23 files changed

+120
-288
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Removal",
3+
"description": "Reverted prefetch logic to enable more stable inline completion"
4+
}

packages/amazonq/test/unit/codewhisperer/commands/onAcceptance.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,19 @@ import * as sinon from 'sinon'
99
import {
1010
onAcceptance,
1111
AcceptedSuggestionEntry,
12-
CodeWhispererSessionState,
12+
session,
1313
CodeWhispererTracker,
1414
RecommendationHandler,
1515
AuthUtil,
16-
CodeWhispererSession,
1716
} from 'aws-core-vscode/codewhisperer'
1817
import { resetCodeWhispererGlobalVariables, createMockTextEditor } from 'aws-core-vscode/test'
1918
import { assertTelemetryCurried } from 'aws-core-vscode/test'
2019

2120
describe('onAcceptance', function () {
22-
let session: CodeWhispererSession
2321
describe('onAcceptance', function () {
2422
beforeEach(async function () {
25-
session = CodeWhispererSessionState.instance.getSession()
2623
await resetCodeWhispererGlobalVariables()
24+
session.reset()
2725
})
2826

2927
afterEach(function () {

packages/amazonq/test/unit/codewhisperer/commands/onInlineAcceptance.test.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,15 @@ import * as vscode from 'vscode'
88
import * as sinon from 'sinon'
99
import { resetCodeWhispererGlobalVariables, createMockTextEditor } from 'aws-core-vscode/test'
1010
import { assertTelemetryCurried } from 'aws-core-vscode/test'
11-
import {
12-
onInlineAcceptance,
13-
RecommendationHandler,
14-
AuthUtil,
15-
CodeWhispererSessionState,
16-
CodeWhispererSession,
17-
} from 'aws-core-vscode/codewhisperer'
11+
import { onInlineAcceptance, RecommendationHandler, AuthUtil, session } from 'aws-core-vscode/codewhisperer'
1812
import { globals } from 'aws-core-vscode/shared'
1913
import { extensionVersion } from 'aws-core-vscode/shared'
2014

2115
describe('onInlineAcceptance', function () {
22-
let session: CodeWhispererSession
2316
describe('onInlineAcceptance', function () {
2417
beforeEach(async function () {
25-
session = CodeWhispererSessionState.instance.getSession()
2618
await resetCodeWhispererGlobalVariables()
19+
session.reset()
2720
})
2821

2922
afterEach(function () {

packages/amazonq/test/unit/codewhisperer/service/completionProvider.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
getLabel,
1313
Recommendation,
1414
RecommendationHandler,
15-
CodeWhispererSessionState,
15+
session,
1616
} from 'aws-core-vscode/codewhisperer'
1717
import { createMockDocument, resetCodeWhispererGlobalVariables } from 'aws-core-vscode/test'
1818

@@ -39,7 +39,6 @@ describe('completionProviderService', function () {
3939

4040
describe('getCompletionItem', function () {
4141
it('should return targetCompletionItem given input', function () {
42-
const session = CodeWhispererSessionState.instance.getSession()
4342
session.startPos = new vscode.Position(0, 0)
4443
RecommendationHandler.instance.requestId = 'mock_requestId_getCompletionItem'
4544
session.sessionId = 'mock_sessionId_getCompletionItem'
@@ -96,7 +95,6 @@ describe('completionProviderService', function () {
9695

9796
describe('getCompletionItems', function () {
9897
it('should return completion items for each non-empty recommendation', async function () {
99-
const session = CodeWhispererSessionState.instance.getSession()
10098
session.recommendations = [
10199
{ content: "\n\t\tconsole.log('Hello world!');\n\t}" },
102100
{ content: '\nvar a = 10' },
@@ -108,7 +106,6 @@ describe('completionProviderService', function () {
108106
})
109107

110108
it('should return empty completion items when recommendation is empty', async function () {
111-
const session = CodeWhispererSessionState.instance.getSession()
112109
session.recommendations = []
113110
const mockPosition = new vscode.Position(14, 83)
114111
const mockDocument = createMockDocument()

packages/amazonq/test/unit/codewhisperer/service/inlineCompletionService.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
CodeSuggestionsState,
1515
ConfigurationEntry,
1616
CWInlineCompletionItemProvider,
17-
CodeWhispererSessionState,
17+
session,
1818
AuthUtil,
1919
listCodeWhispererCommandsId,
2020
DefaultCodeWhispererClient,
@@ -46,7 +46,6 @@ describe('inlineCompletionService', function () {
4646
})
4747

4848
it('should call checkAndResetCancellationTokens before showing inline and next token to be null', async function () {
49-
const session = CodeWhispererSessionState.instance.getSession()
5049
const mockEditor = createMockTextEditor()
5150
sinon.stub(RecommendationHandler.instance, 'getRecommendations').resolves({
5251
result: 'Succeeded',
@@ -71,7 +70,6 @@ describe('inlineCompletionService', function () {
7170

7271
describe('clearInlineCompletionStates', function () {
7372
it('should remove inline reference and recommendations', async function () {
74-
const session = CodeWhispererSessionState.instance.getSession()
7573
const fakeReferences = [
7674
{
7775
message: '',

packages/amazonq/test/unit/codewhisperer/service/recommendationHandler.test.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as vscode from 'vscode'
88
import * as sinon from 'sinon'
99
import {
1010
ReferenceInlineProvider,
11-
CodeWhispererSessionState,
11+
session,
1212
AuthUtil,
1313
DefaultCodeWhispererClient,
1414
RecommendationsList,
@@ -55,7 +55,6 @@ describe('recommendationHandler', function () {
5555
})
5656

5757
it('should assign correct recommendations given input', async function () {
58-
const session = CodeWhispererSessionState.instance.getSession()
5958
assert.strictEqual(CodeWhispererCodeCoverageTracker.instances.size, 0)
6059
assert.strictEqual(
6160
CodeWhispererCodeCoverageTracker.getTracker(mockEditor.document.languageId)?.serviceInvocationCount,
@@ -75,7 +74,7 @@ describe('recommendationHandler', function () {
7574
}
7675
const handler = new RecommendationHandler()
7776
sinon.stub(handler, 'getServerResponse').resolves(mockServerResult)
78-
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, session, 'Enter', false)
77+
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, 'Enter', false)
7978
const actual = session.recommendations
8079
const expected: RecommendationsList = [{ content: "print('Hello World!')" }, { content: '' }]
8180
assert.deepStrictEqual(actual, expected)
@@ -86,7 +85,6 @@ describe('recommendationHandler', function () {
8685
})
8786

8887
it('should assign request id correctly', async function () {
89-
const session = CodeWhispererSessionState.instance.getSession()
9088
const mockServerResult = {
9189
recommendations: [{ content: "print('Hello World!')" }, { content: '' }],
9290
$response: {
@@ -101,7 +99,7 @@ describe('recommendationHandler', function () {
10199
const handler = new RecommendationHandler()
102100
sinon.stub(handler, 'getServerResponse').resolves(mockServerResult)
103101
sinon.stub(handler, 'isCancellationRequested').returns(false)
104-
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, session, 'Enter', false)
102+
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, 'Enter', false)
105103
assert.strictEqual(handler.requestId, 'test_request')
106104
assert.strictEqual(session.sessionId, 'test_request')
107105
assert.strictEqual(session.triggerType, 'AutoTrigger')
@@ -130,10 +128,9 @@ describe('recommendationHandler', function () {
130128
strategy: 'empty',
131129
})
132130
sinon.stub(performance, 'now').returns(0.0)
133-
const session = CodeWhispererSessionState.instance.getSession()
134131
session.startPos = new vscode.Position(1, 0)
135132
session.startCursorOffset = 2
136-
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, session, 'Enter')
133+
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, 'Enter')
137134
const assertTelemetry = assertTelemetryCurried('codewhisperer_serviceInvocation')
138135
assertTelemetry({
139136
codewhispererRequestId: 'test_request',
@@ -170,11 +167,10 @@ describe('recommendationHandler', function () {
170167
const handler = new RecommendationHandler()
171168
sinon.stub(handler, 'getServerResponse').resolves(mockServerResult)
172169
sinon.stub(performance, 'now').returns(0.0)
173-
const session = CodeWhispererSessionState.instance.getSession()
174170
session.startPos = new vscode.Position(1, 0)
175171
session.requestIdList = ['test_request_empty']
176172
session.startCursorOffset = 2
177-
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, session, 'Enter')
173+
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, 'Enter')
178174
const assertTelemetry = assertTelemetryCurried('codewhisperer_userDecision')
179175
assertTelemetry({
180176
codewhispererRequestId: 'test_request_empty',
@@ -196,7 +192,6 @@ describe('recommendationHandler', function () {
196192
sinon.restore()
197193
})
198194
it('should return true if any response is not empty', function () {
199-
const session = CodeWhispererSessionState.instance.getSession()
200195
const handler = new RecommendationHandler()
201196
session.recommendations = [
202197
{
@@ -209,14 +204,12 @@ describe('recommendationHandler', function () {
209204
})
210205

211206
it('should return false if response is empty', function () {
212-
const session = CodeWhispererSessionState.instance.getSession()
213207
const handler = new RecommendationHandler()
214208
session.recommendations = []
215209
assert.ok(!handler.isValidResponse())
216210
})
217211

218212
it('should return false if all response has no string length', function () {
219-
const session = CodeWhispererSessionState.instance.getSession()
220213
const handler = new RecommendationHandler()
221214
session.recommendations = [{ content: '' }, { content: '' }]
222215
assert.ok(!handler.isValidResponse())
@@ -229,7 +222,6 @@ describe('recommendationHandler', function () {
229222
})
230223

231224
it('should set the completion type to block given a multi-line suggestion', function () {
232-
const session = CodeWhispererSessionState.instance.getSession()
233225
session.setCompletionType(0, { content: 'test\n\n \t\r\nanother test' })
234226
assert.strictEqual(session.getCompletionType(0), 'Block')
235227

@@ -241,7 +233,6 @@ describe('recommendationHandler', function () {
241233
})
242234

243235
it('should set the completion type to line given a single-line suggestion', function () {
244-
const session = CodeWhispererSessionState.instance.getSession()
245236
session.setCompletionType(0, { content: 'test' })
246237
assert.strictEqual(session.getCompletionType(0), 'Line')
247238

@@ -250,7 +241,6 @@ describe('recommendationHandler', function () {
250241
})
251242

252243
it('should set the completion type to line given a multi-line completion but only one-lien of non-blank sequence', function () {
253-
const session = CodeWhispererSessionState.instance.getSession()
254244
session.setCompletionType(0, { content: 'test\n\t' })
255245
assert.strictEqual(session.getCompletionType(0), 'Line')
256246

@@ -267,7 +257,6 @@ describe('recommendationHandler', function () {
267257

268258
describe('on event change', async function () {
269259
beforeEach(function () {
270-
const session = CodeWhispererSessionState.instance.getSession()
271260
const fakeReferences = [
272261
{
273262
message: '',
@@ -285,14 +274,12 @@ describe('recommendationHandler', function () {
285274
})
286275

287276
it('should remove inline reference onEditorChange', async function () {
288-
const session = CodeWhispererSessionState.instance.getSession()
289277
session.sessionId = 'aSessionId'
290278
RecommendationHandler.instance.requestId = 'aRequestId'
291279
await RecommendationHandler.instance.onEditorChange()
292280
assert.strictEqual(ReferenceInlineProvider.instance.refs.length, 0)
293281
})
294282
it('should remove inline reference onFocusChange', async function () {
295-
const session = CodeWhispererSessionState.instance.getSession()
296283
session.sessionId = 'aSessionId'
297284
RecommendationHandler.instance.requestId = 'aRequestId'
298285
await RecommendationHandler.instance.onFocusChange()

packages/amazonq/test/unit/codewhisperer/service/telemetry.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
invokeRecommendation,
2323
ConfigurationEntry,
2424
RecommendationHandler,
25-
CodeWhispererSessionState,
25+
session,
2626
vsCodeCursorUpdateDelay,
2727
AuthUtil,
2828
} from 'aws-core-vscode/codewhisperer'
@@ -36,7 +36,6 @@ type CodeWhispererResponse = ListRecommendationsResponse & {
3636
let tempFolder: string
3737

3838
describe.skip('CodeWhisperer telemetry', async function () {
39-
const session = CodeWhispererSessionState.instance.getSession()
4039
let sandbox: sinon.SinonSandbox
4140
let client: DefaultCodeWhispererClient
4241

@@ -520,7 +519,6 @@ async function manualTrigger(
520519

521520
// Note: RecommendationHandler.isSuggestionVisible seems not to work well, hence not using it
522521
async function waitUntilSuggestionSeen(index: number = 0) {
523-
const session = CodeWhispererSessionState.instance.getSession()
524522
const state = await waitUntil(
525523
async () => {
526524
const r = session.getSuggestionState(index)

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import assert from 'assert'
77
import { assertTelemetryCurried, resetCodeWhispererGlobalVariables } from 'aws-core-vscode/test'
8-
import { TelemetryHelper, Completion, CodeWhispererSessionState } from 'aws-core-vscode/codewhisperer'
8+
import { TelemetryHelper, Completion, session } from 'aws-core-vscode/codewhisperer'
99
import {
1010
CodewhispererCompletionType,
1111
CodewhispererSuggestionState,
@@ -39,7 +39,6 @@ function aCompletion(): Completion {
3939
}
4040

4141
describe('telemetryHelper', function () {
42-
const session = CodeWhispererSessionState.instance.getSession()
4342
describe('clientComponentLatency', function () {
4443
let sut: TelemetryHelper
4544

@@ -49,7 +48,6 @@ describe('telemetryHelper', function () {
4948

5049
afterEach(function () {
5150
sinon.restore()
52-
session.reset()
5351
})
5452

5553
it('resetClientComponentLatencyTime should reset state variables', function () {

packages/core/src/codewhisperer/client/codewhisperer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { isSsoConnection } from '../../auth/connection'
1717
import { pageableToCollection } from '../../shared/utilities/collectionUtils'
1818
import apiConfig = require('./service-2.json')
1919
import userApiConfig = require('./user-service-2.json')
20-
import { CodeWhispererSessionState } from '../util/codeWhispererSession'
20+
import { session } from '../util/codeWhispererSession'
2121
import { getLogger } from '../../shared/logger/logger'
2222
import { indent } from '../../shared/utilities/textUtilities'
2323
import { keepAliveHeader } from './agent'
@@ -133,7 +133,6 @@ export class DefaultCodeWhispererClient {
133133
}
134134

135135
async createUserSdkClient(maxRetries?: number): Promise<CodeWhispererUserClient> {
136-
const session = CodeWhispererSessionState.instance.getSession()
137136
const isOptedOut = CodeWhispererSettings.instance.isOptoutEnabled()
138137
session.setFetchCredentialStart()
139138
const bearerToken = await AuthUtil.instance.getBearerToken()

packages/core/src/codewhisperer/commands/invokeRecommendation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { vsCodeState, ConfigurationEntry } from '../models/model'
88
import { resetIntelliSenseState } from '../util/globalStateUtil'
99
import { DefaultCodeWhispererClient } from '../client/codewhisperer'
1010
import { RecommendationHandler } from '../service/recommendationHandler'
11-
import { CodeWhispererSessionState } from '../util/codeWhispererSession'
11+
import { session } from '../util/codeWhispererSession'
1212
import { RecommendationService } from '../service/recommendationService'
1313

1414
/**
@@ -33,7 +33,6 @@ export async function invokeRecommendation(
3333
/**
3434
* When using intelliSense, if invocation position changed, reject previous active recommendations
3535
*/
36-
const session = CodeWhispererSessionState.instance.getSession()
3736
if (vsCodeState.isIntelliSenseActive && editor.selection.active !== session.startPos) {
3837
resetIntelliSenseState(
3938
config.isManualTriggerEnabled,

0 commit comments

Comments
 (0)