@@ -7,10 +7,12 @@ import DeepCodeFilesWatcher from "../watchers/DeepCodeFilesWatcher";
77import DeepCodeWorkspaceFoldersWatcher from "../watchers/WorkspaceFoldersWatcher" ;
88import DeepCodeEditorsWatcher from "../watchers/EditorsWatcher" ;
99import DeepCodeSettingsWatcher from "../watchers/DeepCodeSettingsWatcher" ;
10+ import { PendingTask , PendingTaskInterface } from "../../utils/pendingTask" ;
1011import { IDE_NAME , REFRESH_VIEW_DEBOUNCE_INTERVAL } from "../../constants/general" ;
1112import { setContext } from "../../utils/vscodeCommandsUtils" ;
1213import { DEEPCODE_VIEW_ANALYSIS } from "../../constants/views" ;
1314import { errorsLogs } from '../../messages/errorsServerLogMessages' ;
15+ import { pendingMocks } from 'nock/types' ;
1416
1517export default abstract class BaseDeepCodeModule implements DeepCode . BaseDeepCodeModuleInterface {
1618 currentWorkspacePath : string ;
@@ -29,8 +31,8 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
2931 refreshViewEmitter : vscode . EventEmitter < any > ;
3032 analysisStatus = '' ;
3133 analysisProgress = 0 ;
32- private progressBadgePromise : Promise < void > | undefined ;
33- private progressBadgeResolveFn : ( ( ) => void ) | undefined ;
34+ private initializedView : PendingTaskInterface ;
35+ private progressBadge : PendingTaskInterface | undefined ;
3436 private viewContext : { [ key : string ] : unknown } ;
3537
3638 // These attributes are used in tests
@@ -55,6 +57,7 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
5557 this . analysisStatus = '' ;
5658 this . analysisProgress = 0 ;
5759 this . viewContext = { } ;
60+ this . initializedView = new PendingTask ( ) ;
5861 }
5962
6063 get baseURL ( ) : string {
@@ -123,40 +126,39 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
123126 }
124127
125128 private getProgressBadgePromise ( ) : Promise < void > {
126- if ( this . progressBadgePromise === undefined ) {
127- // This should not be needed, but we resolve pending Promises
128- // before overwriting the progressBadgeResolveFn reference.
129- if ( this . progressBadgeResolveFn ) this . progressBadgeResolveFn ( ) ;
130- this . progressBadgePromise = new Promise (
131- ( resolve ) => {
132- this . progressBadgeResolveFn = resolve ;
133- }
134- ) ;
129+ if ( ! this . progressBadge || this . progressBadge . isCompleted ) {
130+ this . progressBadge = new PendingTask ( ) ;
135131 }
136- return this . progressBadgePromise ;
132+ return this . progressBadge . waiter ;
137133 }
138134
139135 // Leave viewId undefined to remove the badge from all views
140136 async setLoadingBadge ( value : boolean ) : Promise < void > {
141- if ( this . progressBadgeResolveFn ) this . progressBadgeResolveFn ( ) ;
142137 if ( value ) {
143138 // Using closure on this to allow partial binding in arbitrary positions
144139 const self = this ;
145- vscode . window . withProgress (
146- { location : { viewId : DEEPCODE_VIEW_ANALYSIS } } ,
147- ( ) => self . getProgressBadgePromise ( )
140+ this . initializedView . waiter . then (
141+ ( ) => vscode . window . withProgress (
142+ { location : { viewId : DEEPCODE_VIEW_ANALYSIS } } ,
143+ ( ) => self . getProgressBadgePromise ( )
144+ )
148145 ) . then (
149146 ( ) => { } ,
150147 ( error ) => self . processError ( error , {
151148 message : errorsLogs . loadingBadge ,
152149 } )
153150 ) ;
154151 } else {
155- this . progressBadgePromise = undefined ;
156- this . progressBadgeResolveFn = undefined ;
152+ if ( this . progressBadge && ! this . progressBadge . isCompleted ) {
153+ this . progressBadge . complete ( ) ;
154+ }
157155 }
158156 }
159157
158+ emitViewInitialized ( ) : void {
159+ if ( ! this . initializedView . isCompleted ) this . initializedView . complete ( ) ;
160+ }
161+
160162 // Avoid refreshing context/views too often:
161163 // https://github.com/Microsoft/vscode/issues/68424
162164 refreshViews = _ . debounce (
0 commit comments