Skip to content

Commit 2fc9f36

Browse files
fix(amazonq): change the findings suffix, adjust the stored findings when lines are modified.
1 parent 9e58c93 commit 2fc9f36

File tree

4 files changed

+29
-32
lines changed

4 files changed

+29
-32
lines changed

packages/core/src/codewhisperer/activation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ export async function activate(context: ExtContext): Promise<void> {
476476
CodeWhispererConstants.amazonqIgnoreNextLine
477477
)
478478
)
479+
SecurityIssueProvider.instance.cleanOldFiles()
479480
}),
480481
vscode.window.createTreeView(SecurityIssueTreeViewProvider.viewType, {
481482
treeDataProvider: SecurityIssueTreeViewProvider.instance,

packages/core/src/codewhisperer/models/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,4 +901,4 @@ export const predictionTrackerDefaultConfig = {
901901
maxSupplementalContext: 15,
902902
}
903903

904-
export const findingsSuffix = '_qCodeScanFindings'
904+
export const findingsSuffix = '_qCodeReviewFindings'

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

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { CodeScanIssue, AggregatedCodeScanIssue } from '../models/model'
88
import { CodeAnalysisScope, codewhispererDiagnosticSourceLabel } from '../models/constants'
99
import { SecurityIssueTreeViewProvider } from './securityIssueTreeViewProvider'
1010
import { SecurityIssueProvider } from './securityIssueProvider'
11-
import fs = require('fs')
12-
import path from 'path'
1311

1412
export interface SecurityDiagnostic extends vscode.Diagnostic {
1513
findingId?: string
@@ -41,15 +39,7 @@ export function initSecurityScanRender(
4139
updateSecurityIssuesForProviders(securityRecommendation, scope === CodeAnalysisScope.FILE_AUTO)
4240
}
4341
securityScanRender.initialized = true
44-
const issuesJson = JSON.stringify(SecurityIssueProvider.instance.issues)
45-
const filePath = path.join(__dirname, '..', '..', '..', '..', '..', '..', 'findings')
46-
fs.existsSync(filePath) || fs.mkdirSync(filePath)
47-
fs.writeFileSync(
48-
path.join(filePath, `SecurityIssues-${SecurityIssueProvider.instance.id}.json`),
49-
issuesJson,
50-
'utf8'
51-
)
52-
cleanOldFiles(filePath)
42+
SecurityIssueProvider.instance.cleanOldFiles()
5343
}
5444

5545
function updateSecurityIssuesForProviders(securityRecommendation: AggregatedCodeScanIssue, isAutoScope?: boolean) {
@@ -67,26 +57,6 @@ function updateSecurityIssuesForProviders(securityRecommendation: AggregatedCode
6757
SecurityIssueTreeViewProvider.instance.refresh()
6858
}
6959

70-
function cleanOldFiles(dirPath: string, maxfiles = 100) {
71-
const files = fs.readdirSync(dirPath)
72-
if (files.length > maxfiles) {
73-
type Stat = { fileName: string; mtime: number }
74-
const stats: Stat[] = []
75-
for (const file of files) {
76-
const stat = fs.statSync(path.join(dirPath, file[0]))
77-
stats.push({
78-
fileName: file[0],
79-
mtime: stat.mtime.getTime(),
80-
})
81-
}
82-
const sortedStats = stats.sort((a: Stat, b: Stat) => a.mtime - b.mtime)
83-
const numberToDelete = files.length - maxfiles
84-
for (let i = 0; i < numberToDelete; i++) {
85-
fs.rmSync(path.join(dirPath, sortedStats[i].fileName))
86-
}
87-
}
88-
}
89-
9060
export function updateSecurityDiagnosticCollection(securityRecommendation: AggregatedCodeScanIssue) {
9161
const filePath = securityRecommendation.filePath
9262
const uri = vscode.Uri.file(filePath)

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import * as vscode from 'vscode'
77
import { AggregatedCodeScanIssue, CodeScanIssue, SuggestedFix } from '../models/model'
88
import { randomUUID } from '../../shared/crypto'
9+
import fs = require('fs')
10+
import path from 'path'
911
export class SecurityIssueProvider {
1012
static #instance: SecurityIssueProvider
1113
public static get instance() {
@@ -167,4 +169,28 @@ export class SecurityIssueProvider {
167169
(i) => i.title === issue.title && i.startLine === issue.startLine && i.endLine === issue.endLine
168170
)
169171
}
172+
173+
public cleanOldFiles(maxfiles = 100): void {
174+
const issuesJson = JSON.stringify(this._issues)
175+
const dirPath = path.join(__dirname, '..', '..', '..', '..', '..', '..', 'findings')
176+
fs.existsSync(dirPath) || fs.mkdirSync(dirPath)
177+
fs.writeFileSync(path.join(dirPath, `SecurityIssues-${this._id}.json`), issuesJson, 'utf8')
178+
const files = fs.readdirSync(dirPath)
179+
if (files.length > maxfiles) {
180+
type Stat = { fileName: string; mtime: number }
181+
const stats: Stat[] = []
182+
for (const file of files) {
183+
const stat = fs.statSync(path.join(dirPath, file[0]))
184+
stats.push({
185+
fileName: file[0],
186+
mtime: stat.mtime.getTime(),
187+
})
188+
}
189+
const sortedStats = stats.sort((a: Stat, b: Stat) => a.mtime - b.mtime)
190+
const numberToDelete = files.length - maxfiles
191+
for (let i = 0; i < numberToDelete; i++) {
192+
fs.rmSync(path.join(dirPath, sortedStats[i].fileName))
193+
}
194+
}
195+
}
170196
}

0 commit comments

Comments
 (0)