44 */
55
66import * as vscode from 'vscode'
7- import { CodeScanIssue , AggregatedCodeScanIssue , CodeScansState } from '../models/model'
7+ import { CodeScanIssue , AggregatedCodeScanIssue } from '../models/model'
88import { CodeAnalysisScope , codewhispererDiagnosticSourceLabel } from '../models/constants'
99import { SecurityIssueTreeViewProvider } from './securityIssueTreeViewProvider'
1010import { SecurityIssueProvider } from './securityIssueProvider'
@@ -30,24 +30,30 @@ export function initSecurityScanRender(
3030 scope : CodeAnalysisScope
3131) {
3232 securityScanRender . initialized = false
33- if ( ( scope === CodeAnalysisScope . FILE_AUTO || scope === CodeAnalysisScope . FILE_ON_DEMAND ) && editor ) {
33+ if ( scope === CodeAnalysisScope . FILE_ON_DEMAND && editor ) {
3434 securityScanRender . securityDiagnosticCollection ?. delete ( editor . document . uri )
3535 } else if ( scope === CodeAnalysisScope . PROJECT ) {
3636 securityScanRender . securityDiagnosticCollection ?. clear ( )
3737 }
3838 for ( const securityRecommendation of securityRecommendationList ) {
3939 updateSecurityDiagnosticCollection ( securityRecommendation )
40- updateSecurityIssuesForProviders ( securityRecommendation )
40+ updateSecurityIssuesForProviders ( securityRecommendation , scope === CodeAnalysisScope . FILE_AUTO )
4141 }
4242 securityScanRender . initialized = true
4343}
4444
45- function updateSecurityIssuesForProviders ( securityRecommendation : AggregatedCodeScanIssue ) {
46- const updatedSecurityRecommendationList = [
47- ...SecurityIssueProvider . instance . issues . filter ( ( group ) => group . filePath !== securityRecommendation . filePath ) ,
48- securityRecommendation ,
49- ]
50- SecurityIssueProvider . instance . issues = updatedSecurityRecommendationList
45+ function updateSecurityIssuesForProviders ( securityRecommendation : AggregatedCodeScanIssue , isAutoScope ?: boolean ) {
46+ if ( isAutoScope ) {
47+ SecurityIssueProvider . instance . mergeIssues ( securityRecommendation )
48+ } else {
49+ const updatedSecurityRecommendationList = [
50+ ...SecurityIssueProvider . instance . issues . filter (
51+ ( group ) => group . filePath !== securityRecommendation . filePath
52+ ) ,
53+ securityRecommendation ,
54+ ]
55+ SecurityIssueProvider . instance . issues = updatedSecurityRecommendationList
56+ }
5157 SecurityIssueTreeViewProvider . instance . refresh ( )
5258}
5359
@@ -58,8 +64,22 @@ export function updateSecurityDiagnosticCollection(securityRecommendation: Aggre
5864 const securityDiagnostics : vscode . Diagnostic [ ] = vscode . languages
5965 . getDiagnostics ( uri )
6066 . filter ( ( diagnostic ) => diagnostic . source === codewhispererDiagnosticSourceLabel )
61- for ( const securityIssue of securityRecommendation . issues . filter ( ( securityIssue ) => securityIssue . visible ) ) {
62- securityDiagnostics . push ( createSecurityDiagnostic ( securityIssue ) )
67+ for ( const securityIssue of securityRecommendation . issues ) {
68+ const existingDiagnosticIndex = securityDiagnostics . findIndex (
69+ ( diagnostic ) =>
70+ ( diagnostic . message === securityIssue . title &&
71+ diagnostic . range . start . line === securityIssue . startLine &&
72+ diagnostic . range . end . line === securityIssue . endLine ) ||
73+ ( diagnostic . message === 'Re-scan to validate the fix: ' + securityIssue . title &&
74+ diagnostic . range . start . line === securityIssue . startLine &&
75+ diagnostic . range . end . line === securityIssue . startLine )
76+ )
77+ if ( existingDiagnosticIndex !== - 1 ) {
78+ securityDiagnostics . splice ( existingDiagnosticIndex , 1 )
79+ }
80+ if ( securityIssue . visible ) {
81+ securityDiagnostics . push ( createSecurityDiagnostic ( securityIssue ) )
82+ }
6383 }
6484 securityDiagnosticCollection . set ( uri , securityDiagnostics )
6585}
@@ -112,8 +132,7 @@ export function disposeSecurityDiagnostic(event: vscode.TextDocumentChangeEvent)
112132 if (
113133 issue . severity === vscode . DiagnosticSeverity . Warning &&
114134 intersection &&
115- ( / \S / . test ( changedText ) || changedText === '' ) &&
116- ! CodeScansState . instance . isScansEnabled ( )
135+ ( / \S / . test ( changedText ) || changedText === '' )
117136 ) {
118137 issue . severity = vscode . DiagnosticSeverity . Information
119138 issue . message = 'Re-scan to validate the fix: ' + issue . message
0 commit comments