Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/amazonq/src/app/inline/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { LanguageClient } from 'vscode-languageclient'
import { LogInlineCompletionSessionResultsParams } from '@aws/language-server-runtimes/protocol'
import { SessionManager } from './sessionManager'
import { RecommendationService } from './recommendationService'
import { CodeWhispererConstants } from 'aws-core-vscode/codewhisperer'
import { CodeWhispererConstants, ReferenceInlineProvider } from 'aws-core-vscode/codewhisperer'

export class InlineCompletionManager implements Disposable {
private disposable: Disposable
Expand Down Expand Up @@ -181,6 +181,11 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
session.firstCompletionDisplayLatency,
],
}
ReferenceInlineProvider.instance.setInlineReference(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely familiar with the flow but is it something like this:

  • user gets inline suggestion
    • it may have a reference attached
  • if it does have a reference then show it as a code lens
  • if they click the codelens to add a code reference it adds it in the "Code reference log" panel and opens it up

Is that mostly correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that is right, and I realized that I missed the logging reference on acceptance piece, just added it. Thanks for catching!

position.line,
item.insertText as string,
item.references
)
}
return items as InlineCompletionItem[]
}
Expand Down
108 changes: 106 additions & 2 deletions packages/amazonq/test/unit/amazonq/apps/inline/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
* SPDX-License-Identifier: Apache-2.0
*/
import sinon from 'sinon'
import { commands, languages } from 'vscode'
import { CancellationToken, commands, languages, Position } from 'vscode'
import assert from 'assert'
import { LanguageClient } from 'vscode-languageclient'
import { InlineCompletionManager } from '../../../../../src/app/inline/completion'
import { AmazonQInlineCompletionItemProvider, InlineCompletionManager } from '../../../../../src/app/inline/completion'
import { RecommendationService } from '../../../../../src/app/inline/recommendationService'
import { SessionManager } from '../../../../../src/app/inline/sessionManager'
import { createMockDocument } from 'aws-core-vscode/test'
import { ReferenceInlineProvider } from 'aws-core-vscode/codewhisperer'

describe('InlineCompletionManager', () => {
let manager: InlineCompletionManager
Expand All @@ -19,6 +23,10 @@ describe('InlineCompletionManager', () => {
let sandbox: sinon.SinonSandbox
let getActiveSessionStub: sinon.SinonStub
let getActiveRecommendationStub: sinon.SinonStub
const mockDocument = createMockDocument()
const mockPosition = { line: 0, character: 0 } as Position
const mockContext = { triggerKind: 1, selectedCompletionInfo: undefined }
const mockToken = { isCancellationRequested: false } as CancellationToken

beforeEach(() => {
sandbox = sinon.createSandbox()
Expand Down Expand Up @@ -179,4 +187,100 @@ describe('InlineCompletionManager', () => {
})
})
})

describe('AmazonQInlineCompletionItemProvider', () => {
describe('provideInlineCompletionItems', () => {
const fakeReferences = [
{
message: '',
licenseName: 'TEST_LICENSE',
repository: 'TEST_REPO',
recommendationContentSpan: {
start: 0,
end: 10,
},
},
]
const mockSuggestions = [
{
itemId: 'test-item',
insertText: 'test',
references: fakeReferences,
},
]
let mockSessionManager: SessionManager
let provider: AmazonQInlineCompletionItemProvider
let getAllRecommendationsStub: sinon.SinonStub
let recommendationService: RecommendationService
let setInlineReferenceStub: sinon.SinonStub

beforeEach(() => {
recommendationService = new RecommendationService(mockSessionManager)
setInlineReferenceStub = sandbox.stub(ReferenceInlineProvider.instance, 'setInlineReference')

mockSessionManager = {
getActiveSession: getActiveSessionStub,
getActiveRecommendation: getActiveRecommendationStub,
} as unknown as SessionManager

getActiveSessionStub.returns({
sessionId: 'test-session',
suggestions: mockSuggestions,
isRequestInProgress: false,
requestStartTime: Date.now(),
})
getActiveRecommendationStub.returns(mockSuggestions)
getAllRecommendationsStub = sandbox.stub(recommendationService, 'getAllRecommendations')
getAllRecommendationsStub.resolves()
}),
it('should call recommendation service to get new suggestions for new sessions', async () => {
provider = new AmazonQInlineCompletionItemProvider(
languageClient,
recommendationService,
mockSessionManager
)
const items = await provider.provideInlineCompletionItems(
mockDocument,
mockPosition,
mockContext,
mockToken
)
assert(getAllRecommendationsStub.calledOnce)
assert.deepStrictEqual(items, mockSuggestions)
}),
it('should not call recommendation service for existing sessions', async () => {
provider = new AmazonQInlineCompletionItemProvider(
languageClient,
recommendationService,
mockSessionManager,
false
)
const items = await provider.provideInlineCompletionItems(
mockDocument,
mockPosition,
mockContext,
mockToken
)
assert(getAllRecommendationsStub.notCalled)
assert.deepStrictEqual(items, mockSuggestions)
}),
it('should handle reference if there is any', async () => {
provider = new AmazonQInlineCompletionItemProvider(
languageClient,
recommendationService,
mockSessionManager,
false
)
await provider.provideInlineCompletionItems(mockDocument, mockPosition, mockContext, mockToken)
assert(setInlineReferenceStub.calledOnce)
assert(
setInlineReferenceStub.calledWithExactly(
mockPosition.line,
mockSuggestions[0].insertText,
fakeReferences
)
)
})
})
})
})
Loading