提交 9f9d09ed 编写于 作者: M Manish Vasani

Turn off full solution analysis by default for C#

上级 b37f5665
......@@ -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, False) _
.WithChangedOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, LanguageNames.VisualBasic, False))
.WithChangedOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, LanguageNames.CSharp, 0) _
.WithChangedOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, LanguageNames.VisualBasic, 0))
End If
Dim registrationService = workspace.Services.GetService(Of ISolutionCrawlerRegistrationService)()
......
......@@ -10,6 +10,7 @@ Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.CodeAnalysis.Shared.Options
Imports Microsoft.CodeAnalysis.Test.Utilities
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.UnitTests.Diagnostics
......@@ -1917,6 +1918,9 @@ class MyClass
</Workspace>
Using workspace = TestWorkspace.CreateWorkspace(test)
' set csharp closed diagnostic option on
workspace.Options = workspace.Options.WithChangedOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, LanguageNames.CSharp, 1)
Dim project = workspace.CurrentSolution.Projects.Single()
' Add analyzer
......
......@@ -143,7 +143,7 @@ private Task ClearOnlyDocumentStates(Document document)
private bool CheckOptions(Project project, bool forceAnalysis)
{
var workspace = project.Solution.Workspace;
if (workspace.Options.GetOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, project.Language) &&
if (ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(workspace, project.Language) &&
workspace.Options.GetOption(RuntimeOptions.FullSolutionAnalysis))
{
return true;
......
......@@ -8,11 +8,33 @@ internal static class ServiceFeatureOnOffOptions
{
public const string OptionName = "ServiceFeaturesOnOff";
private const bool CSharpClosedFileDiagnosticsEnabledByDefault = false;
private const bool DefaultClosedFileDiagnosticsEnabledByDefault = true;
/// <summary>
/// this option is solely for performance. don't confused by option name.
/// 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<bool> ClosedFileDiagnostic = new PerLanguageOption<bool>(OptionName, "Closed File Diagnostic", defaultValue: true);
public static readonly PerLanguageOption<int> ClosedFileDiagnostic = new PerLanguageOption<int>(OptionName, "Closed File Diagnostic", defaultValue: -1);
public static bool IsClosedFileDiagnosticsEnabled(Workspace workspace, string language)
{
var optionsService = workspace.Services.GetService<IOptionService>();
return optionsService != null && IsClosedFileDiagnosticsEnabled(optionsService, language);
}
public static bool IsClosedFileDiagnosticsEnabled(IOptionService optionService, string language)
{
var option = optionService.GetOption(ClosedFileDiagnostic, language);
if (option == ClosedFileDiagnostic.DefaultValue)
{
return language == LanguageNames.CSharp ?
CSharpClosedFileDiagnosticsEnabledByDefault :
DefaultClosedFileDiagnosticsEnabledByDefault;
}
return option != 0;
}
}
}
......@@ -36,10 +36,25 @@ public int BringUpOnIdentifier
set { SetBooleanOption(CompletionOptions.TriggerOnTypingLetters, value); }
}
// This SettingStore option has now been deprecated in favor of CSharpClosedFileDiagnostics.
public int ClosedFileDiagnostics
{
get { return GetBooleanOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic); }
set { SetBooleanOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, value); }
get { return GetIntegerOption(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);
}
}
}
public int CSharpClosedFileDiagnostics
{
get { return GetIntegerOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic); }
set { SetIntegerOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, value); }
}
public int DisplayLineSeparators
......@@ -520,5 +535,29 @@ private void SetBooleanOption(PerLanguageOption<bool> key, int value)
optionSet = optionSet.WithChangedOption(key, LanguageNames.CSharp, value != 0);
_optionService.SetOptions(optionSet);
}
private int GetIntegerOption(Option<int> key)
{
return _optionService.GetOption(key);
}
private int GetIntegerOption(PerLanguageOption<int> key)
{
return _optionService.GetOption(key, LanguageNames.CSharp);
}
private void SetIntegerOption(Option<int> key, int value)
{
var optionSet = _optionService.GetOptions();
optionSet = optionSet.WithChangedOption(key, value);
_optionService.SetOptions(optionSet);
}
private void SetIntegerOption(PerLanguageOption<int> key, int value)
{
var optionSet = _optionService.GetOptions();
optionSet = optionSet.WithChangedOption(key, LanguageNames.CSharp, value);
_optionService.SetOptions(optionSet);
}
}
}
......@@ -103,6 +103,18 @@ private bool ShouldIncludeOnOffOption(FieldInfo fieldInfo)
protected override string SettingStorageRoot { get { return "TextEditor.CSharp.Specific."; } }
protected override string GetStorageKeyForOption(IOption option)
{
var name = option.Name;
if (option == ServiceFeatureOnOffOptions.ClosedFileDiagnostic)
{
// ClosedFileDiagnostics has been deprecated in favor of CSharpClosedFileDiagnostics
name = nameof(AutomationObject.CSharpClosedFileDiagnostics);
}
return SettingStorageRoot + name;
}
protected override bool SupportsOption(IOption option, string languageName)
{
if (option == OrganizerOptions.PlaceSystemNamespaceFirst ||
......
......@@ -152,7 +152,7 @@ public void RemoveProject(ProjectId projectId)
private bool CheckOptions(Document document)
{
if (_workspace.Options.GetOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, document.Project.Language) &&
if (ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(_workspace, document.Project.Language) &&
_workspace.Options.GetOption(RuntimeOptions.FullSolutionAnalysis))
{
return true;
......
......@@ -11,7 +11,7 @@ internal class FullSolutionAnalysisOptionBinding
private readonly string _languageName;
private readonly Option<bool> _fullSolutionAnalysis;
private readonly PerLanguageOption<bool> _closedFileDiagnostics;
private readonly PerLanguageOption<int> _closedFileDiagnostics;
public FullSolutionAnalysisOptionBinding(IOptionService optionService, string languageName)
{
......@@ -26,7 +26,7 @@ public bool Value
{
get
{
return _optionService.GetOption(_closedFileDiagnostics, _languageName) &&
return ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(_optionService, _languageName) &&
_optionService.GetOption(_fullSolutionAnalysis);
}
......@@ -35,7 +35,7 @@ public bool Value
var oldOptions = _optionService.GetOptions();
// set normal option first
var newOptions = oldOptions.WithChangedOption(_closedFileDiagnostics, _languageName, value);
var newOptions = oldOptions.WithChangedOption(_closedFileDiagnostics, _languageName, value ? 1 : 0);
// we only enable this option if it is disabled. we never disable this option here.
if (value)
......
......@@ -44,12 +44,26 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options
End Set
End Property
' This SettingStore option has now been deprecated in favor of BasicClosedFileDiagnostics.
Public Property ClosedFileDiagnostics As Boolean
Get
Return GetBooleanOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic)
Return ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(_optionService, LanguageNames.VisualBasic)
End Get
Set(value As Boolean)
SetBooleanOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, value)
' 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)
End If
End Set
End Property
Public Property BasicClosedFileDiagnostics As Integer
Get
Return GetIntegerOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic)
End Get
Set(value As Integer)
SetIntegerOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, value)
End Set
End Property
......@@ -171,5 +185,25 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options
optionSet = optionSet.WithChangedOption(key, LanguageNames.VisualBasic, value)
_optionService.SetOptions(optionSet)
End Sub
Private Function GetIntegerOption(key As [Option](Of Integer)) As Integer
Return _optionService.GetOption(key)
End Function
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)
End Function
Private Sub SetIntegerOption(key As PerLanguageOption(Of Integer), value As Integer)
Dim optionSet = _optionService.GetOptions()
optionSet = optionSet.WithChangedOption(key, LanguageNames.VisualBasic, value)
_optionService.SetOptions(optionSet)
End Sub
End Class
End Namespace
......@@ -117,6 +117,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options
Return SettingStorageRoot + "AutoRequiredMemberInsert"
Case FeatureOnOffOptions.FormatOnPaste.Name
Return Nothing
Case ServiceFeatureOnOffOptions.ClosedFileDiagnostic.Name
' ClosedFileDiagnostics has been deprecated in favor of BasicClosedFileDiagnostics
Return SettingStorageRoot + NameOf(AutomationObject.BasicClosedFileDiagnostics)
End Select
End If
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册