Skip to content

Commit

Permalink
Add event for when an option is changed (#8417)
Browse files Browse the repository at this point in the history
This will help us track usage
  • Loading branch information
ryzngard authored Mar 9, 2023
1 parent fcf7fdb commit 595bc7c
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.CodeAnalysis.Razor.Editor;
using Microsoft.VisualStudio.Editor.Razor;
using Microsoft.VisualStudio.LanguageServer.Client;
Expand All @@ -19,16 +22,18 @@ internal class OptionsStorage : IAdvancedSettingsStorage
{
private readonly WritableSettingsStore _writableSettingsStore;
private readonly ILanguageServiceBroker2 _languageServiceBroker;
private readonly ITelemetryReporter _telemetryReporter;
private const string Collection = "Razor";

[ImportingConstructor]
public OptionsStorage(SVsServiceProvider vsServiceProvider, ILanguageServiceBroker2 languageServiceBroker)
public OptionsStorage(SVsServiceProvider vsServiceProvider, ILanguageServiceBroker2 languageServiceBroker, ITelemetryReporter telemetryReporter)
{
var shellSettingsManager = new ShellSettingsManager(vsServiceProvider);
_writableSettingsStore = shellSettingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);

_writableSettingsStore.CreateCollection(Collection);
_languageServiceBroker = languageServiceBroker;
_telemetryReporter = telemetryReporter;
}

public event EventHandler<ClientAdvancedSettingsChangedEventArgs>? Changed;
Expand All @@ -47,6 +52,11 @@ public bool GetBool(string name, bool defaultValue)
public void SetBool(string name, bool value)
{
_writableSettingsStore.SetBoolean(Collection, name, value);
_telemetryReporter.ReportEvent("OptionChanged", Telemetry.TelemetrySeverity.Normal, new Dictionary<string, bool>()
{
{ name, value }
}.ToImmutableDictionary());

NotifyChange();
}

Expand Down

0 comments on commit 595bc7c

Please sign in to comment.