Skip to content

Commit 4b20c5a

Browse files
authored
refactor(ziputil): remove non-zipping related utilities out of ZipUtil (aws#6830)
## Problem `ZipUtil` contains a mix of different utilities from working with workspaces, to computing git diffs. These are all used in zipping the project, but inherently have no connection to it. Larger problem is that `ZipUtil` is highly coupled to agent implementations and is difficult to generalize. Moving out non-zipping noise will help. ## Solution - Move these utils to more appropriate locations. - Move the `GitDiff` utilities out of the `ZipUtil` class. These functions have no test coverage and are therefore unsafe to export or move to their own file in its current state. ## Future Work Refactor to avoid references to scope and use case. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent d67aa9d commit 4b20c5a

File tree

9 files changed

+236
-208
lines changed

9 files changed

+236
-208
lines changed

packages/core/src/codewhisperer/commands/startSecurityScan.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
import { SecurityIssueTreeViewProvider } from '../service/securityIssueTreeViewProvider'
5151
import { ChatSessionManager } from '../../amazonqScan/chat/storages/chatSession'
5252
import { TelemetryHelper } from '../util/telemetryHelper'
53+
import { getWorkspacePaths } from '../../shared/utilities/workspaceUtils'
5354

5455
const localize = nls.loadMessageBundle()
5556
export const stopScanButton = localize('aws.codewhisperer.stopscan', 'Stop Scan')
@@ -156,7 +157,7 @@ export async function startSecurityScan(
156157
})
157158
}
158159
const zipMetadata = await zipUtil.generateZip(editor?.document.uri, scope)
159-
const projectPaths = zipUtil.getProjectPaths()
160+
const projectPaths = getWorkspacePaths()
160161

161162
const contextTruncationStartTime = performance.now()
162163
codeScanTelemetryEntry.contextTruncationDuration = performance.now() - contextTruncationStartTime

packages/core/src/codewhisperer/commands/startTestGeneration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ChildProcess, spawn } from 'child_process' // eslint-disable-line no-re
2121
import { BuildStatus } from '../../amazonqTest/chat/session/session'
2222
import { fs } from '../../shared/fs/fs'
2323
import { Range } from '../client/codewhispereruserclient'
24+
import { getWorkspaceForFile } from '../../shared/utilities/workspaceUtils'
2425

2526
// eslint-disable-next-line unicorn/no-null
2627
let spawnResult: ChildProcess | null = null
@@ -48,7 +49,7 @@ export async function startTestGenerationProcess(
4849

4950
const zipUtil = new ZipUtil()
5051
if (initialExecution) {
51-
const projectPath = zipUtil.getProjectPath(filePath) ?? ''
52+
const projectPath = getWorkspaceForFile(filePath) ?? ''
5253
const relativeTargetPath = path.relative(projectPath, filePath)
5354
session.listOfTestGenerationJobId = []
5455
session.shortAnswer = undefined

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,3 +926,7 @@ export const testGenExcludePatterns = [
926926
'**/*.deb',
927927
'**/*.model',
928928
]
929+
930+
export const isFileAnalysisScope = (scope: CodeAnalysisScope) => {
931+
return scope === CodeAnalysisScope.FILE_AUTO || scope === CodeAnalysisScope.FILE_ON_DEMAND
932+
}

0 commit comments

Comments
 (0)