@@ -12,6 +12,8 @@ import { ToolkitError } from '../../shared/errors'
12
12
import { fsCommon } from '../../srcShared/fs'
13
13
import { collectFiles } from '../../amazonqFeatureDev/util/files'
14
14
import { getLoggerForScope } from '../service/securityScanHandler'
15
+ import { runtimeLanguageContext } from './runtimeLanguageContext'
16
+ import { CodewhispererLanguage } from '../../shared/telemetry/telemetry.gen'
15
17
16
18
export interface ZipMetadata {
17
19
rootDir : string
@@ -21,6 +23,7 @@ export interface ZipMetadata {
21
23
buildPayloadSizeInBytes : number
22
24
zipFileSizeInBytes : number
23
25
lines : number
26
+ language : CodewhispererLanguage | undefined
24
27
}
25
28
26
29
export const ZipConstants = {
@@ -38,6 +41,7 @@ export class ZipUtil {
38
41
protected _zipDir : string = ''
39
42
protected _totalLines : number = 0
40
43
protected _fetchedDirs : Set < string > = new Set < string > ( )
44
+ protected _language : CodewhispererLanguage | undefined
41
45
42
46
constructor ( ) { }
43
47
@@ -119,6 +123,7 @@ export class ZipUtil {
119
123
}
120
124
121
125
const files = await collectFiles ( [ projectPath ] , [ workspaceFolder ] )
126
+ const languageCount = new Map < CodewhispererLanguage , number > ( )
122
127
for ( const file of files ) {
123
128
const isFileOpenAndDirty = this . isFileOpenAndDirty ( file . fileUri )
124
129
const fileContent = isFileOpenAndDirty ? await this . getTextContent ( file . fileUri ) : file . fileContent
@@ -137,6 +142,13 @@ export class ZipUtil {
137
142
this . _pickedSourceFiles . add ( file . fileUri . fsPath )
138
143
this . _totalSize += fileSize
139
144
this . _totalLines += fileContent . split ( ZipConstants . newlineRegex ) . length
145
+
146
+ const language = runtimeLanguageContext . getLanguageFromFileExtension (
147
+ path . extname ( file . fileUri . fsPath ) . slice ( 1 )
148
+ )
149
+ if ( language ) {
150
+ languageCount . set ( language , ( languageCount . get ( language ) || 0 ) + 1 )
151
+ }
140
152
}
141
153
142
154
if ( isFileOpenAndDirty ) {
@@ -146,6 +158,10 @@ export class ZipUtil {
146
158
}
147
159
}
148
160
161
+ if ( languageCount . size === 0 ) {
162
+ throw new ToolkitError ( 'Project does not contain valid files to scan' )
163
+ }
164
+ this . _language = [ ...languageCount . entries ( ) ] . reduce ( ( a , b ) => ( b [ 1 ] > a [ 1 ] ? b : a ) ) [ 0 ]
149
165
const zipFilePath = this . getZipDirPath ( ) + CodeWhispererConstants . codeScanZipExt
150
166
zip . writeZip ( zipFilePath )
151
167
return zipFilePath
@@ -193,6 +209,7 @@ export class ZipUtil {
193
209
zipFileSizeInBytes : zipFileSize ,
194
210
buildPayloadSizeInBytes : this . _totalBuildSize ,
195
211
lines : this . _totalLines ,
212
+ language : this . _language ,
196
213
}
197
214
} catch ( error ) {
198
215
getLogger ( ) . error ( 'Zip error caused by:' , error )
0 commit comments