Skip to content

Commit

Permalink
Merge pull request #72891 from CyrusNajmabadi/diagnosticOption
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi authored Apr 5, 2024
2 parents 337b5bd + fd6043f commit 648471f
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public async Task ErrorTagGeneratedForErrorInSourceGeneratedDocument()
private static async Task<ImmutableArray<ITagSpan<InlineDiagnosticsTag>>> GetTagSpansAsync(string content)
{
using var workspace = EditorTestWorkspace.CreateCSharp(content, composition: SquiggleUtilities.WpfCompositionWithSolutionCrawler);
Assert.True(workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(
workspace.CurrentSolution.Options.WithChangedOption(new OptionKey(DiagnosticOptionsStorage.PullDiagnosticsFeatureFlag), false))));
return await GetTagSpansAsync(workspace);
}

Expand All @@ -50,8 +48,6 @@ private static async Task<ImmutableArray<ITagSpan<InlineDiagnosticsTag>>> GetTag
files: [],
sourceGeneratedFiles: new[] { content },
composition: SquiggleUtilities.WpfCompositionWithSolutionCrawler);
Assert.True(workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(
workspace.CurrentSolution.Options.WithChangedOption(new OptionKey(DiagnosticOptionsStorage.PullDiagnosticsFeatureFlag), false))));

return await GetTagSpansAsync(workspace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Remote;
using Microsoft.CodeAnalysis.Remote.Testing;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Text;
Expand All @@ -45,7 +42,6 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions
using OptionsCollectionAlias = CODESTYLE_UTILITIES::Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions.OptionsCollection;
#else
using OptionsCollectionAlias = OptionsCollection;
using Microsoft.CodeAnalysis.Editor.UnitTests.Extensions;
#endif

[UseExportProvider]
Expand Down Expand Up @@ -299,8 +295,6 @@ protected async Task TestMissingAsync(
var ps = parameters ?? TestParameters.Default;
using var workspace = CreateWorkspaceFromOptions(initialMarkup, ps);

workspace.GlobalOptions.SetGlobalOption(DiagnosticOptionsStorage.PullDiagnosticsFeatureFlag, false);

var (actions, _) = await GetCodeActionsAsync(workspace, ps);
var offeredActions = Environment.NewLine + string.Join(Environment.NewLine, actions.Select(action => action.Title));

Expand Down Expand Up @@ -493,8 +487,6 @@ private async Task TestAsync(

using (var workspace = CreateWorkspaceFromOptions(initialMarkup, parameters))
{
workspace.GlobalOptions.SetGlobalOption(DiagnosticOptionsStorage.PullDiagnosticsFeatureFlag, false);

// Ideally this check would always run, but there are several hundred tests that would need to be
// updated with {|Unnecessary:|} spans.
if (unnecessarySpans.Any())
Expand Down Expand Up @@ -707,8 +699,6 @@ private static async Task VerifyAgainstWorkspaceDefinitionAsync(string expectedT
{
using (var expectedWorkspace = TestWorkspace.Create(expectedText, composition: composition))
{
expectedWorkspace.GlobalOptions.SetGlobalOption(DiagnosticOptionsStorage.PullDiagnosticsFeatureFlag, false);

var expectedSolution = expectedWorkspace.CurrentSolution;
Assert.Equal(expectedSolution.Projects.Count(), newSolution.Projects.Count());
foreach (var project in newSolution.Projects)
Expand Down
2 changes: 0 additions & 2 deletions src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,6 @@ private static (EditorTestWorkspace workspace, DiagnosticAnalyzerService analyze
new CodeChangeProviderMetadata("Test", languages: LanguageNames.CSharp)));

var workspace = EditorTestWorkspace.CreateCSharp(code, composition: s_compositionWithMockDiagnosticUpdateSourceRegistrationService, openDocuments: true);
Assert.True(workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(
workspace.CurrentSolution.Options.WithChangedOption(new OptionKey(DiagnosticOptionsStorage.PullDiagnosticsFeatureFlag), false))));

if (additionalDocument != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,7 @@ public class DiagnosticAnalyzerServiceTests
private static readonly TestComposition s_editorFeaturesCompositionWithMockDiagnosticUpdateSourceRegistrationService = EditorTestCompositions.EditorFeatures;

private static AdhocWorkspace CreateWorkspace(Type[] additionalParts = null)
{
var workspace = new AdhocWorkspace(s_featuresCompositionWithMockDiagnosticUpdateSourceRegistrationService.AddParts(additionalParts).GetHostServices());

Assert.True(workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(
workspace.CurrentSolution.Options.WithChangedOption(new OptionKey(DiagnosticOptionsStorage.PullDiagnosticsFeatureFlag), false))));

return workspace;
}
=> new AdhocWorkspace(s_featuresCompositionWithMockDiagnosticUpdateSourceRegistrationService.AddParts(additionalParts).GetHostServices());

private static IGlobalOptionService GetGlobalOptions(Workspace workspace)
=> workspace.Services.SolutionServices.ExportProvider.GetExportedValue<IGlobalOptionService>();
Expand Down Expand Up @@ -427,8 +420,6 @@ private static async Task TestFullSolutionAnalysisForProjectAsync(AdhocWorkspace
internal async Task TestAdditionalFileAnalyzer(bool registerFromInitialize, bool testMultiple)
{
using var workspace = CreateWorkspace();
Assert.True(workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(
workspace.CurrentSolution.Options.WithChangedOption(new OptionKey(DiagnosticOptionsStorage.PullDiagnosticsFeatureFlag), false))));

var globalOptions = GetGlobalOptions(workspace);

Expand Down Expand Up @@ -513,8 +504,6 @@ internal async Task TestDiagnosticSuppressor(bool includeAnalyzer, bool includeS
var analyzerReference = new AnalyzerImageReference(analyzers.ToImmutableArray());

using var workspace = EditorTestWorkspace.CreateCSharp("class A {}", composition: s_editorFeaturesCompositionWithMockDiagnosticUpdateSourceRegistrationService.AddParts(typeof(TestDocumentTrackingService)));
Assert.True(workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(
workspace.CurrentSolution.Options.WithChangedOption(new OptionKey(DiagnosticOptionsStorage.PullDiagnosticsFeatureFlag), false))));

workspace.GlobalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.BackgroundAnalysisScopeOption, LanguageNames.CSharp, analysisScope);

Expand Down Expand Up @@ -625,8 +614,6 @@ void M()
typeof(TestDocumentTrackingService));

using var workspace = new EditorTestWorkspace(composition);
Assert.True(workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(
workspace.CurrentSolution.Options.WithChangedOption(new OptionKey(DiagnosticOptionsStorage.PullDiagnosticsFeatureFlag), false))));

workspace.GlobalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.BackgroundAnalysisScopeOption, LanguageNames.CSharp, analysisScope);
workspace.GlobalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.EnableDiagnosticsInSourceGeneratedFiles, isSourceGenerated);
Expand Down Expand Up @@ -870,8 +857,6 @@ void M()
internal async Task TestGeneratorProducedDiagnostics(bool fullSolutionAnalysis, bool analyzeProject, TestHost testHost)
{
using var workspace = EditorTestWorkspace.CreateCSharp("// This file will get a diagnostic", composition: s_featuresCompositionWithMockDiagnosticUpdateSourceRegistrationService.WithTestHostParts(testHost));
Assert.True(workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(
workspace.CurrentSolution.Options.WithChangedOption(new OptionKey(DiagnosticOptionsStorage.PullDiagnosticsFeatureFlag), false))));

var globalOptions = workspace.GetService<IGlobalOptionService>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ Imports System.Threading
Imports Microsoft.CodeAnalysis.CSharp
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.Editor.UnitTests
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.CodeAnalysis.SolutionCrawler
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.UnitTests
Expand Down Expand Up @@ -257,10 +255,6 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.Diagnostics.UnitTests

Private Shared Sub VerifyAllAvailableDiagnostics(test As XElement, diagnostics As XElement, Optional ordered As Boolean = True)
Using workspace = EditorTestWorkspace.CreateWorkspace(test, composition:=s_composition)

Assert.True(workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(
workspace.CurrentSolution.Options.WithChangedOption(New OptionKey(DiagnosticOptionsStorage.PullDiagnosticsFeatureFlag), False))))

' Ensure that diagnostic service computes diagnostics for all open files, not just the active file (default mode)
For Each language In workspace.Projects.Select(Function(p) p.Language).Distinct()
workspace.GlobalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.BackgroundAnalysisScopeOption, language, BackgroundAnalysisScope.OpenFiles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ namespace Microsoft.CodeAnalysis.Diagnostics;

internal sealed class DiagnosticOptionsStorage
{
public static readonly Option2<bool> PullDiagnosticsFeatureFlag = new(
"dotnet_enable_pull_diagnostics", defaultValue: true);

public static readonly Option2<bool> LogTelemetryForBackgroundAnalyzerExecution = new(
"dotnet_log_telemetry_for_background_analyzer_execution", defaultValue: false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,6 @@ public async Task TestDocumentDiagnosticsForOpenFilesIfDefaultAndFeatureFlagOn(b
var document = testLspServer.GetCurrentSolution().Projects.Single().Documents.Single();
await OpenDocumentAsync(testLspServer, document);

testLspServer.TestWorkspace.GlobalOptions.SetGlobalOption(DiagnosticOptionsStorage.PullDiagnosticsFeatureFlag, true);

var results = await RunGetDocumentPullDiagnosticsAsync(testLspServer, document.GetURI(), useVSDiagnostics);
Assert.Equal("CS1513", results.Single().Diagnostics.Single().Code);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ public bool TryFetch(LocalUserRegistryOptionPersister persister, OptionKey2 opti
{"dotnet_provide_date_and_time_completions", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.ProvideDateAndTimeCompletions")},
{"dotnet_log_telemetry_for_background_analyzer_execution", new FeatureFlagStorage(@"Roslyn.LogTelemetryForBackgroundAnalyzerExecution")},
{"dotnet_lightbulb_skip_executing_deprioritized_analyzers", new FeatureFlagStorage(@"Roslyn.LightbulbSkipExecutingDeprioritizedAnalyzers")},
// Do not change Lsp.PullDiagnostics. It is a shared feature flag between us and CPS.
{"dotnet_enable_pull_diagnostics", new FeatureFlagStorage(@"Lsp.PullDiagnostics")},
#pragma warning disable CS0612 // Type or member is obsolete
{"dotnet_auto_xml_doc_comment_generation", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.Automatic XML Doc Comment Generation", "TextEditor.VisualBasic.Specific.AutoComment")},
#pragma warning restore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public async Task ResetGlobalOptionsAsync(CancellationToken cancellationToken)
configurationService.Clear();

var globalOptions = await GetComponentModelServiceAsync<IGlobalOptionService>(cancellationToken);
ResetOption(globalOptions, DiagnosticOptionsStorage.PullDiagnosticsFeatureFlag);
ResetOption(globalOptions, CSharpCodeStyleOptions.NamespaceDeclarations);
ResetOption(globalOptions, InheritanceMarginOptionsStorage.InheritanceMarginCombinedWithIndicatorMargin);
ResetOption(globalOptions, InlineRenameSessionOptionsStorage.PreviewChanges);
Expand Down

0 comments on commit 648471f

Please sign in to comment.