@@ -23,6 +23,7 @@ export interface ICycodeService {
2323 startAuth ( ) : Promise < void > ;
2424 startScan ( scanType : CliScanType , paths : string [ ] , onDemand : boolean ) : Promise < void > ;
2525 startScanForCurrentProject ( scanType : CliScanType ) : Promise < void > ;
26+ startAllScansForCurrentProject ( scanTypes : CliScanType [ ] ) : Promise < void > ;
2627 applyDetectionIgnore ( scanType : CliScanType , ignoreType : CliIgnoreType , value : string ) : Promise < void > ;
2728 getAiRemediation ( detectionId : string ) : Promise < AiRemediationResultData | null > ;
2829}
@@ -99,17 +100,22 @@ export class CycodeService implements ICycodeService {
99100 await this . startScan ( scanType , [ projectRoot ] , true ) ; // onDemand = true
100101 }
101102
102- public async startScan ( scanType : CliScanType , paths : string [ ] , onDemand = false ) {
103- const scanMethods = {
104- [ CliScanType . Secret ] : (
105- token : vscode . CancellationToken ,
106- ) => this . cliService . scanPathsSecrets ( paths , onDemand , token ) ,
107- [ CliScanType . Sca ] : ( token : vscode . CancellationToken ) => this . cliService . scanPathsSca ( paths , onDemand , token ) ,
108- [ CliScanType . Iac ] : ( token : vscode . CancellationToken ) => this . cliService . scanPathsIac ( paths , onDemand , token ) ,
109- [ CliScanType . Sast ] : ( token : vscode . CancellationToken ) => this . cliService . scanPathsSast ( paths , onDemand , token ) ,
103+ private getScanMethod (
104+ scanType : CliScanType ,
105+ paths : string [ ] ,
106+ onDemand : boolean ,
107+ ) : ( ( token : vscode . CancellationToken ) => Promise < void > ) | undefined {
108+ const scanMethods : Record < CliScanType , ( token : vscode . CancellationToken ) => Promise < void > > = {
109+ [ CliScanType . Secret ] : ( token ) => this . cliService . scanPathsSecrets ( paths , onDemand , token ) ,
110+ [ CliScanType . Sca ] : ( token ) => this . cliService . scanPathsSca ( paths , onDemand , token ) ,
111+ [ CliScanType . Iac ] : ( token ) => this . cliService . scanPathsIac ( paths , onDemand , token ) ,
112+ [ CliScanType . Sast ] : ( token ) => this . cliService . scanPathsSast ( paths , onDemand , token ) ,
110113 } ;
114+ return scanMethods [ scanType ] ;
115+ }
111116
112- const scanMethod = scanMethods [ scanType ] ;
117+ public async startScan ( scanType : CliScanType , paths : string [ ] , onDemand = false ) {
118+ const scanMethod = this . getScanMethod ( scanType , paths , onDemand ) ;
113119 if ( ! scanMethod ) {
114120 this . logger . error ( `Unknown scan type: ${ scanType } ` ) ;
115121 return ;
@@ -128,6 +134,37 @@ export class CycodeService implements ICycodeService {
128134 ) ;
129135 }
130136
137+ public async startAllScansForCurrentProject ( scanTypes : CliScanType [ ] ) {
138+ const projectRoot = this . cliService . getProjectRootDirectory ( ) ;
139+ if ( ! projectRoot ) {
140+ vscode . window . showErrorMessage (
141+ 'Cycode scans the project that is currently opened. Please open a project and try again' ,
142+ ) ;
143+ return ;
144+ }
145+
146+ await this . withProgressBar (
147+ 'Cycode is scanning files...' ,
148+ async ( cancellationToken : vscode . CancellationToken ) => {
149+ this . logger . debug ( `[RunAll] Start scanning paths: ${ projectRoot } ` ) ;
150+ statusBar . showScanningInProgress ( ) ;
151+ await Promise . all (
152+ scanTypes . map ( ( scanType ) => {
153+ const scanMethod = this . getScanMethod ( scanType , [ projectRoot ] , true ) ;
154+ if ( ! scanMethod ) {
155+ this . logger . error ( `Unknown scan type: ${ scanType } ` ) ;
156+ return Promise . resolve ( ) ;
157+ }
158+ return scanMethod ( cancellationToken ) ;
159+ } ) ,
160+ ) ;
161+ statusBar . showScanComplete ( ) ;
162+ this . logger . debug ( `[RunAll] Finish scanning paths: ${ projectRoot } ` ) ;
163+ } ,
164+ { cancellable : true , location : vscode . ProgressLocation . Notification } ,
165+ ) ;
166+ }
167+
131168 private async applyDetectionIgnoreInUi ( ignoreType : CliIgnoreType , value : string ) {
132169 if ( ignoreType !== CliIgnoreType . Value ) {
133170 return ;
0 commit comments