-
Notifications
You must be signed in to change notification settings - Fork 749
fix(amazonq): auto-review removes existing issues #6535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "type": "Bug Fix", | ||
| "description": "/review: Auto-review should not remove issues from manual reviews" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| */ | ||
|
|
||
| import * as vscode from 'vscode' | ||
| import { CodeScanIssue, AggregatedCodeScanIssue, CodeScansState } from '../models/model' | ||
| import { CodeScanIssue, AggregatedCodeScanIssue } from '../models/model' | ||
| import { CodeAnalysisScope, codewhispererDiagnosticSourceLabel } from '../models/constants' | ||
| import { SecurityIssueTreeViewProvider } from './securityIssueTreeViewProvider' | ||
| import { SecurityIssueProvider } from './securityIssueProvider' | ||
|
|
@@ -30,24 +30,30 @@ export function initSecurityScanRender( | |
| scope: CodeAnalysisScope | ||
| ) { | ||
| securityScanRender.initialized = false | ||
| if ((scope === CodeAnalysisScope.FILE_AUTO || scope === CodeAnalysisScope.FILE_ON_DEMAND) && editor) { | ||
| if (scope === CodeAnalysisScope.FILE_ON_DEMAND && editor) { | ||
| securityScanRender.securityDiagnosticCollection?.delete(editor.document.uri) | ||
| } else if (scope === CodeAnalysisScope.PROJECT) { | ||
| securityScanRender.securityDiagnosticCollection?.clear() | ||
| } | ||
| for (const securityRecommendation of securityRecommendationList) { | ||
| updateSecurityDiagnosticCollection(securityRecommendation) | ||
| updateSecurityIssuesForProviders(securityRecommendation) | ||
| updateSecurityIssuesForProviders(securityRecommendation, scope === CodeAnalysisScope.FILE_AUTO) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so we are skipping rendering of issues all together for auto scans and updating the list.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, here auto-scan results should not remove anything existing. Only append new ones or skip existing ones |
||
| } | ||
| securityScanRender.initialized = true | ||
| } | ||
|
|
||
| function updateSecurityIssuesForProviders(securityRecommendation: AggregatedCodeScanIssue) { | ||
| const updatedSecurityRecommendationList = [ | ||
| ...SecurityIssueProvider.instance.issues.filter((group) => group.filePath !== securityRecommendation.filePath), | ||
| securityRecommendation, | ||
| ] | ||
| SecurityIssueProvider.instance.issues = updatedSecurityRecommendationList | ||
| function updateSecurityIssuesForProviders(securityRecommendation: AggregatedCodeScanIssue, isAutoScope?: boolean) { | ||
| if (isAutoScope) { | ||
| SecurityIssueProvider.instance.mergeIssues(securityRecommendation) | ||
| } else { | ||
| const updatedSecurityRecommendationList = [ | ||
| ...SecurityIssueProvider.instance.issues.filter( | ||
| (group) => group.filePath !== securityRecommendation.filePath | ||
| ), | ||
| securityRecommendation, | ||
| ] | ||
| SecurityIssueProvider.instance.issues = updatedSecurityRecommendationList | ||
| } | ||
| SecurityIssueTreeViewProvider.instance.refresh() | ||
| } | ||
|
|
||
|
|
@@ -58,8 +64,22 @@ export function updateSecurityDiagnosticCollection(securityRecommendation: Aggre | |
| const securityDiagnostics: vscode.Diagnostic[] = vscode.languages | ||
| .getDiagnostics(uri) | ||
| .filter((diagnostic) => diagnostic.source === codewhispererDiagnosticSourceLabel) | ||
| for (const securityIssue of securityRecommendation.issues.filter((securityIssue) => securityIssue.visible)) { | ||
| securityDiagnostics.push(createSecurityDiagnostic(securityIssue)) | ||
| for (const securityIssue of securityRecommendation.issues) { | ||
| const existingDiagnosticIndex = securityDiagnostics.findIndex( | ||
| (diagnostic) => | ||
| (diagnostic.message === securityIssue.title && | ||
| diagnostic.range.start.line === securityIssue.startLine && | ||
| diagnostic.range.end.line === securityIssue.endLine) || | ||
| (diagnostic.message === 'Re-scan to validate the fix: ' + securityIssue.title && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't this a bit manual check?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we can clean this up later. We need to check this because there are cases where the title has been modified by document changes, but ultimately it is still the same finding. |
||
| diagnostic.range.start.line === securityIssue.startLine && | ||
| diagnostic.range.end.line === securityIssue.startLine) | ||
| ) | ||
| if (existingDiagnosticIndex !== -1) { | ||
| securityDiagnostics.splice(existingDiagnosticIndex, 1) | ||
| } | ||
| if (securityIssue.visible) { | ||
| securityDiagnostics.push(createSecurityDiagnostic(securityIssue)) | ||
| } | ||
| } | ||
| securityDiagnosticCollection.set(uri, securityDiagnostics) | ||
| } | ||
|
|
@@ -112,8 +132,7 @@ export function disposeSecurityDiagnostic(event: vscode.TextDocumentChangeEvent) | |
| if ( | ||
| issue.severity === vscode.DiagnosticSeverity.Warning && | ||
| intersection && | ||
| (/\S/.test(changedText) || changedText === '') && | ||
| !CodeScansState.instance.isScansEnabled() | ||
| (/\S/.test(changedText) || changedText === '') | ||
| ) { | ||
| issue.severity = vscode.DiagnosticSeverity.Information | ||
| issue.message = 'Re-scan to validate the fix: ' + issue.message | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this being removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bug. The
toggleIssuesVisibilitywas getting invoked on every document change, so it always removes all of the diagnostics when really we just want to check if an issue should be visible or not.