Skip to content

Commit 0833b6d

Browse files
Remove feature options entirely (#77806)
2 parents 3db308f + 75639d2 commit 0833b6d

32 files changed

+89
-438
lines changed

src/EditorFeatures/Test/Diagnostics/DiagnosticAnalyzerServiceTests.cs

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,12 @@ public async Task TestDisabledByDefaultAnalyzerEnabledWithEditorConfig(bool enab
162162

163163
if (enabledWithEditorconfig)
164164
{
165-
var editorconfigText = @$"
166-
[*.cs]
167-
dotnet_diagnostic.{DisabledByDefaultAnalyzer.s_syntaxRule.Id}.severity = warning
168-
dotnet_diagnostic.{DisabledByDefaultAnalyzer.s_semanticRule.Id}.severity = warning
169-
dotnet_diagnostic.{DisabledByDefaultAnalyzer.s_compilationRule.Id}.severity = warning";
165+
var editorconfigText = $"""
166+
[*.cs]
167+
dotnet_diagnostic.{DisabledByDefaultAnalyzer.s_syntaxRule.Id}.severity = warning
168+
dotnet_diagnostic.{DisabledByDefaultAnalyzer.s_semanticRule.Id}.severity = warning
169+
dotnet_diagnostic.{DisabledByDefaultAnalyzer.s_compilationRule.Id}.severity = warning
170+
""";
170171

171172
project = project.AddAnalyzerConfigDocument(".editorconfig", filePath: "z:\\.editorconfig", text: SourceText.From(editorconfigText)).Project;
172173
}
@@ -345,10 +346,10 @@ public async Task TestFullSolutionAnalysisForHiddenAnalyzers_SeverityInAnalyzerC
345346

346347
// Escalating the analyzer to non-hidden effective severity through analyzer config options
347348
// ensures that analyzer executes in full solution analysis.
348-
var analyzerConfigText = $@"
349-
[*.cs]
350-
dotnet_diagnostic.{NamedTypeAnalyzer.DiagnosticId}.severity = warning
351-
";
349+
var analyzerConfigText = $"""
350+
[*.cs]
351+
dotnet_diagnostic.{NamedTypeAnalyzer.DiagnosticId}.severity = warning
352+
""";
352353

353354
project = project.AddAnalyzerConfigDocument(
354355
".editorconfig",
@@ -554,36 +555,36 @@ internal async Task TestRemoveUnnecessaryInlineSuppressionsAnalyzer(BackgroundAn
554555
string code;
555556
if (testPragma)
556557
{
557-
code = $@"
558-
#pragma warning disable {NamedTypeAnalyzer.DiagnosticId} // Unnecessary
559-
#pragma warning disable CS0168 // Variable is declared but never used - Unnecessary
560-
561-
#pragma warning disable {NamedTypeAnalyzer.DiagnosticId} // Necessary
562-
class A
563-
{{
564-
void M()
565-
{{
566-
#pragma warning disable CS0168 // Variable is declared but never used - Necessary
567-
int x;
568-
}}
569-
}}
570-
";
558+
code = $$"""
559+
#pragma warning disable {{NamedTypeAnalyzer.DiagnosticId}} // Unnecessary
560+
#pragma warning disable CS0168 // Variable is declared but never used - Unnecessary
561+
562+
#pragma warning disable {{NamedTypeAnalyzer.DiagnosticId}} // Necessary
563+
class A
564+
{
565+
void M()
566+
{
567+
#pragma warning disable CS0168 // Variable is declared but never used - Necessary
568+
int x;
569+
}
570+
}
571+
""";
571572
}
572573
else
573574
{
574-
code = $@"
575-
[System.Diagnostics.CodeAnalysis.SuppressMessage(""Category1"", ""{NamedTypeAnalyzer.DiagnosticId}"")] // Necessary
576-
class A
577-
{{
578-
[System.Diagnostics.CodeAnalysis.SuppressMessage(""Category2"", ""{NamedTypeAnalyzer.DiagnosticId}"")] // Unnecessary
579-
[System.Diagnostics.CodeAnalysis.SuppressMessage(""Category3"", ""CS0168"")] // Unnecessary
580-
void M()
581-
{{
582-
#pragma warning disable CS0168 // Variable is declared but never used - Necessary
583-
int x;
584-
}}
585-
}}
586-
";
575+
code = $$"""
576+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Category1", "{{NamedTypeAnalyzer.DiagnosticId}}")] // Necessary
577+
class A
578+
{
579+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Category2", "{{NamedTypeAnalyzer.DiagnosticId}}")] // Unnecessary
580+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Category3", "CS0168")] // Unnecessary
581+
void M()
582+
{
583+
#pragma warning disable CS0168 // Variable is declared but never used - Necessary
584+
int x;
585+
}
586+
}
587+
""";
587588
}
588589

589590
string[] files;
@@ -605,7 +606,6 @@ void M()
605606
using var workspace = new EditorTestWorkspace(composition);
606607

607608
workspace.GlobalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.BackgroundAnalysisScopeOption, LanguageNames.CSharp, analysisScope);
608-
workspace.GlobalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.EnableDiagnosticsInSourceGeneratedFiles, isSourceGenerated);
609609

610610
var compilerDiagnosticsScope = analysisScope.ToEquivalentCompilerDiagnosticsScope();
611611
workspace.GlobalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.CompilerDiagnosticsScopeOption, LanguageNames.CSharp, compilerDiagnosticsScope);
@@ -714,14 +714,15 @@ internal async Task TestOnlyRequiredAnalyzerExecutedDuringDiagnosticComputation(
714714
[CombinatorialData]
715715
public async Task TestFilterSpanOnContextAsync(FilterSpanTestAnalyzer.AnalysisKind kind)
716716
{
717-
var source = @"
718-
class B
719-
{
720-
void M()
721-
{
722-
int x = 1;
723-
}
724-
}";
717+
var source = """
718+
class B
719+
{
720+
void M()
721+
{
722+
int x = 1;
723+
}
724+
}
725+
""";
725726
var additionalText = @"This is an additional file!";
726727

727728
using var workspace = TestWorkspace.CreateCSharp(source);
@@ -788,14 +789,15 @@ internal async Task TestCancellationDuringDiagnosticComputation_OutOfProc(Analyz
788789
// NOTE: Unfortunately, we cannot perform an end-to-end OutOfProc test, similar to the InProc test above because AnalyzerImageReference is not serializable.
789790
// So, we perform a very targeted test which directly uses the 'DiagnosticComputer' type that is used for all OutOfProc diagnostic computation.
790791

791-
var source = @"
792-
class A
793-
{
794-
void M()
795-
{
796-
int x = 0;
797-
}
798-
}";
792+
var source = """
793+
class A
794+
{
795+
void M()
796+
{
797+
int x = 0;
798+
}
799+
}
800+
""";
799801

800802
using var workspace = TestWorkspace.CreateCSharp(source);
801803

src/EditorFeatures/TestUtilities/Options/OptionSerializerTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public void SerializationAndDeserializationForNullableBool([CombinatorialValues(
2727
CompletionViewOptionsStorage.EnableArgumentCompletionSnippets,
2828
FeatureOnOffOptions.OfferRemoveUnusedReferences,
2929
InheritanceMarginOptionsStorage.ShowInheritanceMargin,
30-
SolutionCrawlerOptionsStorage.EnableDiagnosticsInSourceGeneratedFiles,
3130
CompletionOptionsStorage.ShowItemsFromUnimportedNamespaces,
3231
CompletionOptionsStorage.ShowNewSnippetExperienceUserOption,
3332
CompletionOptionsStorage.TriggerOnDeletion,

src/Features/Core/Portable/ExternalAccess/UnitTesting/SolutionCrawler/UnitTestingWorkCoordinator.cs

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ internal sealed partial class UnitTestingWorkCoordinator : IUnitTestingWorkCoord
2525
{
2626
private readonly CountLogAggregator<WorkspaceChangeKind> _logAggregator = new();
2727
private readonly IAsynchronousOperationListener _listener;
28-
private readonly Microsoft.CodeAnalysis.SolutionCrawler.ISolutionCrawlerOptionsService? _solutionCrawlerOptionsService;
2928

3029
private readonly CancellationTokenSource _shutdownNotificationSource = new();
3130
private readonly CancellationToken _shutdownToken;
@@ -43,7 +42,6 @@ public UnitTestingWorkCoordinator(
4342
Registration = registration;
4443

4544
_listener = listener;
46-
_solutionCrawlerOptionsService = Registration.Services.GetService<Microsoft.CodeAnalysis.SolutionCrawler.ISolutionCrawlerOptionsService>();
4745

4846
// event and worker queues
4947
_shutdownToken = _shutdownNotificationSource.Token;
@@ -294,36 +292,34 @@ private void EnqueueDocumentChangedEvent(Solution oldSolution, Solution newSolut
294292

295293
// If all features are enabled for source generated documents, the solution crawler needs to
296294
// include them in incremental analysis.
297-
if (_solutionCrawlerOptionsService?.EnableDiagnosticsInSourceGeneratedFiles == true)
295+
296+
// TODO: if this becomes a hot spot, we should be able to expose/access the dictionary
297+
// underneath GetSourceGeneratedDocumentsAsync rather than create a new one here.
298+
var oldProjectSourceGeneratedDocuments = await oldProject.GetSourceGeneratedDocumentsAsync(_shutdownToken).ConfigureAwait(false);
299+
var oldProjectSourceGeneratedDocumentsById = oldProjectSourceGeneratedDocuments.ToDictionary(static document => document.Id);
300+
var newProjectSourceGeneratedDocuments = await newProject.GetSourceGeneratedDocumentsAsync(_shutdownToken).ConfigureAwait(false);
301+
var newProjectSourceGeneratedDocumentsById = newProjectSourceGeneratedDocuments.ToDictionary(static document => document.Id);
302+
303+
foreach (var (oldDocumentId, _) in oldProjectSourceGeneratedDocumentsById)
298304
{
299-
// TODO: if this becomes a hot spot, we should be able to expose/access the dictionary
300-
// underneath GetSourceGeneratedDocumentsAsync rather than create a new one here.
301-
var oldProjectSourceGeneratedDocuments = await oldProject.GetSourceGeneratedDocumentsAsync(_shutdownToken).ConfigureAwait(false);
302-
var oldProjectSourceGeneratedDocumentsById = oldProjectSourceGeneratedDocuments.ToDictionary(static document => document.Id);
303-
var newProjectSourceGeneratedDocuments = await newProject.GetSourceGeneratedDocumentsAsync(_shutdownToken).ConfigureAwait(false);
304-
var newProjectSourceGeneratedDocumentsById = newProjectSourceGeneratedDocuments.ToDictionary(static document => document.Id);
305-
306-
foreach (var (oldDocumentId, _) in oldProjectSourceGeneratedDocumentsById)
305+
if (!newProjectSourceGeneratedDocumentsById.ContainsKey(oldDocumentId))
307306
{
308-
if (!newProjectSourceGeneratedDocumentsById.ContainsKey(oldDocumentId))
309-
{
310-
// This source generated document was removed
311-
EnqueueFullDocumentEvent(oldSolution, oldDocumentId, UnitTestingInvocationReasons.DocumentRemoved);
312-
}
307+
// This source generated document was removed
308+
EnqueueFullDocumentEvent(oldSolution, oldDocumentId, UnitTestingInvocationReasons.DocumentRemoved);
313309
}
310+
}
314311

315-
foreach (var (newDocumentId, newDocument) in newProjectSourceGeneratedDocumentsById)
312+
foreach (var (newDocumentId, newDocument) in newProjectSourceGeneratedDocumentsById)
313+
{
314+
if (!oldProjectSourceGeneratedDocumentsById.TryGetValue(newDocumentId, out var oldDocument))
316315
{
317-
if (!oldProjectSourceGeneratedDocumentsById.TryGetValue(newDocumentId, out var oldDocument))
318-
{
319-
// This source generated document was added
320-
EnqueueFullDocumentEvent(newSolution, newDocumentId, UnitTestingInvocationReasons.DocumentAdded);
321-
}
322-
else
323-
{
324-
// This source generated document may have changed
325-
await EnqueueChangedDocumentWorkItemAsync(oldDocument, newDocument).ConfigureAwait(continueOnCapturedContext: false);
326-
}
316+
// This source generated document was added
317+
EnqueueFullDocumentEvent(newSolution, newDocumentId, UnitTestingInvocationReasons.DocumentAdded);
318+
}
319+
else
320+
{
321+
// This source generated document may have changed
322+
await EnqueueChangedDocumentWorkItemAsync(oldDocument, newDocument).ConfigureAwait(continueOnCapturedContext: false);
327323
}
328324
}
329325
});
@@ -382,11 +378,8 @@ private async Task EnqueueFullProjectWorkItemAsync(Project project, UnitTestingI
382378

383379
// If all features are enabled for source generated documents, the solution crawler needs to
384380
// include them in incremental analysis.
385-
if (_solutionCrawlerOptionsService?.EnableDiagnosticsInSourceGeneratedFiles == true)
386-
{
387-
foreach (var document in await project.GetSourceGeneratedDocumentsAsync(_shutdownToken).ConfigureAwait(false))
388-
await EnqueueDocumentWorkItemAsync(project, document.Id, document, invocationReasons).ConfigureAwait(false);
389-
}
381+
foreach (var document in await project.GetSourceGeneratedDocumentsAsync(_shutdownToken).ConfigureAwait(false))
382+
await EnqueueDocumentWorkItemAsync(project, document.Id, document, invocationReasons).ConfigureAwait(false);
390383
}
391384

392385
private async Task EnqueueWorkItemAsync(IUnitTestingIncrementalAnalyzer analyzer, UnitTestingReanalyzeScope scope)

src/Features/Core/Portable/SolutionCrawler/ISolutionCrawlerOptionsService.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/LanguageServer/Protocol/Features/Options/SolutionCrawlerOptionsService.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/LanguageServer/Protocol/Features/Options/SolutionCrawlerOptionsStorage.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ internal static class SolutionCrawlerOptionsStorage
2323
public static readonly PerLanguageOption2<CompilerDiagnosticsScope> CompilerDiagnosticsScopeOption = new(
2424
"dotnet_compiler_diagnostics_scope", defaultValue: CompilerDiagnosticsScope.OpenFiles, group: s_backgroundAnalysisOptionGroup, serializer: EditorConfigValueSerializer.CreateSerializerForEnum<CompilerDiagnosticsScope>());
2525

26-
public static readonly Option2<bool> EnableDiagnosticsInSourceGeneratedFiles = new(
27-
"dotnet_enable_diagnostics_in_source_generated_files", defaultValue: true, group: s_backgroundAnalysisOptionGroup);
28-
2926
/// <summary>
3027
/// Enables forced <see cref="BackgroundAnalysisScope.Minimal"/> scope when low VM is detected to improve performance.
3128
/// </summary>

src/LanguageServer/Protocol/Handler/Diagnostics/DiagnosticSourceProviders/WorkspaceDocumentsAndProjectDiagnosticSourceProvider.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public async ValueTask<ImmutableArray<IDiagnosticSource>> CreateDiagnosticSource
5555
using var _ = ArrayBuilder<IDiagnosticSource>.GetInstance(out var result);
5656

5757
var solution = context.Solution;
58-
var enableDiagnosticsInSourceGeneratedFiles = solution.Services.GetService<ISolutionCrawlerOptionsService>()?.EnableDiagnosticsInSourceGeneratedFiles == true;
5958
var codeAnalysisService = solution.Services.GetRequiredService<ICodeAnalysisDiagnosticAnalyzerService>();
6059

6160
foreach (var project in WorkspaceDiagnosticSourceHelpers.GetProjectsInPriorityOrder(solution, context.SupportedLanguages))
@@ -75,12 +74,8 @@ async Task AddDocumentsAndProjectAsync(Project project, IDiagnosticAnalyzerServi
7574
AddDocumentSources(project.Documents);
7675
AddDocumentSources(project.AdditionalDocuments);
7776

78-
// If all features are enabled for source generated documents, then compute todo-comments/diagnostics for them.
79-
if (enableDiagnosticsInSourceGeneratedFiles)
80-
{
81-
var sourceGeneratedDocuments = await project.GetSourceGeneratedDocumentsAsync(cancellationToken).ConfigureAwait(false);
82-
AddDocumentSources(sourceGeneratedDocuments);
83-
}
77+
var sourceGeneratedDocuments = await project.GetSourceGeneratedDocumentsAsync(cancellationToken).ConfigureAwait(false);
78+
AddDocumentSources(sourceGeneratedDocuments);
8479

8580
// Finally, add the appropriate FSA or CodeAnalysis project source to get project specific diagnostics, not associated with any document.
8681
AddProjectSource();

src/LanguageServer/ProtocolUnitTests/Diagnostics/AbstractPullDiagnosticTestsBase.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ private protected static InitializationOptions GetInitializationOptions(
330330
bool useVSDiagnostics,
331331
WellKnownLspServerKinds serverKind = WellKnownLspServerKinds.AlwaysActiveVSLspServer,
332332
string[]? sourceGeneratedMarkups = null,
333-
IEnumerable<DiagnosticAnalyzer>? additionalAnalyzers = null,
334-
bool enableDiagnosticsInSourceGeneratedFiles = true)
333+
IEnumerable<DiagnosticAnalyzer>? additionalAnalyzers = null)
335334
{
336335
// If no explicit compiler diagnostics scope has been provided, match it with the provided analyzer diagnostics scope
337336
compilerDiagnosticsScope ??= analyzerDiagnosticsScope switch
@@ -354,7 +353,6 @@ private protected static InitializationOptions GetInitializationOptions(
354353
globalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.CompilerDiagnosticsScopeOption, LanguageNames.CSharp, compilerDiagnosticsScope.Value);
355354
globalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.CompilerDiagnosticsScopeOption, LanguageNames.VisualBasic, compilerDiagnosticsScope.Value);
356355
globalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.CompilerDiagnosticsScopeOption, InternalLanguageNames.TypeScript, compilerDiagnosticsScope.Value);
357-
globalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.EnableDiagnosticsInSourceGeneratedFiles, enableDiagnosticsInSourceGeneratedFiles);
358356
},
359357
ServerKind = serverKind,
360358
SourceGeneratedMarkups = sourceGeneratedMarkups ?? [],

src/LanguageServer/ProtocolUnitTests/Diagnostics/PullDiagnosticTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,12 +1048,12 @@ public async Task TestWorkspaceDiagnosticsForClosedFilesWithRunCodeAnalysisFSAOn
10481048
}
10491049

10501050
[Theory, CombinatorialData]
1051-
public async Task SourceGeneratorFailures_FSA(bool useVSDiagnostics, bool mutatingLspWorkspace, bool enableDiagnosticsInSourceGeneratedFiles)
1051+
public async Task SourceGeneratorFailures_FSA(bool useVSDiagnostics, bool mutatingLspWorkspace)
10521052
{
10531053
await using var testLspServer = await CreateTestLspServerAsync(["class C {}"], mutatingLspWorkspace,
1054-
GetInitializationOptions(BackgroundAnalysisScope.FullSolution, CompilerDiagnosticsScope.FullSolution, useVSDiagnostics, enableDiagnosticsInSourceGeneratedFiles: enableDiagnosticsInSourceGeneratedFiles));
1054+
GetInitializationOptions(BackgroundAnalysisScope.FullSolution, CompilerDiagnosticsScope.FullSolution, useVSDiagnostics));
10551055

1056-
var generator = new Roslyn.Test.Utilities.TestGenerators.TestSourceGenerator()
1056+
var generator = new TestSourceGenerator()
10571057
{
10581058
ExecuteImpl = context => throw new InvalidOperationException("Source generator failed")
10591059
};

0 commit comments

Comments
 (0)