5
5
6
6
using System ;
7
7
using System . Collections . Generic ;
8
+ using System . IO ;
8
9
using System . Threading ;
9
10
using System . Threading . Tasks ;
11
+ using MediatR ;
10
12
using Microsoft . Extensions . Logging ;
13
+ using Microsoft . PowerShell . EditorServices . Logging ;
11
14
using Microsoft . PowerShell . EditorServices . Services ;
12
15
using Microsoft . PowerShell . EditorServices . Services . Configuration ;
13
- using MediatR ;
16
+ using Newtonsoft . Json . Linq ;
14
17
using OmniSharp . Extensions . LanguageServer . Protocol . Client . Capabilities ;
15
18
using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
19
+ using OmniSharp . Extensions . LanguageServer . Protocol . Server ;
20
+ using OmniSharp . Extensions . LanguageServer . Protocol . Window ;
16
21
using OmniSharp . Extensions . LanguageServer . Protocol . Workspace ;
17
- using System . IO ;
18
22
19
23
namespace Microsoft . PowerShell . EditorServices . Handlers
20
24
{
@@ -24,6 +28,7 @@ internal class PsesConfigurationHandler : IDidChangeConfigurationHandler
24
28
private readonly WorkspaceService _workspaceService ;
25
29
private readonly ConfigurationService _configurationService ;
26
30
private readonly PowerShellContextService _powerShellContextService ;
31
+ private readonly ILanguageServerFacade _languageServer ;
27
32
private DidChangeConfigurationCapability _capability ;
28
33
private bool _profilesLoaded ;
29
34
private bool _consoleReplStarted ;
@@ -34,13 +39,14 @@ public PsesConfigurationHandler(
34
39
WorkspaceService workspaceService ,
35
40
AnalysisService analysisService ,
36
41
ConfigurationService configurationService ,
37
- PowerShellContextService powerShellContextService )
42
+ PowerShellContextService powerShellContextService ,
43
+ ILanguageServerFacade languageServer )
38
44
{
39
45
_logger = factory . CreateLogger < PsesConfigurationHandler > ( ) ;
40
46
_workspaceService = workspaceService ;
41
47
_configurationService = configurationService ;
42
48
_powerShellContextService = powerShellContextService ;
43
-
49
+ _languageServer = languageServer ;
44
50
ConfigurationUpdated += analysisService . OnConfigurationUpdated ;
45
51
}
46
52
@@ -57,6 +63,8 @@ public async Task<Unit> Handle(DidChangeConfigurationParams request, Cancellatio
57
63
return await Unit . Task . ConfigureAwait ( false ) ;
58
64
}
59
65
66
+ SendFeatureChangesTelemetry ( incomingSettings ) ;
67
+
60
68
bool oldLoadProfiles = _configurationService . CurrentSettings . EnableProfileLoading ;
61
69
bool oldScriptAnalysisEnabled =
62
70
_configurationService . CurrentSettings . ScriptAnalysis . Enable ?? false ;
@@ -141,6 +149,61 @@ await _powerShellContextService.SetWorkingDirectoryAsync(
141
149
return await Unit . Task . ConfigureAwait ( false ) ;
142
150
}
143
151
152
+ private void SendFeatureChangesTelemetry ( LanguageServerSettingsWrapper incomingSettings )
153
+ {
154
+ var configChanges = new Dictionary < string , bool > ( ) ;
155
+ // Send telemetry if the user opted-out of ScriptAnalysis
156
+ if ( incomingSettings . Powershell . ScriptAnalysis . Enable == false &&
157
+ _configurationService . CurrentSettings . ScriptAnalysis . Enable != incomingSettings . Powershell . ScriptAnalysis . Enable )
158
+ {
159
+ configChanges [ "ScriptAnalysis" ] = incomingSettings . Powershell . ScriptAnalysis . Enable ?? false ;
160
+ }
161
+
162
+ // Send telemetry if the user opted-out of CodeFolding
163
+ if ( ! incomingSettings . Powershell . CodeFolding . Enable &&
164
+ _configurationService . CurrentSettings . CodeFolding . Enable != incomingSettings . Powershell . CodeFolding . Enable )
165
+ {
166
+ configChanges [ "CodeFolding" ] = incomingSettings . Powershell . CodeFolding . Enable ;
167
+ }
168
+
169
+ // Send telemetry if the user opted-out of the prompt to update PackageManagement
170
+ if ( ! incomingSettings . Powershell . PromptToUpdatePackageManagement &&
171
+ _configurationService . CurrentSettings . PromptToUpdatePackageManagement != incomingSettings . Powershell . PromptToUpdatePackageManagement )
172
+ {
173
+ configChanges [ "PromptToUpdatePackageManagement" ] = incomingSettings . Powershell . PromptToUpdatePackageManagement ;
174
+ }
175
+
176
+ // Send telemetry if the user opted-out of Profile loading
177
+ if ( ! incomingSettings . Powershell . EnableProfileLoading &&
178
+ _configurationService . CurrentSettings . EnableProfileLoading != incomingSettings . Powershell . EnableProfileLoading )
179
+ {
180
+ configChanges [ "ProfileLoading" ] = incomingSettings . Powershell . EnableProfileLoading ;
181
+ }
182
+
183
+ // Send telemetry if the user opted-in to Pester 5+ CodeLens
184
+ if ( ! incomingSettings . Powershell . Pester . UseLegacyCodeLens &&
185
+ _configurationService . CurrentSettings . Pester . UseLegacyCodeLens != incomingSettings . Powershell . Pester . UseLegacyCodeLens )
186
+ {
187
+ // From our perspective we want to see how many people are opting in to this so we flip the value
188
+ configChanges [ "Pester5CodeLens" ] = ! incomingSettings . Powershell . Pester . UseLegacyCodeLens ;
189
+ }
190
+
191
+ // No need to send any telemetry since nothing changed
192
+ if ( configChanges . Count == 0 )
193
+ {
194
+ return ;
195
+ }
196
+
197
+ _languageServer . Window . SendTelemetryEvent ( new TelemetryEventParams
198
+ {
199
+ Data = new PsesTelemetryEvent
200
+ {
201
+ EventName = "NonDefaultPsesFeatureConfiguration" ,
202
+ Data = JObject . FromObject ( configChanges )
203
+ }
204
+ } ) ;
205
+ }
206
+
144
207
public void SetCapability ( DidChangeConfigurationCapability capability )
145
208
{
146
209
_capability = capability ;
0 commit comments