@@ -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' ;
1616import { IServiceAI , ServiceAI } from '@deepcode/tsc' ;
1717
1818export default abstract class BaseDeepCodeModule implements DeepCode . BaseDeepCodeModuleInterface {
@@ -34,6 +34,7 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
3434 analysisProgress = 0 ;
3535 private initializedView : PendingTaskInterface ;
3636 private progressBadge : PendingTaskInterface | undefined ;
37+ private shouldShowProgressBadge = false ;
3738 private viewContext : { [ key : string ] : unknown } ;
3839
3940 // These attributes are used in tests
@@ -114,19 +115,73 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
114115
115116 async setContext ( key : string , value : unknown ) : Promise < void > {
116117 console . log ( "DeepCode context" , key , value ) ;
118+ const oldValue = this . viewContext [ key ] ;
117119 this . viewContext [ key ] = value ;
118120 await setContext ( key , value ) ;
119121 this . refreshViews ( ) ;
122+ this . trackContextChange ( key , value , oldValue ) ;
123+ }
124+
125+ private trackContextChange ( key : string , value : unknown , oldValue : unknown ) {
126+ let event = "" ;
127+ let shouldWaitForView = true ;
128+ let options : Record < string , any > | undefined ;
129+ switch ( key ) {
130+ case DEEPCODE_CONTEXT . LOGGEDIN : {
131+ if ( oldValue !== undefined ) {
132+ if ( ! value && oldValue ) event = TELEMETRY_EVENTS . viewLoginView ;
133+ if ( value && ! oldValue ) event = TELEMETRY_EVENTS . viewConsentView ;
134+ } else {
135+ // If key was un-initialized (i.e. at start), we still report it if new value is false
136+ if ( ! value ) event = TELEMETRY_EVENTS . viewLoginView ;
137+ }
138+ break ;
139+ }
140+ case DEEPCODE_CONTEXT . APPROVED : {
141+ if ( oldValue !== undefined ) {
142+ if ( ! value && oldValue ) event = TELEMETRY_EVENTS . viewConsentView ;
143+ if ( value && ! oldValue ) event = TELEMETRY_EVENTS . viewSuggestionView ;
144+ }
145+ break ;
146+ }
147+ case DEEPCODE_CONTEXT . ADVANCED : {
148+ if ( oldValue !== undefined ) {
149+ event = TELEMETRY_EVENTS . toggleAdvancedMode ;
150+ options = { data : { value } } ;
151+ shouldWaitForView = false ;
152+ }
153+ break ;
154+ }
155+ case DEEPCODE_CONTEXT . MODE : {
156+ event = TELEMETRY_EVENTS . changeExecutionMode ;
157+ options = { data : { value } } ;
158+ shouldWaitForView = false ;
159+ break ;
160+ }
161+ }
162+ // We want to fire the event only when the user actually sees the View
163+ if ( event ) {
164+ if ( shouldWaitForView ) this . initializedView . waiter . then (
165+ ( ) => this . processEvent ( event , options )
166+ ) ;
167+ else this . processEvent ( event , options ) ;
168+ }
120169 }
121170
122171 get shouldShowAnalysis ( ) : boolean {
123- return ! this . viewContext [ 'error' ] &&
124- [ 'loggedIn' , 'uploadApproved' , 'workspaceFound' ] . every (
125- ( c ) => ! ! this . viewContext [ c ]
126- ) ;
172+ return ! this . viewContext [
173+ DEEPCODE_CONTEXT . ERROR
174+ ] && [
175+ DEEPCODE_CONTEXT . LOGGEDIN ,
176+ DEEPCODE_CONTEXT . APPROVED ,
177+ DEEPCODE_CONTEXT . ANALYZING ,
178+ ] . every (
179+ ( c ) => ! ! this . viewContext [ c ]
180+ ) ;
127181 }
128182
129183 private getProgressBadgePromise ( ) : Promise < void > {
184+ if ( ! this . shouldShowProgressBadge ) return Promise . resolve ( ) ;
130185 if ( ! this . progressBadge || this . progressBadge . isCompleted ) {
131186 this . progressBadge = new PendingTask ( ) ;
132187 }
@@ -135,6 +190,7 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
135190
136191 // Leave viewId undefined to remove the badge from all views
137192 async setLoadingBadge ( value : boolean ) : Promise < void > {
193+ this . shouldShowProgressBadge = value ;
138194 if ( value ) {
139195 // Using closure on this to allow partial binding in arbitrary positions
140196 const self = this ;
@@ -173,5 +229,10 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
173229 options ?: { [ key : string ] : any }
174230 ) : Promise < void > ;
175231
232+ abstract processEvent (
233+ event : string ,
234+ options ?: { [ key : string ] : any }
235+ ) : Promise < void > ;
236+
176237 abstract startExtension ( ) : Promise < void > ;
177238}
0 commit comments