@@ -16,6 +16,7 @@ export class UiProvider implements vscode.WebviewViewProvider {
1616 private logger : LoggerService ;
1717 private _scanStartTime ?: number ;
1818 private _fetchStartTime ?: number ;
19+ private _scanInProgress : boolean = false ;
1920
2021 constructor ( private readonly _extensionContext : vscode . ExtensionContext ) {
2122 this . _githubService = new GitHubService ( ) ;
@@ -420,7 +421,26 @@ export class UiProvider implements vscode.WebviewViewProvider {
420421 }
421422
422423 private async runLocalScan ( ) {
424+ // Check if a scan is already in progress
425+ if ( this . _scanInProgress ) {
426+ this . logger . warn ( "UiProvider" , "Attempted to start a scan while one is already in progress" ) ;
427+
428+ // Send message to UI
429+ this . _view ?. webview . postMessage ( {
430+ command : "scanBlocked" ,
431+ success : false ,
432+ message : "A scan is already in progress. Please wait for it to complete." ,
433+ } ) ;
434+
435+ // Show error notification to the user
436+ vscode . window . showErrorMessage ( "CodeQL scan already in progress. Please wait for it to complete." ) ;
437+
438+ return ;
439+ }
440+
423441 try {
442+ // Set scan in progress flag
443+ this . _scanInProgress = true ;
424444 this . _scanStartTime = Date . now ( ) ;
425445
426446 this . _view ?. webview . postMessage ( {
@@ -455,10 +475,33 @@ export class UiProvider implements vscode.WebviewViewProvider {
455475 message : `CodeQL scan failed after ${ durationText } : ${ error } ` ,
456476 duration : scanDuration ,
457477 } ) ;
478+ } finally {
479+ // Reset scan in progress flag regardless of success or failure
480+ this . _scanInProgress = false ;
458481 }
459482 }
460483
461484 private async fetchRemoteAlerts ( ) {
485+ // Check if a scan is already in progress
486+ if ( this . _scanInProgress ) {
487+ this . logger . warn ( "UiProvider" , "Attempted to fetch alerts while a scan is in progress" ) ;
488+
489+ // Send message to UI
490+ this . _view ?. webview . postMessage ( {
491+ command : "fetchBlocked" ,
492+ success : false ,
493+ message : "A scan is currently in progress. Please wait for it to complete before fetching alerts." ,
494+ } ) ;
495+
496+ // Show error notification to the user
497+ vscode . window . showErrorMessage ( "Cannot fetch alerts: CodeQL scan is in progress. Please wait for it to complete." ) ;
498+
499+ return ;
500+ }
501+
502+ // Set scan in progress flag for the duration of the fetch
503+ this . _scanInProgress = true ;
504+
462505 try {
463506 this . _fetchStartTime = Date . now ( ) ;
464507
@@ -544,6 +587,9 @@ export class UiProvider implements vscode.WebviewViewProvider {
544587 message : `Failed to fetch remote alerts after ${ durationText } : ${ error } ` ,
545588 duration : fetchDuration ,
546589 } ) ;
590+ } finally {
591+ // Reset scan in progress flag regardless of success or failure
592+ this . _scanInProgress = false ;
547593 }
548594 }
549595
@@ -1856,7 +1902,6 @@ export class UiProvider implements vscode.WebviewViewProvider {
18561902 Last scan: <span id="scanDate" style="font-weight: 600;">Never</span>
18571903 </small>
18581904 </div>
1859- </div>
18601905
18611906 <div id="noResultsMessage" class="no-results">
18621907 <div style="font-size: 14px; margin-bottom: 4px;">🛡️</div>
0 commit comments