@@ -10,9 +10,9 @@ import DeepCodeSettingsWatcher from "../watchers/DeepCodeSettingsWatcher";
1010import { PendingTask , PendingTaskInterface } from "../../utils/pendingTask" ;
1111import { IDE_NAME , REFRESH_VIEW_DEBOUNCE_INTERVAL } from "../../constants/general" ;
1212import { setContext } from "../../utils/vscodeCommandsUtils" ;
13- import { DEEPCODE_VIEW_ANALYSIS } from "../../constants/views" ;
13+ import { DEEPCODE_CONTEXT , DEEPCODE_VIEW_ANALYSIS } from "../../constants/views" ;
14+ import { TELEMETRY_EVENTS } from "../../constants/telemetry" ;
1415import { errorsLogs } from '../../messages/errorsServerLogMessages' ;
15- import { pendingMocks } from 'nock/types' ;
1616
1717export default abstract class BaseDeepCodeModule implements DeepCode . BaseDeepCodeModuleInterface {
1818 currentWorkspacePath : string ;
@@ -33,6 +33,7 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
3333 analysisProgress = 0 ;
3434 private initializedView : PendingTaskInterface ;
3535 private progressBadge : PendingTaskInterface | undefined ;
36+ private shouldShowProgressBadge = false ;
3637 private viewContext : { [ key : string ] : unknown } ;
3738
3839 // These attributes are used in tests
@@ -113,19 +114,73 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
113114
114115 async setContext ( key : string , value : unknown ) : Promise < void > {
115116 console . log ( "DeepCode context" , key , value ) ;
117+ const oldValue = this . viewContext [ key ] ;
116118 this . viewContext [ key ] = value ;
117119 await setContext ( key , value ) ;
118120 this . refreshViews ( ) ;
121+ this . trackContextChange ( key , value , oldValue ) ;
122+ }
123+
124+ private trackContextChange ( key : string , value : unknown , oldValue : unknown ) {
125+ let event = "" ;
126+ let shouldWaitForView = true ;
127+ let options : Record < string , any > | undefined ;
128+ switch ( key ) {
129+ case DEEPCODE_CONTEXT . LOGGEDIN : {
130+ if ( oldValue !== undefined ) {
131+ if ( ! value && oldValue ) event = TELEMETRY_EVENTS . viewLoginView ;
132+ if ( value && ! oldValue ) event = TELEMETRY_EVENTS . viewConsentView ;
133+ } else {
134+ // If key was un-initialized (i.e. at start), we still report it if new value is false
135+ if ( ! value ) event = TELEMETRY_EVENTS . viewLoginView ;
136+ }
137+ break ;
138+ }
139+ case DEEPCODE_CONTEXT . APPROVED : {
140+ if ( oldValue !== undefined ) {
141+ if ( ! value && oldValue ) event = TELEMETRY_EVENTS . viewConsentView ;
142+ if ( value && ! oldValue ) event = TELEMETRY_EVENTS . viewSuggestionView ;
143+ }
144+ break ;
145+ }
146+ case DEEPCODE_CONTEXT . ADVANCED : {
147+ if ( oldValue !== undefined ) {
148+ event = TELEMETRY_EVENTS . toggleAdvancedMode ;
149+ options = { data : { value } } ;
150+ shouldWaitForView = false ;
151+ }
152+ break ;
153+ }
154+ case DEEPCODE_CONTEXT . MODE : {
155+ event = TELEMETRY_EVENTS . changeExecutionMode ;
156+ options = { data : { value } } ;
157+ shouldWaitForView = false ;
158+ break ;
159+ }
160+ }
161+ // We want to fire the event only when the user actually sees the View
162+ if ( event ) {
163+ if ( shouldWaitForView ) this . initializedView . waiter . then (
164+ ( ) => this . processEvent ( event , options )
165+ ) ;
166+ else this . processEvent ( event , options ) ;
167+ }
119168 }
120169
121170 get shouldShowAnalysis ( ) : boolean {
122- return ! this . viewContext [ 'error' ] &&
123- [ 'loggedIn' , 'uploadApproved' , 'workspaceFound' ] . every (
124- ( c ) => ! ! this . viewContext [ c ]
125- ) ;
171+ return ! this . viewContext [
172+ DEEPCODE_CONTEXT . ERROR
173+ ] && [
174+ DEEPCODE_CONTEXT . LOGGEDIN ,
175+ DEEPCODE_CONTEXT . APPROVED ,
176+ DEEPCODE_CONTEXT . ANALYZING ,
177+ ] . every (
178+ ( c ) => ! ! this . viewContext [ c ]
179+ ) ;
126180 }
127181
128182 private getProgressBadgePromise ( ) : Promise < void > {
183+ if ( ! this . shouldShowProgressBadge ) return Promise . resolve ( ) ;
129184 if ( ! this . progressBadge || this . progressBadge . isCompleted ) {
130185 this . progressBadge = new PendingTask ( ) ;
131186 }
@@ -134,6 +189,7 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
134189
135190 // Leave viewId undefined to remove the badge from all views
136191 async setLoadingBadge ( value : boolean ) : Promise < void > {
192+ this . shouldShowProgressBadge = value ;
137193 if ( value ) {
138194 // Using closure on this to allow partial binding in arbitrary positions
139195 const self = this ;
@@ -172,5 +228,10 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
172228 options ?: { [ key : string ] : any }
173229 ) : Promise < void > ;
174230
231+ abstract processEvent (
232+ event : string ,
233+ options ?: { [ key : string ] : any }
234+ ) : Promise < void > ;
235+
175236 abstract startExtension ( ) : Promise < void > ;
176237}
0 commit comments