Skip to content

Commit 632a570

Browse files
Merge pull request #7739 from singhAws/code-review-tool
feat(amazonq): adapt feature flag for CodeReviewInChat, emit metrics for explainIssue, applyFix
1 parent 5d70676 commit 632a570

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

packages/amazonq/src/app/amazonqScan/app.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { Messenger } from './chat/controller/messenger/messenger'
1919
import { UIMessageListener } from './chat/views/actions/uiMessageListener'
2020
import { debounce } from 'lodash'
2121
import { Commands, placeholder } from 'aws-core-vscode/shared'
22+
import { codeReviewInChat } from './models/constants'
2223

2324
export function init(appContext: AmazonQAppInitContext) {
2425
const scanChatControllerEventEmitters: ScanChatControllerEventEmitters = {
@@ -74,17 +75,19 @@ export function init(appContext: AmazonQAppInitContext) {
7475
return debouncedEvent()
7576
})
7677

77-
Commands.register('aws.amazonq.security.scan-statusbar', async () => {
78-
if (AuthUtil.instance.isConnectionExpired()) {
79-
await AuthUtil.instance.notifyReauthenticate()
80-
}
81-
return focusAmazonQPanel.execute(placeholder, 'amazonq.security.scan').then(() => {
82-
DefaultAmazonQAppInitContext.instance.getAppsToWebViewMessagePublisher().publish({
83-
sender: 'amazonqCore',
84-
command: 'review',
78+
if (!codeReviewInChat) {
79+
Commands.register('aws.amazonq.security.scan-statusbar', async () => {
80+
if (AuthUtil.instance.isConnectionExpired()) {
81+
await AuthUtil.instance.notifyReauthenticate()
82+
}
83+
return focusAmazonQPanel.execute(placeholder, 'amazonq.security.scan').then(() => {
84+
DefaultAmazonQAppInitContext.instance.getAppsToWebViewMessagePublisher().publish({
85+
sender: 'amazonqCore',
86+
command: 'review',
87+
})
8588
})
8689
})
87-
})
90+
}
8891

8992
codeScanState.setChatControllers(scanChatControllerEventEmitters)
9093
onDemandFileScanState.setChatControllers(scanChatControllerEventEmitters)

packages/amazonq/src/app/amazonqScan/models/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,5 @@ const getIconForStep = (targetStep: number, currentStep: number) => {
9797
? checkIcons.done
9898
: checkIcons.wait
9999
}
100+
101+
export const codeReviewInChat = true

packages/amazonq/src/lsp/chat/commands.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import { Commands, globals } from 'aws-core-vscode/shared'
77
import { window } from 'vscode'
88
import { AmazonQChatViewProvider } from './webviewProvider'
9-
import { CodeScanIssue } from 'aws-core-vscode/codewhisperer'
9+
import { CodeScanIssue, AuthUtil } from 'aws-core-vscode/codewhisperer'
1010
import { getLogger } from 'aws-core-vscode/shared'
1111
import * as vscode from 'vscode'
1212
import * as path from 'path'
13+
import { codeReviewInChat } from '../../app/amazonqScan/models/constants'
14+
import { telemetry, AmazonqCodeReviewTool } from 'aws-core-vscode/telemetry'
1315

1416
/**
1517
* TODO: Re-enable these once we can figure out which path they're going to live in
@@ -29,7 +31,8 @@ export function registerCommands(provider: AmazonQChatViewProvider) {
2931
filePath,
3032
'Explain',
3133
'Provide a small description of the issue. You must not attempt to fix the issue. You should only give a small summary of it to the user.',
32-
provider
34+
provider,
35+
'explainIssue'
3336
)
3437
),
3538
Commands.register('aws.amazonq.generateFix', (issue: CodeScanIssue, filePath: string) =>
@@ -38,7 +41,8 @@ export function registerCommands(provider: AmazonQChatViewProvider) {
3841
filePath,
3942
'Fix',
4043
'Generate a fix for the following code issue. You must not explain the issue, just generate and explain the fix. The user should have the option to accept or reject the fix before any code is changed.',
41-
provider
44+
provider,
45+
'applyFix'
4246
)
4347
),
4448
Commands.register('aws.amazonq.sendToPrompt', (data) => {
@@ -64,14 +68,20 @@ export function registerCommands(provider: AmazonQChatViewProvider) {
6468
registerShellCommandShortCut('aws.amazonq.rejectCmdExecution', 'reject-shell-command', provider),
6569
registerShellCommandShortCut('aws.amazonq.stopCmdExecution', 'stop-shell-command', provider)
6670
)
71+
if (codeReviewInChat) {
72+
globals.context.subscriptions.push(
73+
registerGenericCommand('aws.amazonq.security.scan-statusbar', 'Review', provider)
74+
)
75+
}
6776
}
6877

6978
async function handleIssueCommand(
7079
issue: CodeScanIssue,
7180
filePath: string,
7281
action: string,
7382
contextPrompt: string,
74-
provider: AmazonQChatViewProvider
83+
provider: AmazonQChatViewProvider,
84+
metricName: string
7585
) {
7686
await focusAmazonQPanel()
7787

@@ -95,6 +105,16 @@ async function handleIssueCommand(
95105
autoSubmit: true,
96106
},
97107
})
108+
109+
telemetry.amazonq_codeReviewTool.emit({
110+
findingId: issue.findingId,
111+
detectorId: issue.detectorId,
112+
ruleId: issue.ruleId,
113+
credentialStartUrl: AuthUtil.instance.startUrl,
114+
autoDetected: issue.autoDetected,
115+
result: 'Succeeded',
116+
reason: metricName,
117+
} as AmazonqCodeReviewTool)
98118
}
99119

100120
async function openFileWithSelection(issue: CodeScanIssue, filePath: string) {

packages/amazonq/src/lsp/client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { SessionManager } from '../app/inline/sessionManager'
5151
import { LineTracker } from '../app/inline/stateTracker/lineTracker'
5252
import { InlineTutorialAnnotation } from '../app/inline/tutorials/inlineTutorialAnnotation'
5353
import { InlineChatTutorialAnnotation } from '../app/inline/tutorials/inlineChatTutorialAnnotation'
54+
import { codeReviewInChat } from '../app/amazonqScan/models/constants'
5455

5556
const localize = nls.loadMessageBundle()
5657
const logger = getLogger('amazonqLsp.lspClient')
@@ -179,7 +180,7 @@ export async function startLanguageServer(
179180
reroute: true,
180181
modelSelection: true,
181182
workspaceFilePath: vscode.workspace.workspaceFile?.fsPath,
182-
codeReviewInChat: false,
183+
codeReviewInChat: codeReviewInChat,
183184
},
184185
window: {
185186
notifications: true,

0 commit comments

Comments
 (0)