Skip to content

Commit e5cc9a7

Browse files
committed
fix(amazonq): fix issue with reject
1 parent a270116 commit e5cc9a7

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

packages/amazonq/src/app/inline/completion.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,19 @@ export class InlineCompletionManager implements Disposable {
7979
}
8080
commands.registerCommand('aws.amazonq.acceptInline', onInlineAcceptance)
8181

82-
const onInlineRejection = async (sessionId: string, itemId: string) => {
82+
const onInlineRejection = async () => {
8383
await commands.executeCommand('editor.action.inlineSuggest.hide')
8484
// TODO: also log the seen state for other suggestions in session
85+
this.disposable.dispose()
86+
this.disposable = languages.registerInlineCompletionItemProvider(
87+
CodeWhispererConstants.platformLanguageIds,
88+
this.inlineCompletionProvider
89+
)
90+
const sessionId = this.sessionManager.getActiveSession()?.sessionId
91+
const itemId = this.sessionManager.getActiveRecommendation()[0]?.itemId
92+
if (!sessionId || !itemId) {
93+
return
94+
}
8595
const params: LogInlineCompletionSessionResultsParams = {
8696
sessionId: sessionId,
8797
completionSessionResult: {
@@ -93,13 +103,8 @@ export class InlineCompletionManager implements Disposable {
93103
},
94104
}
95105
this.languageClient.sendNotification(this.logSessionResultMessageName, params)
96-
this.disposable.dispose()
97-
this.disposable = languages.registerInlineCompletionItemProvider(
98-
CodeWhispererConstants.platformLanguageIds,
99-
this.inlineCompletionProvider
100-
)
101106
}
102-
commands.registerCommand('aws.amazonq.rejectInline', onInlineRejection)
107+
commands.registerCommand('aws.amazonq.rejectCodeSuggestion', onInlineRejection)
103108

104109
/*
105110
We have to overwrite the prev. and next. commands because the inlineCompletionProvider only contained the current item

packages/amazonq/src/lsp/activation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
1818
Commands.register({ id: 'aws.amazonq.invokeInlineCompletion', autoconnect: true }, async () => {
1919
await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
2020
}),
21-
Commands.declare('aws.amazonq.rejectCodeSuggestion', () => async () => {
22-
await vscode.commands.executeCommand('editor.action.inlineSuggest.hide')
23-
}).register()
21+
vscode.workspace.onDidCloseTextDocument(async () => {
22+
await vscode.commands.executeCommand('aws.amazonq.rejectCodeSuggestion')
23+
})
2424
)
2525
} catch (err) {
2626
const e = err as ToolkitError

packages/amazonq/test/unit/amazonq/apps/inline/completion.test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ describe('InlineCompletionManager', () => {
1717
let executeCommandStub: sinon.SinonStub
1818
let disposableStub: sinon.SinonStub
1919
let sandbox: sinon.SinonSandbox
20+
let getActiveSessionStub: sinon.SinonStub
21+
let getActiveRecommendationStub: sinon.SinonStub
2022

2123
beforeEach(() => {
2224
sandbox = sinon.createSandbox()
@@ -38,6 +40,8 @@ describe('InlineCompletionManager', () => {
3840
} as unknown as LanguageClient
3941

4042
manager = new InlineCompletionManager(languageClient)
43+
getActiveSessionStub = sandbox.stub(manager['sessionManager'], 'getActiveSession')
44+
getActiveRecommendationStub = sandbox.stub(manager['sessionManager'], 'getActiveRecommendation')
4145
})
4246

4347
afterEach(() => {
@@ -70,7 +74,7 @@ describe('InlineCompletionManager', () => {
7074

7175
it('should register accept and reject commands', () => {
7276
assert(registerCommandStub.calledWith('aws.amazonq.acceptInline'))
73-
assert(registerCommandStub.calledWith('aws.amazonq.rejectInline'))
77+
assert(registerCommandStub.calledWith('aws.amazonq.rejectCodeSuggestion'))
7478
})
7579

7680
describe('onInlineAcceptance', () => {
@@ -114,12 +118,23 @@ describe('InlineCompletionManager', () => {
114118
// Get the rejection handler
115119
const rejectionHandler = registerCommandStub
116120
.getCalls()
117-
.find((call) => call.args[0] === 'aws.amazonq.rejectInline')?.args[1]
121+
.find((call) => call.args[0] === 'aws.amazonq.rejectCodeSuggestion')?.args[1]
118122

119123
const sessionId = 'test-session'
120124
const itemId = 'test-item'
125+
const mockSuggestion = {
126+
itemId,
127+
insertText: 'test',
128+
}
121129

122-
await rejectionHandler(sessionId, itemId)
130+
getActiveSessionStub.returns({
131+
sessionId: 'test-session',
132+
suggestions: [mockSuggestion],
133+
isRequestInProgress: false,
134+
requestStartTime: Date.now(),
135+
})
136+
getActiveRecommendationStub.returns([mockSuggestion])
137+
await rejectionHandler()
123138

124139
assert(executeCommandStub.calledWith('editor.action.inlineSuggest.hide'))
125140
assert(sendNotificationStub.calledOnce)

0 commit comments

Comments
 (0)