提交 66e96e01 编写于 作者: M Manish Vasani

Address PR feedback from Jason: Move the option to use nullable bool instead of integer

上级 5c4ab77d
......@@ -280,8 +280,8 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.Diagnostics.UnitTests
Dim optionService = workspace.Services.GetService(Of IOptionService)()
optionService.SetOptions(
optionService.GetOptions().WithChangedOption(ServiceComponentOnOffOptions.DiagnosticProvider, False) _
.WithChangedOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, LanguageNames.CSharp, 0) _
.WithChangedOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, LanguageNames.VisualBasic, 0))
.WithChangedOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, LanguageNames.CSharp, False) _
.WithChangedOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, LanguageNames.VisualBasic, False))
End If
Dim registrationService = workspace.Services.GetService(Of ISolutionCrawlerRegistrationService)()
......
......@@ -1916,8 +1916,7 @@ class MyClass
</Workspace>
Using workspace = TestWorkspace.CreateWorkspace(test)
' set csharp closed diagnostic option on
workspace.Options = workspace.Options.WithChangedOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, LanguageNames.CSharp, 1)
workspace.Options = workspace.Options.WithChangedOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, LanguageNames.CSharp, True)
Dim project = workspace.CurrentSolution.Projects.Single()
......
......@@ -16,7 +16,7 @@ internal static class ServiceFeatureOnOffOptions
/// this option doesn't mean we will show all diagnostics that belong to opened files when turned off,
/// rather it means we will only show diagnostics that are cheap to calculate for small scope such as opened files.
/// </summary>
public static readonly PerLanguageOption<int> ClosedFileDiagnostic = new PerLanguageOption<int>(OptionName, "Closed File Diagnostic", defaultValue: -1);
public static readonly PerLanguageOption<bool?> ClosedFileDiagnostic = new PerLanguageOption<bool?>(OptionName, "Closed File Diagnostic", defaultValue: null);
public static bool IsClosedFileDiagnosticsEnabled(Workspace workspace, string language)
{
......@@ -27,14 +27,14 @@ public static bool IsClosedFileDiagnosticsEnabled(Workspace workspace, string la
public static bool IsClosedFileDiagnosticsEnabled(IOptionService optionService, string language)
{
var option = optionService.GetOption(ClosedFileDiagnostic, language);
if (option == ClosedFileDiagnostic.DefaultValue)
if (!option.HasValue)
{
return language == LanguageNames.CSharp ?
CSharpClosedFileDiagnosticsEnabledByDefault :
DefaultClosedFileDiagnosticsEnabledByDefault;
}
return option != 0;
return option.Value;
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Completion;
......@@ -36,25 +37,25 @@ public int BringUpOnIdentifier
set { SetBooleanOption(CompletionOptions.TriggerOnTypingLetters, value); }
}
// This SettingStore option has now been deprecated in favor of CSharpClosedFileDiagnostics.
[Obsolete("This SettingStore option has now been deprecated in favor of CSharpClosedFileDiagnostics")]
public int ClosedFileDiagnostics
{
get { return GetIntegerOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic); }
get { return GetBooleanOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic); }
set
{
// Even though this option has been deprecated, we want to respect the setting if the user has explicitly turned off closed file diagnostics (which is the non-default value for 'ClosedFileDiagnostics').
// So, we invoke the setter only for value = 0.
if (value == 0)
{
SetIntegerOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, value);
SetBooleanOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, value);
}
}
}
public int CSharpClosedFileDiagnostics
{
get { return GetIntegerOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic); }
set { SetIntegerOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, value); }
get { return GetBooleanOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic); }
set { SetBooleanOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, value); }
}
public int DisplayLineSeparators
......@@ -536,27 +537,22 @@ private void SetBooleanOption(PerLanguageOption<bool> key, int value)
_optionService.SetOptions(optionSet);
}
private int GetIntegerOption(Option<int> key)
private int GetBooleanOption(PerLanguageOption<bool?> key)
{
return _optionService.GetOption(key);
}
private int GetIntegerOption(PerLanguageOption<int> key)
{
return _optionService.GetOption(key, LanguageNames.CSharp);
}
var option = _optionService.GetOption(key, LanguageNames.CSharp);
if (!option.HasValue)
{
return -1;
}
private void SetIntegerOption(Option<int> key, int value)
{
var optionSet = _optionService.GetOptions();
optionSet = optionSet.WithChangedOption(key, value);
_optionService.SetOptions(optionSet);
return option.Value ? 1 : 0;
}
private void SetIntegerOption(PerLanguageOption<int> key, int value)
private void SetBooleanOption(PerLanguageOption<bool?> key, int value)
{
bool? boolValue = (value < 0) ? (bool?)null : (value > 0);
var optionSet = _optionService.GetOptions();
optionSet = optionSet.WithChangedOption(key, LanguageNames.CSharp, value);
optionSet = optionSet.WithChangedOption(key, LanguageNames.CSharp, boolValue);
_optionService.SetOptions(optionSet);
}
}
......
......@@ -108,7 +108,9 @@ protected override string GetStorageKeyForOption(IOption option)
var name = option.Name;
if (option == ServiceFeatureOnOffOptions.ClosedFileDiagnostic)
{
// ClosedFileDiagnostics has been deprecated in favor of CSharpClosedFileDiagnostics
// ClosedFileDiagnostics has been deprecated in favor of CSharpClosedFileDiagnostics.
// ClosedFileDiagnostics had a default value of 'true', while CSharpClosedFileDiagnostics has a default value of 'false'.
// We want to ensure that we don't fetch the setting store value for the old flag, as that can cause the default value for this option to change.
name = nameof(AutomationObject.CSharpClosedFileDiagnostics);
}
......
......@@ -11,7 +11,7 @@ internal class FullSolutionAnalysisOptionBinding
private readonly string _languageName;
private readonly Option<bool> _fullSolutionAnalysis;
private readonly PerLanguageOption<int> _closedFileDiagnostics;
private readonly PerLanguageOption<bool?> _closedFileDiagnostics;
public FullSolutionAnalysisOptionBinding(IOptionService optionService, string languageName)
{
......@@ -35,7 +35,7 @@ public bool Value
var oldOptions = _optionService.GetOptions();
// set normal option first
var newOptions = oldOptions.WithChangedOption(_closedFileDiagnostics, _languageName, value ? 1 : 0);
var newOptions = oldOptions.WithChangedOption(_closedFileDiagnostics, _languageName, value);
// we only enable this option if it is disabled. we never disable this option here.
if (value)
......
......@@ -44,7 +44,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options
End Set
End Property
' This SettingStore option has now been deprecated in favor of BasicClosedFileDiagnostics.
<Obsolete("This SettingStore option has now been deprecated in favor of BasicClosedFileDiagnostics")>
Public Property ClosedFileDiagnostics As Boolean
Get
Return ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(_optionService, LanguageNames.VisualBasic)
......@@ -53,17 +53,17 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options
' Even though this option has been deprecated, we want to respect the setting if the user has explicitly turned off closed file diagnostics (which is the non-default value for 'ClosedFileDiagnostics').
' So, we invoke the setter only for value = False.
If Not value Then
SetIntegerOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, value:=0)
SetBooleanOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, value:=0)
End If
End Set
End Property
Public Property BasicClosedFileDiagnostics As Integer
Get
Return GetIntegerOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic)
Return GetBooleanOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic)
End Get
Set(value As Integer)
SetIntegerOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, value)
SetBooleanOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, value)
End Set
End Property
......@@ -186,23 +186,19 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options
_optionService.SetOptions(optionSet)
End Sub
Private Function GetIntegerOption(key As [Option](Of Integer)) As Integer
Return _optionService.GetOption(key)
End Function
Private Function GetBooleanOption(key As PerLanguageOption(Of Boolean?)) As Integer
Dim [option] = _optionService.GetOption(key, LanguageNames.VisualBasic)
If Not [option].HasValue Then
Return -1
End If
Private Sub SetIntegerOption(key As [Option](Of Integer), value As Integer)
Dim optionSet = _optionService.GetOptions()
optionSet = optionSet.WithChangedOption(key, value)
_optionService.SetOptions(optionSet)
End Sub
Private Function GetIntegerOption(key As PerLanguageOption(Of Integer)) As Integer
Return _optionService.GetOption(key, LanguageNames.VisualBasic)
Return If([option].Value, 1, 0)
End Function
Private Sub SetIntegerOption(key As PerLanguageOption(Of Integer), value As Integer)
Private Sub SetBooleanOption(key As PerLanguageOption(Of Boolean?), value As Integer)
Dim boolValue As Boolean? = If(value < 0, Nothing, value > 0)
Dim optionSet = _optionService.GetOptions()
optionSet = optionSet.WithChangedOption(key, LanguageNames.VisualBasic, value)
optionSet = optionSet.WithChangedOption(key, LanguageNames.VisualBasic, boolValue)
_optionService.SetOptions(optionSet)
End Sub
End Class
......
......@@ -118,9 +118,6 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options
Case FeatureOnOffOptions.FormatOnPaste.Name
Return Nothing
End Select
ElseIf key.Feature = ServiceFeatureOnOffOptions.OptionName Then
' ClosedFileDiagnostics has been deprecated in favor of BasicClosedFileDiagnostics
Return SettingStorageRoot + NameOf(AutomationObject.BasicClosedFileDiagnostics)
End If
Return MyBase.GetStorageKeyForOption(key)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册