Skip to content
21 changes: 12 additions & 9 deletions packages/amazonq/src/app/amazonqScan/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Messenger } from './chat/controller/messenger/messenger'
import { UIMessageListener } from './chat/views/actions/uiMessageListener'
import { debounce } from 'lodash'
import { Commands, placeholder } from 'aws-core-vscode/shared'
import { codeReviewInChat } from './models/constants'

export function init(appContext: AmazonQAppInitContext) {
const scanChatControllerEventEmitters: ScanChatControllerEventEmitters = {
Expand Down Expand Up @@ -74,17 +75,19 @@ export function init(appContext: AmazonQAppInitContext) {
return debouncedEvent()
})

Commands.register('aws.amazonq.security.scan-statusbar', async () => {
if (AuthUtil.instance.isConnectionExpired()) {
await AuthUtil.instance.notifyReauthenticate()
}
return focusAmazonQPanel.execute(placeholder, 'amazonq.security.scan').then(() => {
DefaultAmazonQAppInitContext.instance.getAppsToWebViewMessagePublisher().publish({
sender: 'amazonqCore',
command: 'review',
if (!codeReviewInChat) {
Commands.register('aws.amazonq.security.scan-statusbar', async () => {
if (AuthUtil.instance.isConnectionExpired()) {
await AuthUtil.instance.notifyReauthenticate()
}
return focusAmazonQPanel.execute(placeholder, 'amazonq.security.scan').then(() => {
DefaultAmazonQAppInitContext.instance.getAppsToWebViewMessagePublisher().publish({
sender: 'amazonqCore',
command: 'review',
})
})
})
})
}

codeScanState.setChatControllers(scanChatControllerEventEmitters)
onDemandFileScanState.setChatControllers(scanChatControllerEventEmitters)
Expand Down
2 changes: 2 additions & 0 deletions packages/amazonq/src/app/amazonqScan/models/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ const getIconForStep = (targetStep: number, currentStep: number) => {
? checkIcons.done
: checkIcons.wait
}

export const codeReviewInChat = true
28 changes: 24 additions & 4 deletions packages/amazonq/src/lsp/chat/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import { Commands, globals } from 'aws-core-vscode/shared'
import { window } from 'vscode'
import { AmazonQChatViewProvider } from './webviewProvider'
import { CodeScanIssue } from 'aws-core-vscode/codewhisperer'
import { CodeScanIssue, AuthUtil } from 'aws-core-vscode/codewhisperer'
import { getLogger } from 'aws-core-vscode/shared'
import * as vscode from 'vscode'
import * as path from 'path'
import { codeReviewInChat } from '../../app/amazonqScan/models/constants'
import { telemetry, AmazonqCodeReviewTool } from 'aws-core-vscode/telemetry'

/**
* TODO: Re-enable these once we can figure out which path they're going to live in
Expand All @@ -29,7 +31,8 @@ export function registerCommands(provider: AmazonQChatViewProvider) {
filePath,
'Explain',
'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.',
provider
provider,
'explainIssue'
)
),
Commands.register('aws.amazonq.generateFix', (issue: CodeScanIssue, filePath: string) =>
Expand All @@ -38,7 +41,8 @@ export function registerCommands(provider: AmazonQChatViewProvider) {
filePath,
'Fix',
'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.',
provider
provider,
'applyFix'
)
),
Commands.register('aws.amazonq.sendToPrompt', (data) => {
Expand All @@ -64,14 +68,20 @@ export function registerCommands(provider: AmazonQChatViewProvider) {
registerShellCommandShortCut('aws.amazonq.rejectCmdExecution', 'reject-shell-command', provider),
registerShellCommandShortCut('aws.amazonq.stopCmdExecution', 'stop-shell-command', provider)
)
if (codeReviewInChat) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for re-directing the command >Amazon Q: Run Project Review in the top menu

globals.context.subscriptions.push(
registerGenericCommand('aws.amazonq.security.scan-statusbar', 'Review', provider)
)
}
}

async function handleIssueCommand(
issue: CodeScanIssue,
filePath: string,
action: string,
contextPrompt: string,
provider: AmazonQChatViewProvider
provider: AmazonQChatViewProvider,
metricName: string
) {
await focusAmazonQPanel()

Expand All @@ -95,6 +105,16 @@ async function handleIssueCommand(
autoSubmit: true,
},
})

telemetry.amazonq_codeReviewTool.emit({
findingId: issue.findingId,
detectorId: issue.detectorId,
ruleId: issue.ruleId,
credentialStartUrl: AuthUtil.instance.startUrl,
autoDetected: issue.autoDetected,
result: 'Succeeded',
reason: metricName,
} as AmazonqCodeReviewTool)
}

async function openFileWithSelection(issue: CodeScanIssue, filePath: string) {
Expand Down
3 changes: 2 additions & 1 deletion packages/amazonq/src/lsp/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { SessionManager } from '../app/inline/sessionManager'
import { LineTracker } from '../app/inline/stateTracker/lineTracker'
import { InlineTutorialAnnotation } from '../app/inline/tutorials/inlineTutorialAnnotation'
import { InlineChatTutorialAnnotation } from '../app/inline/tutorials/inlineChatTutorialAnnotation'
import { codeReviewInChat } from '../app/amazonqScan/models/constants'

const localize = nls.loadMessageBundle()
const logger = getLogger('amazonqLsp.lspClient')
Expand Down Expand Up @@ -179,7 +180,7 @@ export async function startLanguageServer(
reroute: true,
modelSelection: true,
workspaceFilePath: vscode.workspace.workspaceFile?.fsPath,
codeReviewInChat: false,
codeReviewInChat: codeReviewInChat,
},
window: {
notifications: true,
Expand Down
Loading