Skip to content

Commit 3898ca2

Browse files
Merge pull request #7696 from singhAws/code-review-tool
fix(amazonq): handle suppress single finding, change icon
2 parents c43ff0f + 9bb3be3 commit 3898ca2

File tree

5 files changed

+46
-11
lines changed

5 files changed

+46
-11
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import { decryptResponse, encryptRequest } from '../encryption'
9595
import { getCursorState } from '../utils'
9696
import { focusAmazonQPanel } from './commands'
9797
import { ChatMessage } from '@aws/language-server-runtimes/server-interface'
98+
import { CommentUtils } from 'aws-core-vscode/utils'
9899

99100
export function registerActiveEditorChangeListener(languageClient: LanguageClient) {
100101
let debounceTimer: NodeJS.Timeout | undefined
@@ -701,7 +702,7 @@ async function handleCompleteResult<T extends ChatResult>(
701702
) {
702703
const decryptedMessage = await decryptResponse<T>(result, encryptionKey)
703704

704-
handleSecurityFindings(decryptedMessage, languageClient)
705+
await handleSecurityFindings(decryptedMessage, languageClient)
705706

706707
void provider.webview?.postMessage({
707708
command: chatRequestType.method,
@@ -716,10 +717,10 @@ async function handleCompleteResult<T extends ChatResult>(
716717
disposable.dispose()
717718
}
718719

719-
function handleSecurityFindings(
720+
async function handleSecurityFindings(
720721
decryptedMessage: { additionalMessages?: ChatMessage[] },
721722
languageClient: LanguageClient
722-
): void {
723+
): Promise<void> {
723724
if (decryptedMessage.additionalMessages === undefined || decryptedMessage.additionalMessages.length === 0) {
724725
return
725726
}
@@ -730,10 +731,18 @@ function handleSecurityFindings(
730731
try {
731732
const aggregatedCodeScanIssues: AggregatedCodeScanIssue[] = JSON.parse(message.body)
732733
for (const aggregatedCodeScanIssue of aggregatedCodeScanIssues) {
734+
const document = await vscode.workspace.openTextDocument(aggregatedCodeScanIssue.filePath)
733735
for (const issue of aggregatedCodeScanIssue.issues) {
734-
issue.visible = !CodeWhispererSettings.instance
736+
const isIssueTitleIgnored = CodeWhispererSettings.instance
735737
.getIgnoredSecurityIssues()
736738
.includes(issue.title)
739+
const isSingleIssueIgnored = CommentUtils.detectCommentAboveLine(
740+
document,
741+
issue.startLine,
742+
CodeWhispererConstants.amazonqIgnoreNextLine
743+
)
744+
745+
issue.visible = !isIssueTitleIgnored && !isSingleIssueIgnored
737746
}
738747
}
739748
initSecurityScanRender(aggregatedCodeScanIssues, undefined, CodeAnalysisScope.PROJECT)

packages/amazonq/src/lsp/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ export async function startLanguageServer(
186186
reroute: true,
187187
modelSelection: true,
188188
workspaceFilePath: vscode.workspace.workspaceFile?.fsPath,
189+
qCodeReviewInChat: true,
189190
},
190191
window: {
191192
notifications: true,

packages/amazonq/test/unit/codewhisperer/service/securityIssueHoverProvider.test.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,41 @@ describe('securityIssueHoverProvider', () => {
2121
token = new vscode.CancellationTokenSource()
2222
})
2323

24-
function buildCommandLink(command: string, args: any[], label: string, tooltip: string): string {
25-
return `[$(${command.includes('ignore') ? 'error' : 'comment'}) ${label}](command:${command}?${encodeURIComponent(JSON.stringify(args))} '${tooltip}')`
24+
function buildCommandLink(
25+
command: string,
26+
commandIcon: string,
27+
args: any[],
28+
label: string,
29+
tooltip: string
30+
): string {
31+
return `[$(${commandIcon}) ${label}](command:${command}?${encodeURIComponent(JSON.stringify(args))} '${tooltip}')`
2632
}
2733

2834
function buildExpectedContent(issue: any, fileName: string, description: string, severity?: string): string {
2935
const severityBadge = severity ? ` ![${severity}](severity-${severity.toLowerCase()}.svg)` : ' '
3036
const commands = [
31-
buildCommandLink('aws.amazonq.explainIssue', [issue, fileName], 'Explain', 'Explain with Amazon Q'),
32-
buildCommandLink('aws.amazonq.generateFix', [issue, fileName], 'Fix', 'Fix with Amazon Q'),
33-
buildCommandLink('aws.amazonq.security.ignore', [issue, fileName, 'hover'], 'Ignore', 'Ignore Issue'),
34-
buildCommandLink('aws.amazonq.security.ignoreAll', [issue, 'hover'], 'Ignore All', 'Ignore Similar Issues'),
37+
buildCommandLink(
38+
'aws.amazonq.explainIssue',
39+
'comment',
40+
[issue, fileName],
41+
'Explain',
42+
'Explain with Amazon Q'
43+
),
44+
buildCommandLink('aws.amazonq.generateFix', 'wrench', [issue, fileName], 'Fix', 'Fix with Amazon Q'),
45+
buildCommandLink(
46+
'aws.amazonq.security.ignore',
47+
'error',
48+
[issue, fileName, 'hover'],
49+
'Ignore',
50+
'Ignore Issue'
51+
),
52+
buildCommandLink(
53+
'aws.amazonq.security.ignoreAll',
54+
'error',
55+
[issue, 'hover'],
56+
'Ignore All',
57+
'Ignore Similar Issues'
58+
),
3559
]
3660
return `## title${severityBadge}\n${description}\n\n${commands.join('\n | ')}\n`
3761
}

packages/core/src/codewhisperer/service/securityIssueHoverProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class SecurityIssueHoverProvider implements vscode.HoverProvider {
9090
const generateFixCommand = this._getCommandMarkdown(
9191
'aws.amazonq.generateFix',
9292
[issue, filePath],
93-
'comment',
93+
'wrench',
9494
'Fix',
9595
'Fix with Amazon Q'
9696
)

packages/core/src/shared/utilities/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export { isExtensionInstalled, isExtensionActive } from './vsCodeUtils'
77
export { VSCODE_EXTENSION_ID } from '../extensions'
88
export * from './functionUtils'
99
export * as messageUtils from './messages'
10+
export * as CommentUtils from './commentUtils'

0 commit comments

Comments
 (0)