1- import * as vscode from 'vscode'
2-
1+ import { ConfigurationWithAccessToken } from '../configuration'
32import { SourcegraphGraphQLAPIClient } from '../sourcegraph-api/graphql'
43
5- function getServerEndpointFromConfig ( config : vscode . WorkspaceConfiguration ) : string {
6- return config . get < string > ( 'cody.serverEndpoint' , '' )
7- }
8-
9- function getUseContextFromConfig ( config : vscode . WorkspaceConfiguration ) : string {
10- if ( ! config ) {
11- return ''
12- }
13- return config . get < string > ( 'cody.useContext' , '' )
14- }
15-
16- function getChatPredictionsFromConfig ( config : vscode . WorkspaceConfiguration ) : boolean {
17- if ( ! config ) {
18- return false
19- }
20- return config . get < boolean > ( 'cody.experimental.chatPredictions' , false )
21- }
22-
23- function getInlineFromConfig ( config : vscode . WorkspaceConfiguration ) : boolean {
24- if ( ! config ) {
25- return false
26- }
27- return config . get < boolean > ( 'cody.inlineChat.enabled' , false )
28- }
29-
30- function getNonStopFromConfig ( config : vscode . WorkspaceConfiguration ) : boolean {
31- if ( ! config ) {
32- return false
33- }
34- return config . get < boolean > ( 'cody.experimental.nonStop' , false )
35- }
36-
37- function getSuggestionsFromConfig ( config : vscode . WorkspaceConfiguration ) : boolean {
38- if ( ! config ) {
39- return false
40- }
41- return config . get < boolean > ( 'cody.experimental.suggestions' , false )
42- }
43-
44- function getGuardrailsFromConfig ( config : vscode . WorkspaceConfiguration ) : boolean {
45- if ( ! config ) {
46- return false
47- }
48- return config . get < boolean > ( 'cody.experimental.guardrails' , false )
4+ export interface ExtensionDetails {
5+ ide : 'VSCode' | 'JetBrains' | 'Neovim' | 'Emacs'
6+ ideExtensionType : 'Cody' | 'CodeSearch'
497}
508
519export class EventLogger {
52- private serverEndpoint = getServerEndpointFromConfig ( vscode . workspace . getConfiguration ( ) )
53- private extensionDetails = { ide : 'VSCode' , ideExtensionType : 'Cody' }
54- private constructor ( private gqlAPIClient : SourcegraphGraphQLAPIClient ) { }
55-
56- public static create ( gqlAPIClient : SourcegraphGraphQLAPIClient ) : EventLogger {
57- return new EventLogger ( gqlAPIClient )
58- }
10+ private gqlAPIClient : SourcegraphGraphQLAPIClient
5911
60- public configurationDetails = {
61- contextSelection : getUseContextFromConfig ( vscode . workspace . getConfiguration ( ) ) ,
62- chatPredictions : getChatPredictionsFromConfig ( vscode . workspace . getConfiguration ( ) ) ,
63- inline : getInlineFromConfig ( vscode . workspace . getConfiguration ( ) ) ,
64- nonStop : getNonStopFromConfig ( vscode . workspace . getConfiguration ( ) ) ,
65- suggestions : getSuggestionsFromConfig ( vscode . workspace . getConfiguration ( ) ) ,
66- guardrails : getGuardrailsFromConfig ( vscode . workspace . getConfiguration ( ) ) ,
12+ constructor (
13+ private serverEndpoint : string ,
14+ private extensionDetails : ExtensionDetails ,
15+ private config : ConfigurationWithAccessToken
16+ ) {
17+ this . gqlAPIClient = new SourcegraphGraphQLAPIClient ( this . config )
6718 }
6819
69- public onConfigurationChange ( newconfig : vscode . WorkspaceConfiguration ) : void {
70- this . configurationDetails = {
71- contextSelection : getUseContextFromConfig ( newconfig ) ,
72- chatPredictions : getChatPredictionsFromConfig ( newconfig ) ,
73- inline : getInlineFromConfig ( newconfig ) ,
74- nonStop : getNonStopFromConfig ( newconfig ) ,
75- suggestions : getSuggestionsFromConfig ( newconfig ) ,
76- guardrails : getGuardrailsFromConfig ( newconfig ) ,
77- }
20+ public onConfigurationChange (
21+ newServerEndpoint : string ,
22+ newExtensionDetails : ExtensionDetails ,
23+ newConfig : ConfigurationWithAccessToken
24+ ) : void {
25+ this . serverEndpoint = newServerEndpoint
26+ this . extensionDetails = newExtensionDetails
27+ this . config = newConfig
28+ this . gqlAPIClient . onConfigurationChange ( newConfig )
7829 }
7930
8031 /**
@@ -91,32 +42,37 @@ export class EventLogger {
9142 * @param publicProperties Public argument information.
9243 */
9344 public log ( eventName : string , anonymousUserID : string , eventProperties ?: any , publicProperties ?: any ) : void {
45+ const configurationDetails = {
46+ contextSelection : this . config . useContext ,
47+ chatPredictions : this . config . experimentalChatPredictions ,
48+ inline : this . config . inlineChat ,
49+ nonStop : this . config . experimentalNonStop ,
50+ guardrails : this . config . experimentalGuardrails ,
51+ }
9452 const argument = {
9553 ...eventProperties ,
9654 serverEndpoint : this . serverEndpoint ,
9755 extensionDetails : this . extensionDetails ,
98- configurationDetails : this . configurationDetails ,
56+ configurationDetails,
9957 }
10058 const publicArgument = {
10159 ...publicProperties ,
10260 serverEndpoint : this . serverEndpoint ,
10361 extensionDetails : this . extensionDetails ,
104- configurationDetails : this . configurationDetails ,
105- }
106- try {
107- this . gqlAPIClient
108- . logEvent ( {
109- event : eventName ,
110- userCookieID : anonymousUserID ,
111- source : 'IDEEXTENSION' ,
112- url : '' ,
113- argument : JSON . stringify ( argument ) ,
114- publicArgument : JSON . stringify ( publicArgument ) ,
115- } )
116- . then ( ( ) => { } )
117- . catch ( ( ) => { } )
118- } catch ( error ) {
119- console . log ( error )
62+ configurationDetails,
12063 }
64+ this . gqlAPIClient
65+ . logEvent ( {
66+ event : eventName ,
67+ userCookieID : anonymousUserID ,
68+ source : 'IDEEXTENSION' ,
69+ url : '' ,
70+ argument : JSON . stringify ( argument ) ,
71+ publicArgument : JSON . stringify ( publicArgument ) ,
72+ } )
73+ . then ( ( ) => { } )
74+ . catch ( error => {
75+ console . log ( error )
76+ } )
12177 }
12278}
0 commit comments