55
66using System ;
77using System . Collections . Generic ;
8+ using System . IO ;
89using System . Threading ;
910using System . Threading . Tasks ;
11+ using MediatR ;
1012using Microsoft . Extensions . Logging ;
13+ using Microsoft . PowerShell . EditorServices . Logging ;
1114using Microsoft . PowerShell . EditorServices . Services ;
1215using Microsoft . PowerShell . EditorServices . Services . Configuration ;
13- using MediatR ;
16+ using Newtonsoft . Json . Linq ;
1417using OmniSharp . Extensions . LanguageServer . Protocol . Client . Capabilities ;
1518using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
19+ using OmniSharp . Extensions . LanguageServer . Protocol . Server ;
20+ using OmniSharp . Extensions . LanguageServer . Protocol . Window ;
1621using OmniSharp . Extensions . LanguageServer . Protocol . Workspace ;
17- using System . IO ;
1822
1923namespace Microsoft . PowerShell . EditorServices . Handlers
2024{
@@ -24,6 +28,7 @@ internal class PsesConfigurationHandler : IDidChangeConfigurationHandler
2428 private readonly WorkspaceService _workspaceService ;
2529 private readonly ConfigurationService _configurationService ;
2630 private readonly PowerShellContextService _powerShellContextService ;
31+ private readonly ILanguageServerFacade _languageServer ;
2732 private DidChangeConfigurationCapability _capability ;
2833 private bool _profilesLoaded ;
2934 private bool _consoleReplStarted ;
@@ -34,13 +39,14 @@ public PsesConfigurationHandler(
3439 WorkspaceService workspaceService ,
3540 AnalysisService analysisService ,
3641 ConfigurationService configurationService ,
37- PowerShellContextService powerShellContextService )
42+ PowerShellContextService powerShellContextService ,
43+ ILanguageServerFacade languageServer )
3844 {
3945 _logger = factory . CreateLogger < PsesConfigurationHandler > ( ) ;
4046 _workspaceService = workspaceService ;
4147 _configurationService = configurationService ;
4248 _powerShellContextService = powerShellContextService ;
43-
49+ _languageServer = languageServer ;
4450 ConfigurationUpdated += analysisService . OnConfigurationUpdated ;
4551 }
4652
@@ -57,6 +63,8 @@ public async Task<Unit> Handle(DidChangeConfigurationParams request, Cancellatio
5763 return await Unit . Task . ConfigureAwait ( false ) ;
5864 }
5965
66+ SendFeatureChangesTelemetry ( incomingSettings ) ;
67+
6068 bool oldLoadProfiles = _configurationService . CurrentSettings . EnableProfileLoading ;
6169 bool oldScriptAnalysisEnabled =
6270 _configurationService . CurrentSettings . ScriptAnalysis . Enable ?? false ;
@@ -141,6 +149,61 @@ await _powerShellContextService.SetWorkingDirectoryAsync(
141149 return await Unit . Task . ConfigureAwait ( false ) ;
142150 }
143151
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+
144207 public void SetCapability ( DidChangeConfigurationCapability capability )
145208 {
146209 _capability = capability ;
0 commit comments