Skip to content

Commit 5254a56

Browse files
committed
cleanup
1 parent 7fc546d commit 5254a56

File tree

6 files changed

+21
-43
lines changed

6 files changed

+21
-43
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export async function onInlineAcceptance(acceptanceEntry: OnRecommendationAccept
143143
}
144144

145145
RecommendationHandler.instance.reportUserDecisions(acceptanceEntry.acceptIndex)
146-
if (acceptanceEntry.acceptIndex == 0) {
146+
if (acceptanceEntry.acceptIndex === 0) {
147147
const nextSession = CodeWhispererSessionState.instance.getNextSession()
148148
nextSession.startPos = acceptanceEntry.editor.selection.active
149149
CodeWhispererSessionState.instance.setSession(nextSession)

packages/core/src/codewhisperer/service/inlineCompletionItemProvider.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,18 @@ export class CWInlineCompletionItemProvider implements vscode.InlineCompletionIt
153153
// valid one. Otherwise, inline completion which utilizes this position will function
154154
// improperly.
155155
const start = document.validatePosition(this.startPos)
156-
console.log('start pos', start)
157156
const end = position
158157
const iteratingIndexes = this.getIteratingIndexes()
159158
const prefix = document.getText(new vscode.Range(start, end)).replace(/\r\n/g, '\n')
160159
const matchedCount = this.session.recommendations.filter(
161-
(r: any) => r.content.length > 0 && r.content.startsWith(prefix) && r.content !== prefix
160+
(r) => r.content.length > 0 && r.content.startsWith(prefix) && r.content !== prefix
162161
).length
163162
for (const i of iteratingIndexes) {
164163
const r = this.recommendations[i]
165-
console.log('in show', r)
166164
const item = this.getInlineCompletionItem(document, r, start, end, i, prefix)
167165
if (item === undefined) {
168166
continue
169167
}
170-
console.log('item', item)
171168
this.activeItemIndex = i
172169
this.session.setSuggestionState(i, 'Showed')
173170
ReferenceInlineProvider.instance.setInlineReference(this.startPos.line, r.content, r.references)

packages/core/src/codewhisperer/service/recommendationHandler.ts

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
DefaultCodeWhispererClient,
1111
CognitoCredentialsError,
1212
ListRecommendationsRequest,
13-
GenerateRecommendationsRequest,
1413
} from '../client/codewhisperer'
1514
import * as EditorContext from '../util/editorContext'
1615
import * as CodeWhispererConstants from '../models/constants'
@@ -93,8 +92,6 @@ export class RecommendationHandler {
9392
private prev: vscode.Disposable
9493
private _timer?: NodeJS.Timer
9594
documentUri: vscode.Uri | undefined = undefined
96-
// private session: CodeWhispererSession
97-
// private nextSession: CodeWhispererSession
9895

9996
constructor() {
10097
this.requestId = ''
@@ -104,8 +101,6 @@ export class RecommendationHandler {
104101
this.prev = new vscode.Disposable(() => {})
105102
this.next = new vscode.Disposable(() => {})
106103
this.reject = new vscode.Disposable(() => {})
107-
// this.session = CodeWhispererSessionState.instance.getSession()
108-
// this.nextSession = CodeWhispererSessionState.instance.getNextSession()
109104
}
110105

111106
static #instance: RecommendationHandler
@@ -178,7 +173,7 @@ export class RecommendationHandler {
178173
let errorCode: string | undefined = undefined
179174
let currentSession = CodeWhispererSessionState.instance.getSession()
180175
if (isNextSession) {
181-
getLogger().info('pre-fetching next recommendation for model routing')
176+
getLogger().debug('pre-fetching next recommendation for model routing')
182177
currentSession = new CodeWhispererSession()
183178
CodeWhispererSessionState.instance.setNextSession(currentSession)
184179
}
@@ -205,7 +200,6 @@ export class RecommendationHandler {
205200
currentSession.taskType = await this.getTaskTypeFromEditorFileName(editor.document.fileName)
206201

207202
if (pagination && !generate) {
208-
// else {
209203
if (page === 0) {
210204
if (isNextSession) {
211205
const session = CodeWhispererSessionState.instance.getSession()
@@ -234,7 +228,7 @@ export class RecommendationHandler {
234228
...currentSession.requestContext.request,
235229
// Putting nextToken assignment in the end so it overwrites the existing nextToken
236230
nextToken: this.nextToken,
237-
} as ListRecommendationsRequest,
231+
},
238232
supplementalMetadata: currentSession.requestContext.supplementalMetadata,
239233
}
240234
}
@@ -244,10 +238,7 @@ export class RecommendationHandler {
244238
editor as vscode.TextEditor
245239
)
246240
}
247-
const request = generate
248-
? (currentSession.requestContext.request as GenerateRecommendationsRequest)
249-
: (currentSession.requestContext.request as ListRecommendationsRequest)
250-
getLogger().info(`request to inline recommendation : \n${JSON.stringify(request)}`)
241+
const request = currentSession.requestContext.request
251242
TelemetryHelper.instance.setPreprocessEndTime()
252243

253244
// set start pos for non pagination call or first pagination call
@@ -295,7 +286,6 @@ export class RecommendationHandler {
295286
requestId = resp?.$response && resp?.$response?.requestId
296287
nextToken = resp?.nextToken ? resp?.nextToken : ''
297288
sessionId = resp?.$response?.httpResponse?.headers['x-amzn-sessionid']
298-
getLogger().info(`response from inline recommendation : \n${JSON.stringify(resp)}`)
299289
TelemetryHelper.instance.setFirstResponseRequestId(requestId)
300290
if (page === 0) {
301291
currentSession.setTimeToFirstRecommendation(performance.now())
@@ -422,15 +412,19 @@ export class RecommendationHandler {
422412
}
423413
currentSession.setCompletionType(recommendationIndex, r)
424414
}
425-
currentSession.recommendations = pagination ? currentSession.recommendations.concat(recommendations) : recommendations
415+
currentSession.recommendations = pagination
416+
? currentSession.recommendations.concat(recommendations)
417+
: recommendations
426418
if (isInlineCompletionEnabled() && this.hasAtLeastOneValidSuggestion(typedPrefix, currentSession)) {
427419
this._onDidReceiveRecommendation.fire()
428420
}
429421
}
430422

431423
this.requestId = requestId
432424
currentSession.sessionId = sessionId
433-
this.nextToken = nextToken
425+
if (!isNextSession) {
426+
this.nextToken = nextToken
427+
}
434428

435429
// send Empty userDecision event if user receives no recommendations in this session at all.
436430
if (invocationResult === 'Succeeded' && nextToken === '') {
@@ -490,22 +484,12 @@ export class RecommendationHandler {
490484
const session = CodeWhispererSessionState.instance.getSession()
491485
session.requestIdList = []
492486
session.recommendations = []
493-
// session.nextRecommendations = []
494487
session.suggestionStates = new Map<number, string>()
495488
session.completionTypes = new Map<number, CodewhispererCompletionType>()
496489
this.requestId = ''
497490
session.sessionId = ''
498491
this.nextToken = ''
499492
session.requestContext.supplementalMetadata = undefined
500-
// nextSession.requestIdList = []
501-
// nextSession.recommendations = []
502-
// // nextSession.nextRecommendations = []
503-
// nextSession.suggestionStates = new Map<number, string>()
504-
// nextSession.completionTypes = new Map<number, CodewhispererCompletionType>()
505-
// this.requestId = ''
506-
// nextSession.sessionId = ''
507-
// this.nextToken = ''
508-
// nextSession.requestContext.supplementalMetadata = undefined
509493
}
510494

511495
async clearInlineCompletionStates() {
@@ -653,7 +637,6 @@ export class RecommendationHandler {
653637
const session = CodeWhispererSessionState.instance.getSession()
654638

655639
if (!indexShift && session.recommendations.length) {
656-
// TODO: gate behind A/B group if needed
657640
await this.fetchNextRecommendations()
658641
}
659642
await lock.acquire(updateInlineLockKey, async () => {
@@ -725,7 +708,6 @@ export class RecommendationHandler {
725708
const isManualTriggerEnabled: boolean = true
726709
const isSuggestionsWithCodeReferencesEnabled = codewhispererSettings.isSuggestionsWithCodeReferencesEnabled()
727710

728-
// TODO:remove isManualTriggerEnabled
729711
return {
730712
isShowMethodsEnabled,
731713
isManualTriggerEnabled,
@@ -738,9 +720,11 @@ export class RecommendationHandler {
738720
const session = CodeWhispererSessionState.instance.getSession()
739721
const client = new codewhispererClient.DefaultCodeWhispererClient()
740722
const editor = vscode.window.activeTextEditor
741-
if (!editor) return
723+
if (!editor) {
724+
return
725+
}
742726

743-
this.getRecommendations(
727+
await this.getRecommendations(
744728
client,
745729
editor,
746730
session.triggerType,

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ export class CodeWhispererSessionState {
4545
}
4646

4747
export class CodeWhispererSession {
48-
// static #instance: CodeWhispererSession
4948
sessionId: string
5049
requestIdList: string[]
5150
startPos: Position
5251
startCursorOffset: number
5352
leftContextOfCurrentLine: string
5453
requestContext: {
55-
request: ListRecommendationsRequest | GenerateRecommendationsRequest | undefined
54+
request: ListRecommendationsRequest | GenerateRecommendationsRequest
5655
supplementalMetadata: CodeWhispererSupplementalContext | undefined
5756
}
5857
language: CodewhispererLanguage
@@ -77,7 +76,7 @@ export class CodeWhispererSession {
7776
this.startPos = new Position(0, 0)
7877
this.startCursorOffset = 0
7978
this.leftContextOfCurrentLine = ''
80-
this.requestContext = { request: undefined, supplementalMetadata: undefined }
79+
this.requestContext = { request: {} as any, supplementalMetadata: undefined }
8180
this.language = 'python'
8281
this.taskType = undefined
8382
this.triggerType = 'OnDemand'

packages/core/src/testE2E/codewhisperer/referenceTracker.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('CodeWhisperer service invocation', async function () {
4747
isAutomatedTriggerEnabled: true,
4848
isSuggestionsWithCodeReferencesEnabled: false,
4949
}
50+
const session = CodeWhispererSessionState.instance.getSession()
5051

5152
before(async function () {
5253
validConnection = await setValidConnection()
@@ -62,8 +63,7 @@ describe('CodeWhisperer service invocation', async function () {
6263
})
6364

6465
it('trigger known to return recs with references returns rec with reference', async function () {
65-
//check that handler is empty before invocation
66-
const session = CodeWhispererSessionState.instance.getSession()
66+
// check that handler is empty before invocation
6767
const requestIdBefore = RecommendationHandler.instance.requestId
6868
const sessionIdBefore = session.sessionId
6969
const validRecsBefore = RecommendationHandler.instance.isValidResponse()
@@ -98,7 +98,6 @@ describe('CodeWhisperer service invocation', async function () {
9898
it('trigger known to return rec with references does not return rec with references when reference tracker setting is off', async function () {
9999
// check that handler is empty before invocation
100100
const requestIdBefore = RecommendationHandler.instance.requestId
101-
const session = CodeWhispererSessionState.instance.getSession()
102101
const sessionIdBefore = session.sessionId
103102
const validRecsBefore = RecommendationHandler.instance.isValidResponse()
104103

packages/core/src/testE2E/codewhisperer/serviceInvocations.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('CodeWhisperer service invocation', async function () {
4444
})
4545

4646
it('manual trigger returns valid recommendation response', async function () {
47-
//check that handler is empty before invocation
47+
// check that handler is empty before invocation
4848
const requestIdBefore = RecommendationHandler.instance.requestId
4949
const sessionIdBefore = session.sessionId
5050
const validRecsBefore = RecommendationHandler.instance.isValidResponse()
@@ -66,7 +66,7 @@ describe('CodeWhisperer service invocation', async function () {
6666
})
6767

6868
it('auto trigger returns valid recommendation response', async function () {
69-
//check that handler is empty before invocation
69+
// check that handler is empty before invocation
7070
const requestIdBefore = RecommendationHandler.instance.requestId
7171
const sessionIdBefore = session.sessionId
7272
const validRecsBefore = RecommendationHandler.instance.isValidResponse()
@@ -103,7 +103,6 @@ describe('CodeWhisperer service invocation', async function () {
103103

104104
// check that handler is empty before invocation
105105
const requestIdBefore = RecommendationHandler.instance.requestId
106-
const session = CodeWhispererSessionState.instance.getSession()
107106
const sessionIdBefore = session.sessionId
108107
const validRecsBefore = RecommendationHandler.instance.isValidResponse()
109108

0 commit comments

Comments
 (0)