Skip to content

Commit 8814b23

Browse files
authored
Remove fallback options for SimplifierOptions (#74222)
* SimplifierOptions * Fix tests
1 parent 70be0c7 commit 8814b23

File tree

34 files changed

+112
-96
lines changed

34 files changed

+112
-96
lines changed

src/Analyzers/CSharp/CodeFixes/UseImplicitObjectCreation/CSharpUseImplicitObjectCreationCodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected override async Task FixAllAsync(
5858
#if CODE_STYLE
5959
var options = CSharpSimplifierOptions.Default;
6060
#else
61-
var options = (CSharpSimplifierOptions)await document.GetSimplifierOptionsAsync(fallbackOptions, cancellationToken).ConfigureAwait(false);
61+
var options = (CSharpSimplifierOptions)await document.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
6262
#endif
6363

6464
// Bulk apply these, except at the expression level. One fix at the expression level may prevent another fix

src/Analyzers/Core/Analyzers/AnalyzerOptionsProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public AnalyzerOptionsProvider(IOptionsReader options, string language, Analyzer
4949
public CodeStyleOption2<bool> PreferPredefinedTypeKeywordInDeclaration => GetOption(CodeStyleOptions2.PreferIntrinsicPredefinedTypeKeywordInDeclaration, FallbackSimplifierOptions.PreferPredefinedTypeKeywordInDeclaration);
5050

5151
public SimplifierOptions GetSimplifierOptions(ISimplification simplification)
52-
=> simplification.GetSimplifierOptions(_options, _fallbackOptions.CleanupOptions?.SimplifierOptions);
52+
=> simplification.GetSimplifierOptions(_options);
5353

5454
// SyntaxFormattingOptions
5555

src/EditorFeatures/CSharpTest/EventHookup/EventHookupTestState.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ public EventHookupTestState(XElement workspaceElement, OptionsCollection options
4040

4141
_testSessionHookupMutex = new Mutex(false);
4242
_commandHandler.TESTSessionHookupMutex = _testSessionHookupMutex;
43-
options?.SetGlobalOptions(Workspace.GlobalOptions);
43+
44+
if (options != null)
45+
{
46+
Workspace.SetAnalyzerFallbackOptions(options);
47+
}
4448
}
4549

4650
public static EventHookupTestState CreateTestState(string markup, OptionsCollection options = null)

src/EditorFeatures/CSharpTest/Intents/IntentTestsBase.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ internal static async Task<ImmutableArray<IntentSource>> GetIntentsAsync(
9797
OptionsCollection? options = null,
9898
string? intentData = null)
9999
{
100-
options?.SetGlobalOptions(workspace.GlobalOptions);
100+
if (options != null)
101+
{
102+
workspace.SetAnalyzerFallbackOptions(options);
103+
}
101104

102105
var intentSource = workspace.ExportProvider.GetExportedValue<IIntentSourceProvider>();
103106

src/EditorFeatures/VisualBasic/NavigationBar/VisualBasicEditorNavigationBarItemService_CodeGeneration.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
6060
Return document
6161
End If
6262

63-
Dim simplifierOptions = Await newDocument.GetSimplifierOptionsAsync(globalOptions, cancellationToken).ConfigureAwait(False)
63+
Dim simplifierOptions = Await newDocument.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(False)
6464
Dim formattingOptions = Await newDocument.GetSyntaxFormattingOptionsAsync(globalOptions, cancellationToken).ConfigureAwait(False)
6565

6666
newDocument = Await Simplifier.ReduceAsync(newDocument, Simplifier.Annotation, simplifierOptions, cancellationToken).ConfigureAwait(False)

src/Features/CSharp/Portable/CodeRefactorings/UseExplicitOrImplicitType/AbstractUseTypeCodeRefactoringProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
4747
return;
4848
}
4949

50-
var simplifierOptions = (CSharpSimplifierOptions)await document.GetSimplifierOptionsAsync(context.Options, cancellationToken).ConfigureAwait(false);
50+
var simplifierOptions = (CSharpSimplifierOptions)await document.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
5151
var typeStyle = AnalyzeTypeName(declaredType, semanticModel, simplifierOptions, cancellationToken);
5252
if (typeStyle.IsStylePreferred && typeStyle.Notification.Severity != ReportDiagnostic.Suppress)
5353
{

src/Features/CSharp/Portable/GenerateConstructorFromMembers/CSharpGenerateConstructorFromMembersCodeRefactoringProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected override string ToDisplayString(IParameterSymbol parameter, SymbolDisp
4949

5050
protected override async ValueTask<bool> PrefersThrowExpressionAsync(Document document, SimplifierOptionsProvider fallbackOptions, CancellationToken cancellationToken)
5151
{
52-
var options = (CSharpSimplifierOptions)await document.GetSimplifierOptionsAsync(fallbackOptions, cancellationToken).ConfigureAwait(false);
52+
var options = (CSharpSimplifierOptions)await document.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
5353
return options.PreferThrowExpression.Value;
5454
}
5555

src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceLocalForExpressionCodeRefactoringProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected override async Task<ExpressionStatementSyntax> CreateTupleDeconstructi
9494
CancellationToken cancellationToken)
9595
{
9696
var semanticFacts = document.GetRequiredLanguageService<ISemanticFactsService>();
97-
var simplifierOptions = (CSharpSimplifierOptions)await document.GetSimplifierOptionsAsync(optionsProvider, cancellationToken).ConfigureAwait(false);
97+
var simplifierOptions = (CSharpSimplifierOptions)await document.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
9898
var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);
9999

100100
var tupleUnderlyingType = tupleType.TupleUnderlyingType ?? tupleType;

src/Features/Core/Portable/EncapsulateField/AbstractEncapsulateFieldService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ private async Task<Solution> EncapsulateFieldAsync(
220220
new SyntaxAnnotation(),
221221
document);
222222

223-
var simplifierOptions = await document.GetSimplifierOptionsAsync(fallbackOptions, cancellationToken).ConfigureAwait(false);
223+
var simplifierOptions = await document.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
224224

225225
var documentWithProperty = await AddPropertyAsync(
226226
document, document.Project.Solution, field, generatedProperty, fallbackOptions, cancellationToken).ConfigureAwait(false);

src/Features/Core/Portable/InitializeParameter/AbstractAddParameterCheckCodeRefactoringProvider.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected override async Task<ImmutableArray<CodeAction>> GetRefactoringsForAllP
7676
// Great. The list has parameters that need null checks. Offer to add null checks for all.
7777
return [CodeAction.Create(
7878
FeaturesResources.Add_null_checks_for_all_parameters,
79-
c => UpdateDocumentForRefactoringAsync(document, blockStatementOpt, listOfParametersOrdinals, parameterSpan, fallbackOptions, c),
79+
c => UpdateDocumentForRefactoringAsync(document, blockStatementOpt, listOfParametersOrdinals, parameterSpan, c),
8080
nameof(FeaturesResources.Add_null_checks_for_all_parameters))];
8181
}
8282

@@ -96,7 +96,7 @@ protected override async Task<ImmutableArray<CodeAction>> GetRefactoringsForSing
9696
if (!ParameterValidForNullCheck(document, parameter, semanticModel, blockStatementOpt, cancellationToken))
9797
return [];
9898

99-
var simplifierOptions = (TSimplifierOptions)await document.GetSimplifierOptionsAsync(fallbackOptions, cancellationToken).ConfigureAwait(false);
99+
var simplifierOptions = (TSimplifierOptions)await document.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
100100

101101
// Great. There was no null check. Offer to add one.
102102
using var result = TemporaryArray<CodeAction>.Empty;
@@ -128,7 +128,6 @@ private async Task<Document> UpdateDocumentForRefactoringAsync(
128128
IBlockOperation? blockStatementOpt,
129129
List<int> listOfParametersOrdinals,
130130
TextSpan parameterSpan,
131-
CleanCodeGenerationOptionsProvider fallbackOptions,
132131
CancellationToken cancellationToken)
133132
{
134133
TSimplifierOptions? lazySimplifierOptions = null;
@@ -156,7 +155,7 @@ private async Task<Document> UpdateDocumentForRefactoringAsync(
156155
if (!CanOfferRefactoring(functionDeclaration, semanticModel, syntaxFacts, cancellationToken, out blockStatementOpt))
157156
continue;
158157

159-
lazySimplifierOptions ??= (TSimplifierOptions)await document.GetSimplifierOptionsAsync(fallbackOptions, cancellationToken).ConfigureAwait(false);
158+
lazySimplifierOptions ??= (TSimplifierOptions)await document.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
160159

161160
// If parameter is a string, default check would be IsNullOrEmpty. This is because IsNullOrEmpty is more
162161
// commonly used in this regard according to telemetry and UX testing.

src/Features/Core/Portable/IntroduceVariable/AbstractIntroduceVariableService.AbstractIntroduceVariableCodeAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal AbstractIntroduceVariableCodeAction(
5454
protected override async Task<Document> GetChangedDocumentAsync(CancellationToken cancellationToken)
5555
{
5656
var changedDocument = await GetChangedDocumentCoreAsync(cancellationToken).ConfigureAwait(false);
57-
var simplifierOptions = await changedDocument.GetSimplifierOptionsAsync(Options.SimplifierOptions, cancellationToken).ConfigureAwait(false);
57+
var simplifierOptions = await changedDocument.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
5858
return await Simplifier.ReduceAsync(changedDocument, simplifierOptions, cancellationToken).ConfigureAwait(false);
5959
}
6060

src/Features/Core/Portable/SimplifyTypeNames/AbstractSimplifyTypeNamesCodeFixProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
8080

8181
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
8282
var model = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
83-
var options = (TSimplifierOptions)await document.GetSimplifierOptionsAsync(context.Options, cancellationToken).ConfigureAwait(false);
83+
var options = (TSimplifierOptions)await document.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
8484

8585
var (node, diagnosticId) = GetNodeToSimplify(
8686
root, model, span, options, cancellationToken);
@@ -104,7 +104,7 @@ protected override async Task FixAllAsync(
104104
{
105105
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
106106
var model = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
107-
var simplifierOptions = (TSimplifierOptions)await document.GetSimplifierOptionsAsync(fallbackOptions, cancellationToken).ConfigureAwait(false);
107+
var simplifierOptions = (TSimplifierOptions)await document.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
108108

109109
foreach (var diagnostic in diagnostics)
110110
{

src/Features/Core/Portable/Snippets/SnippetProviders/AbstractSnippetProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private async Task<Document> CleanupDocumentAsync(
151151
if (document.SupportsSyntaxTree)
152152
{
153153
var addImportPlacementOptions = await document.GetAddImportPlacementOptionsAsync(fallbackOptions: null, cancellationToken).ConfigureAwait(false);
154-
var simplifierOptions = await document.GetSimplifierOptionsAsync(fallbackOptions: null, cancellationToken).ConfigureAwait(false);
154+
var simplifierOptions = await document.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
155155
var syntaxFormattingOptions = await document.GetSyntaxFormattingOptionsAsync(fallbackOptions: null, cancellationToken).ConfigureAwait(false);
156156

157157
document = await ImportAdder.AddImportsFromSymbolAnnotationAsync(

src/LanguageServer/Protocol/ExternalAccess/Razor/SimplifyMethodHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public SimplifyMethodHandler()
5959
// Call to the Simplifier and pass back the edits.
6060
var configOptions = await originalDocument.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false);
6161
var simplificationService = originalDocument.Project.Services.GetRequiredService<ISimplificationService>();
62-
var options = simplificationService.GetSimplifierOptions(configOptions, simplificationService.DefaultOptions);
62+
var options = simplificationService.GetSimplifierOptions(configOptions);
6363
var newDocument = await Simplifier.ReduceAsync(annotatedDocument, options, cancellationToken).ConfigureAwait(false);
6464
var changes = await newDocument.GetTextChangesAsync(originalDocument, cancellationToken).ConfigureAwait(false);
6565
return changes.Select(change => ProtocolConversions.TextChangeToTextEdit(change, originalSourceText)).ToArray();

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

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

src/LanguageServer/Protocol/Handler/InlineCompletions/InlineCompletionsHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(VSInternalInlineCompleti
138138

139139
// Use the formatting options specified by the client to format the snippet.
140140
var formattingOptions = await ProtocolConversions.GetFormattingOptionsAsync(request.Options, document, _globalOptions, cancellationToken).ConfigureAwait(false);
141-
var simplifierOptions = await document.GetSimplifierOptionsAsync(_globalOptions, cancellationToken).ConfigureAwait(false);
141+
var simplifierOptions = await document.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
142142

143143
var formattedLspSnippet = await GetFormattedLspSnippetAsync(parsedSnippet, wordOnLeft.Value, document, sourceText, formattingOptions, simplifierOptions, cancellationToken).ConfigureAwait(false);
144144

src/LanguageServer/ProtocolUnitTests/VSTypeScriptHandlerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public async Task TestGetSimplifierOptionsOnTypeScriptDocument()
8484

8585
await using var testLspServer = await CreateTsTestLspServerAsync(workspaceXml);
8686
var document = testLspServer.GetCurrentSolution().Projects.Single().Documents.Single();
87-
var simplifierOptions = testLspServer.TestWorkspace.GlobalOptions.GetSimplifierOptions(document.Project.Services, fallbackOptions: null);
87+
var simplifierOptions = testLspServer.TestWorkspace.GlobalOptions.GetSimplifierOptions(document.Project.Services);
8888
Assert.Same(SimplifierOptions.CommonDefaults, simplifierOptions);
8989
}
9090

src/VisualStudio/Core/Def/Snippets/SnippetFunctions/SnippetFunctionGenerateSwitchCases.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected override int FieldChanged(string field, out int requeryFunction)
5555
return (VSConstants.S_OK, snippetFunctionService.SwitchDefaultCaseForm, hasCurrentValue);
5656
}
5757

58-
var simplifierOptions = await document.GetSimplifierOptionsAsync(snippetExpansionClient.EditorOptionsService.GlobalOptions, cancellationToken).ConfigureAwait(false);
58+
var simplifierOptions = await document.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
5959

6060
var value = await snippetFunctionService.GetSwitchExpansionAsync(document, caseGenerationSpan.Value, switchExpressionSpan.Value, simplifierOptions, cancellationToken).ConfigureAwait(false);
6161
if (value == null)

src/VisualStudio/Core/Def/Snippets/SnippetFunctions/SnippetFunctionSimpleTypeName.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public SnippetFunctionSimpleTypeName(
4242
if (!TryGetFieldSpan(out var fieldSpan))
4343
return (VSConstants.E_FAIL, value, hasDefaultValue);
4444

45-
var simplifierOptions = await document.GetSimplifierOptionsAsync(snippetExpansionClient.EditorOptionsService.GlobalOptions, cancellationToken).ConfigureAwait(false);
45+
var simplifierOptions = await document.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
4646

4747
var simplifiedTypeName = await SnippetFunctionService.GetSimplifiedTypeNameAsync(document, fieldSpan.Value, _fullyQualifiedName, simplifierOptions, cancellationToken).ConfigureAwait(false);
4848
if (string.IsNullOrEmpty(simplifiedTypeName))

src/VisualStudio/Core/Impl/CodeModel/AbstractCodeModelService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ private SyntaxNode InsertNode(
10881088
{
10891089
document = _threadingContext.JoinableTaskFactory.Run(async () =>
10901090
{
1091-
var simplifierOptions = await document.GetSimplifierOptionsAsync(_editorOptionsService.GlobalOptions, cancellationToken).ConfigureAwait(false);
1091+
var simplifierOptions = await document.GetSimplifierOptionsAsync(cancellationToken).ConfigureAwait(false);
10921092
return await Simplifier.ReduceAsync(document, annotation, simplifierOptions, cancellationToken).ConfigureAwait(false);
10931093
});
10941094
}

src/VisualStudio/Core/Impl/CodeModel/FileCodeModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ int IVBFileCodeModelEvents.EndEdit()
704704
// perform expensive operations at once
705705
var newDocument = State.ThreadingContext.JoinableTaskFactory.Run(async () =>
706706
{
707-
var simplifierOptions = await _batchDocument.GetSimplifierOptionsAsync(GlobalOptions, CancellationToken.None).ConfigureAwait(false);
707+
var simplifierOptions = await _batchDocument.GetSimplifierOptionsAsync(CancellationToken.None).ConfigureAwait(false);
708708
return await Simplifier.ReduceAsync(_batchDocument, Simplifier.Annotation, simplifierOptions, CancellationToken.None).ConfigureAwait(false);
709709
});
710710

src/Workspaces/CSharp/Portable/Simplification/CSharpSimplificationService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ internal partial class CSharpSimplificationService()
4646
public override SimplifierOptions DefaultOptions
4747
=> CSharpSimplifierOptions.Default;
4848

49-
public override SimplifierOptions GetSimplifierOptions(IOptionsReader options, SimplifierOptions? fallbackOptions)
50-
=> new CSharpSimplifierOptions(options, (CSharpSimplifierOptions?)fallbackOptions);
49+
public override SimplifierOptions GetSimplifierOptions(IOptionsReader options)
50+
=> new CSharpSimplifierOptions(options, fallbackOptions: null);
5151

5252
public override SyntaxNode Expand(SyntaxNode node, SemanticModel semanticModel, SyntaxAnnotation? annotationForReplacedAliasIdentifier, Func<SyntaxNode, bool>? expandInsideNode, bool expandParameter, CancellationToken cancellationToken)
5353
{

src/Workspaces/Core/Portable/Options/LegacyGlobalCodeActionOptionsWorkspaceService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ValueTask<SyntaxFormattingOptions> OptionsProvider<SyntaxFormattingOptions>.GetO
4141
=> ValueTaskFactory.FromResult(options.GetSyntaxFormattingOptions(languageServices, fallbackOptions: null));
4242

4343
ValueTask<SimplifierOptions> OptionsProvider<SimplifierOptions>.GetOptionsAsync(LanguageServices languageServices, CancellationToken cancellationToken)
44-
=> ValueTaskFactory.FromResult(options.GetSimplifierOptions(languageServices, fallbackOptions: null));
44+
=> ValueTaskFactory.FromResult(options.GetSimplifierOptions(languageServices));
4545

4646
ValueTask<AddImportPlacementOptions> OptionsProvider<AddImportPlacementOptions>.GetOptionsAsync(LanguageServices languageServices, CancellationToken cancellationToken)
4747
=> ValueTaskFactory.FromResult(options.GetAddImportPlacementOptions(languageServices, allowInHiddenRegions: null, fallbackOptions: null));

src/Workspaces/Core/Portable/Simplification/AbstractSimplificationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected AbstractSimplificationService(ImmutableArray<AbstractReducer> reducers
4242
protected abstract void AddImportDeclarations(TCompilationUnitSyntax root, ArrayBuilder<SyntaxNode> importDeclarations);
4343

4444
public abstract SimplifierOptions DefaultOptions { get; }
45-
public abstract SimplifierOptions GetSimplifierOptions(IOptionsReader options, SimplifierOptions? fallbackOptions);
45+
public abstract SimplifierOptions GetSimplifierOptions(IOptionsReader options);
4646

4747
protected virtual SyntaxNode TransformReducedNode(SyntaxNode reducedNode, SyntaxNode originalNode)
4848
=> reducedNode;

0 commit comments

Comments
 (0)