Skip to content

Commit

Permalink
Merge pull request #19633 from jasonmalinowski/support-local-serializ…
Browse files Browse the repository at this point in the history
…ation-of-longs

Support serializing longs to/from the local registry
  • Loading branch information
jasonmalinowski authored May 22, 2017
2 parents a53cec0 + ef8e7ba commit 7eba852
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal static class AnalyzerABTestOptions
nameof(LastDateTimeUsedSuggestionAction), defaultValue: DateTime.MinValue.ToBinary(),
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + nameof(LastDateTimeUsedSuggestionAction)));

public static readonly Option<uint> UsedSuggestedActionCount = new Option<uint>(nameof(AnalyzerABTestOptions), nameof(UsedSuggestedActionCount),
public static readonly Option<int> UsedSuggestedActionCount = new Option<int>(nameof(AnalyzerABTestOptions), nameof(UsedSuggestedActionCount),
defaultValue: 0, storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + nameof(UsedSuggestedActionCount)));

public static readonly Option<bool> NeverShowAgain = new Option<bool>(nameof(AnalyzerABTestOptions), nameof(NeverShowAgain),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

namespace Microsoft.VisualStudio.LanguageServices.Implementation.Experimentation
{
// Disabling until https://github.com/dotnet/roslyn/issues/19629 is fixed.
// [Export(typeof(ISuggestedActionCallback))]
[Export(typeof(ISuggestedActionCallback))]
internal class AnalyzerVsixSuggestedActionCallback : ForegroundThreadAffinitizedObject, ISuggestedActionCallback
{
private const string AnalyzerEnabledFlight = @"LiveCA/LiveCAcf";
Expand Down Expand Up @@ -52,7 +51,6 @@ public void OnSuggestedActionExecuted(SuggestedAction action)
// thread to get it
AssertIsForeground();


// If the user has previously clicked don't show again, then we bail out immediately
if (_workspace.Options.GetOption(AnalyzerABTestOptions.NeverShowAgain))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ bool IOptionPersister.TryFetch(OptionKey optionKey, out object value)
value = subKey.GetValue(key, defaultValue: (bool)optionKey.Option.DefaultValue ? 1 : 0).Equals(1);
return true;
}
else if (optionKey.Option.Type == typeof(long))
{
object untypedValue = subKey.GetValue(key, defaultValue: optionKey.Option.DefaultValue);

if (untypedValue is string stringValue)
{
// Due to a previous bug we were accidentally serializing longs as strings. Gracefully convert
// those back.
bool suceeded = long.TryParse(stringValue, out long longValue);
value = longValue;
return suceeded;
}
else if (untypedValue is long longValue)
{
value = longValue;
return true;
}

value = null;
return false;
}
else
{
// Otherwise we can just store normally
Expand Down Expand Up @@ -108,6 +129,11 @@ bool IOptionPersister.TryPersist(OptionKey optionKey, object value)
subKey.SetValue(key, (bool)value ? 1 : 0, RegistryValueKind.DWord);
return true;
}
else if (optionKey.Option.Type == typeof(long))
{
subKey.SetValue(key, value, RegistryValueKind.QWord);
return true;
}
else
{
subKey.SetValue(key, value);
Expand Down

0 comments on commit 7eba852

Please sign in to comment.