Skip to content

Commit

Permalink
Merge master into feature/serverlessland
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-toolkit-automation authored Feb 13, 2025
2 parents 068a515 + f781fc9 commit 34746db
Show file tree
Hide file tree
Showing 23 changed files with 120 additions and 288 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Removal",
"description": "Reverted prefetch logic to enable more stable inline completion"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@ import * as sinon from 'sinon'
import {
onAcceptance,
AcceptedSuggestionEntry,
CodeWhispererSessionState,
session,
CodeWhispererTracker,
RecommendationHandler,
AuthUtil,
CodeWhispererSession,
} from 'aws-core-vscode/codewhisperer'
import { resetCodeWhispererGlobalVariables, createMockTextEditor } from 'aws-core-vscode/test'
import { assertTelemetryCurried } from 'aws-core-vscode/test'

describe('onAcceptance', function () {
let session: CodeWhispererSession
describe('onAcceptance', function () {
beforeEach(async function () {
session = CodeWhispererSessionState.instance.getSession()
await resetCodeWhispererGlobalVariables()
session.reset()
})

afterEach(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@ import * as vscode from 'vscode'
import * as sinon from 'sinon'
import { resetCodeWhispererGlobalVariables, createMockTextEditor } from 'aws-core-vscode/test'
import { assertTelemetryCurried } from 'aws-core-vscode/test'
import {
onInlineAcceptance,
RecommendationHandler,
AuthUtil,
CodeWhispererSessionState,
CodeWhispererSession,
} from 'aws-core-vscode/codewhisperer'
import { onInlineAcceptance, RecommendationHandler, AuthUtil, session } from 'aws-core-vscode/codewhisperer'
import { globals } from 'aws-core-vscode/shared'
import { extensionVersion } from 'aws-core-vscode/shared'

describe('onInlineAcceptance', function () {
let session: CodeWhispererSession
describe('onInlineAcceptance', function () {
beforeEach(async function () {
session = CodeWhispererSessionState.instance.getSession()
await resetCodeWhispererGlobalVariables()
session.reset()
})

afterEach(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
getLabel,
Recommendation,
RecommendationHandler,
CodeWhispererSessionState,
session,
} from 'aws-core-vscode/codewhisperer'
import { createMockDocument, resetCodeWhispererGlobalVariables } from 'aws-core-vscode/test'

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

describe('getCompletionItem', function () {
it('should return targetCompletionItem given input', function () {
const session = CodeWhispererSessionState.instance.getSession()
session.startPos = new vscode.Position(0, 0)
RecommendationHandler.instance.requestId = 'mock_requestId_getCompletionItem'
session.sessionId = 'mock_sessionId_getCompletionItem'
Expand Down Expand Up @@ -96,7 +95,6 @@ describe('completionProviderService', function () {

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

it('should return empty completion items when recommendation is empty', async function () {
const session = CodeWhispererSessionState.instance.getSession()
session.recommendations = []
const mockPosition = new vscode.Position(14, 83)
const mockDocument = createMockDocument()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
CodeSuggestionsState,
ConfigurationEntry,
CWInlineCompletionItemProvider,
CodeWhispererSessionState,
session,
AuthUtil,
listCodeWhispererCommandsId,
DefaultCodeWhispererClient,
Expand Down Expand Up @@ -46,7 +46,6 @@ describe('inlineCompletionService', function () {
})

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

describe('clearInlineCompletionStates', function () {
it('should remove inline reference and recommendations', async function () {
const session = CodeWhispererSessionState.instance.getSession()
const fakeReferences = [
{
message: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as vscode from 'vscode'
import * as sinon from 'sinon'
import {
ReferenceInlineProvider,
CodeWhispererSessionState,
session,
AuthUtil,
DefaultCodeWhispererClient,
RecommendationsList,
Expand Down Expand Up @@ -55,7 +55,6 @@ describe('recommendationHandler', function () {
})

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

it('should assign request id correctly', async function () {
const session = CodeWhispererSessionState.instance.getSession()
const mockServerResult = {
recommendations: [{ content: "print('Hello World!')" }, { content: '' }],
$response: {
Expand All @@ -101,7 +99,7 @@ describe('recommendationHandler', function () {
const handler = new RecommendationHandler()
sinon.stub(handler, 'getServerResponse').resolves(mockServerResult)
sinon.stub(handler, 'isCancellationRequested').returns(false)
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, session, 'Enter', false)
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, 'Enter', false)
assert.strictEqual(handler.requestId, 'test_request')
assert.strictEqual(session.sessionId, 'test_request')
assert.strictEqual(session.triggerType, 'AutoTrigger')
Expand Down Expand Up @@ -130,10 +128,9 @@ describe('recommendationHandler', function () {
strategy: 'empty',
})
sinon.stub(performance, 'now').returns(0.0)
const session = CodeWhispererSessionState.instance.getSession()
session.startPos = new vscode.Position(1, 0)
session.startCursorOffset = 2
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, session, 'Enter')
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, 'Enter')
const assertTelemetry = assertTelemetryCurried('codewhisperer_serviceInvocation')
assertTelemetry({
codewhispererRequestId: 'test_request',
Expand Down Expand Up @@ -170,11 +167,10 @@ describe('recommendationHandler', function () {
const handler = new RecommendationHandler()
sinon.stub(handler, 'getServerResponse').resolves(mockServerResult)
sinon.stub(performance, 'now').returns(0.0)
const session = CodeWhispererSessionState.instance.getSession()
session.startPos = new vscode.Position(1, 0)
session.requestIdList = ['test_request_empty']
session.startCursorOffset = 2
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, session, 'Enter')
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, 'Enter')
const assertTelemetry = assertTelemetryCurried('codewhisperer_userDecision')
assertTelemetry({
codewhispererRequestId: 'test_request_empty',
Expand All @@ -196,7 +192,6 @@ describe('recommendationHandler', function () {
sinon.restore()
})
it('should return true if any response is not empty', function () {
const session = CodeWhispererSessionState.instance.getSession()
const handler = new RecommendationHandler()
session.recommendations = [
{
Expand All @@ -209,14 +204,12 @@ describe('recommendationHandler', function () {
})

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

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

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

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

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

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

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

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

describe('on event change', async function () {
beforeEach(function () {
const session = CodeWhispererSessionState.instance.getSession()
const fakeReferences = [
{
message: '',
Expand All @@ -285,14 +274,12 @@ describe('recommendationHandler', function () {
})

it('should remove inline reference onEditorChange', async function () {
const session = CodeWhispererSessionState.instance.getSession()
session.sessionId = 'aSessionId'
RecommendationHandler.instance.requestId = 'aRequestId'
await RecommendationHandler.instance.onEditorChange()
assert.strictEqual(ReferenceInlineProvider.instance.refs.length, 0)
})
it('should remove inline reference onFocusChange', async function () {
const session = CodeWhispererSessionState.instance.getSession()
session.sessionId = 'aSessionId'
RecommendationHandler.instance.requestId = 'aRequestId'
await RecommendationHandler.instance.onFocusChange()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
invokeRecommendation,
ConfigurationEntry,
RecommendationHandler,
CodeWhispererSessionState,
session,
vsCodeCursorUpdateDelay,
AuthUtil,
} from 'aws-core-vscode/codewhisperer'
Expand All @@ -36,7 +36,6 @@ type CodeWhispererResponse = ListRecommendationsResponse & {
let tempFolder: string

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

Expand Down Expand Up @@ -520,7 +519,6 @@ async function manualTrigger(

// Note: RecommendationHandler.isSuggestionVisible seems not to work well, hence not using it
async function waitUntilSuggestionSeen(index: number = 0) {
const session = CodeWhispererSessionState.instance.getSession()
const state = await waitUntil(
async () => {
const r = session.getSuggestionState(index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import assert from 'assert'
import { assertTelemetryCurried, resetCodeWhispererGlobalVariables } from 'aws-core-vscode/test'
import { TelemetryHelper, Completion, CodeWhispererSessionState } from 'aws-core-vscode/codewhisperer'
import { TelemetryHelper, Completion, session } from 'aws-core-vscode/codewhisperer'
import {
CodewhispererCompletionType,
CodewhispererSuggestionState,
Expand Down Expand Up @@ -39,7 +39,6 @@ function aCompletion(): Completion {
}

describe('telemetryHelper', function () {
const session = CodeWhispererSessionState.instance.getSession()
describe('clientComponentLatency', function () {
let sut: TelemetryHelper

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

afterEach(function () {
sinon.restore()
session.reset()
})

it('resetClientComponentLatencyTime should reset state variables', function () {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/codewhisperer/client/codewhisperer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { isSsoConnection } from '../../auth/connection'
import { pageableToCollection } from '../../shared/utilities/collectionUtils'
import apiConfig = require('./service-2.json')
import userApiConfig = require('./user-service-2.json')
import { CodeWhispererSessionState } from '../util/codeWhispererSession'
import { session } from '../util/codeWhispererSession'
import { getLogger } from '../../shared/logger/logger'
import { indent } from '../../shared/utilities/textUtilities'
import { keepAliveHeader } from './agent'
Expand Down Expand Up @@ -133,7 +133,6 @@ export class DefaultCodeWhispererClient {
}

async createUserSdkClient(maxRetries?: number): Promise<CodeWhispererUserClient> {
const session = CodeWhispererSessionState.instance.getSession()
const isOptedOut = CodeWhispererSettings.instance.isOptoutEnabled()
session.setFetchCredentialStart()
const bearerToken = await AuthUtil.instance.getBearerToken()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { vsCodeState, ConfigurationEntry } from '../models/model'
import { resetIntelliSenseState } from '../util/globalStateUtil'
import { DefaultCodeWhispererClient } from '../client/codewhisperer'
import { RecommendationHandler } from '../service/recommendationHandler'
import { CodeWhispererSessionState } from '../util/codeWhispererSession'
import { session } from '../util/codeWhispererSession'
import { RecommendationService } from '../service/recommendationService'

/**
Expand All @@ -33,7 +33,6 @@ export async function invokeRecommendation(
/**
* When using intelliSense, if invocation position changed, reject previous active recommendations
*/
const session = CodeWhispererSessionState.instance.getSession()
if (vsCodeState.isIntelliSenseActive && editor.selection.active !== session.startPos) {
resetIntelliSenseState(
config.isManualTriggerEnabled,
Expand Down
15 changes: 1 addition & 14 deletions packages/core/src/codewhisperer/commands/onInlineAcceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { ReferenceLogViewProvider } from '../service/referenceLogViewProvider'
import { ReferenceHoverProvider } from '../service/referenceHoverProvider'
import { ImportAdderProvider } from '../service/importAdderProvider'
import { CodeWhispererSessionState } from '../util/codeWhispererSession'
import { session } from '../util/codeWhispererSession'
import path from 'path'
import { RecommendationService } from '../service/recommendationService'
import { Container } from '../service/serviceContainer'
Expand Down Expand Up @@ -89,7 +89,6 @@ export async function onInlineAcceptance(acceptanceEntry: OnRecommendationAccept
const end = acceptanceEntry.editor.selection.active

vsCodeState.isCodeWhispererEditing = true
const session = CodeWhispererSessionState.instance.getSession()
/**
* Mitigation to right context handling mainly for auto closing bracket use case
*/
Expand Down Expand Up @@ -143,17 +142,5 @@ export async function onInlineAcceptance(acceptanceEntry: OnRecommendationAccept
}

RecommendationHandler.instance.reportUserDecisions(acceptanceEntry.acceptIndex)
await promoteNextSessionIfAvailable(acceptanceEntry)
}
}

async function promoteNextSessionIfAvailable(acceptanceEntry: OnRecommendationAcceptanceEntry) {
if (acceptanceEntry.acceptIndex === 0 && acceptanceEntry.editor) {
const nextSession = CodeWhispererSessionState.instance.getNextSession()
nextSession.startPos = acceptanceEntry.editor.selection.active
CodeWhispererSessionState.instance.setSession(nextSession)
if (nextSession.recommendations.length) {
await RecommendationHandler.instance.tryShowRecommendation()
}
}
}
2 changes: 1 addition & 1 deletion packages/core/src/codewhisperer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export { onAcceptance } from './commands/onAcceptance'
export { CodeWhispererTracker } from './tracker/codewhispererTracker'
export { RecommendationHandler } from './service/recommendationHandler'
export { CodeWhispererUserGroupSettings } from './util/userGroupUtil'
export { CodeWhispererSessionState, CodeWhispererSession } from './util/codeWhispererSession'
export { session } from './util/codeWhispererSession'
export { onInlineAcceptance } from './commands/onInlineAcceptance'
export { stopTransformByQ } from './commands/startTransformByQ'
export { getCompletionItems, getCompletionItem, getLabel } from './service/completionProvider'
Expand Down
Loading

0 comments on commit 34746db

Please sign in to comment.