diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/Suppression/SuppressionTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/Suppression/SuppressionTests.cs index 264ef12fda63f..5f660b4ef5fbe 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/Suppression/SuppressionTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/Suppression/SuppressionTests.cs @@ -468,7 +468,7 @@ void Method() Assert.Equal(2, diagnostics.Where(d => d.Id == "CS0219").Count()); var options = CodeActionOptions.Default; - var allFixes = (await fixService.GetFixesAsync(document, span, options, CancellationToken.None)) + var allFixes = (await fixService.GetFixesAsync(document, span, _ => options, CancellationToken.None)) .SelectMany(fixCollection => fixCollection.Fixes); var cs0219Fixes = allFixes.Where(fix => fix.PrimaryDiagnostic.Id == "CS0219").ToArray(); diff --git a/src/EditorFeatures/CSharpTest/Formatting/CodeCleanupTests.cs b/src/EditorFeatures/CSharpTest/Formatting/CodeCleanupTests.cs index 79e99b0d5c3c9..41f18c56889b9 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/CodeCleanupTests.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/CodeCleanupTests.cs @@ -659,7 +659,7 @@ private protected static async Task AssertCodeCleanupResult(string expected, str var enabledDiagnostics = codeCleanupService.GetAllDiagnostics(); var newDoc = await codeCleanupService.CleanupAsync( - document, enabledDiagnostics, new ProgressTracker(), options, formattingOptions, CancellationToken.None); + document, enabledDiagnostics, new ProgressTracker(), _ => options, formattingOptions, CancellationToken.None); var actual = await newDoc.GetTextAsync(); diff --git a/src/EditorFeatures/Core.Wpf/Suggestions/AsyncSuggestedActionsSource.cs b/src/EditorFeatures/Core.Wpf/Suggestions/AsyncSuggestedActionsSource.cs index d95cb66d77b25..c31d60df922a9 100644 --- a/src/EditorFeatures/Core.Wpf/Suggestions/AsyncSuggestedActionsSource.cs +++ b/src/EditorFeatures/Core.Wpf/Suggestions/AsyncSuggestedActionsSource.cs @@ -162,7 +162,7 @@ private async IAsyncEnumerable GetCodeFixesAndRefactoringsAs var workspace = document.Project.Solution.Workspace; var supportsFeatureService = workspace.Services.GetRequiredService(); - var options = GlobalOptions.GetCodeActionOptions(document.Project.Language); + var options = GlobalOptions.GetCodeActionOptionsProvider(); var fixesTask = GetCodeFixesAsync( state, supportsFeatureService, requestedActionCategories, workspace, document, range, diff --git a/src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs b/src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs index 1b5d86630fdce..c2ef69da65011 100644 --- a/src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs +++ b/src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs @@ -177,7 +177,7 @@ public bool TryGetTelemetryId(out Guid telemetryId) Func addOperationScope = description => operationContext?.AddScope(allowCancellation: true, string.Format(EditorFeaturesResources.Gathering_Suggestions_0, description)); - var options = GlobalOptions.GetBlockingCodeActionOptions(document.Project.Language); + var options = GlobalOptions.GetBlockingCodeActionOptionsProvider(); // We convert the code fixes and refactorings to UnifiedSuggestedActionSets instead of // SuggestedActionSets so that we can share logic between local Roslyn and LSP. @@ -266,7 +266,7 @@ protected static Task> GetCodeFixesAsy SnapshotSpan range, Func addOperationScope, CodeActionRequestPriority priority, - CodeActionOptions options, + CodeActionOptionsProvider options, CancellationToken cancellationToken) { if (state.Target.Owner._codeFixService == null || @@ -306,7 +306,7 @@ protected static Task> GetRefactorings TextSpan? selection, Func addOperationScope, CodeActionRequestPriority priority, - CodeActionOptions options, + CodeActionOptionsProvider options, CancellationToken cancellationToken) { if (!selection.HasValue) @@ -414,7 +414,7 @@ await InvokeBelowInputPriorityAsync(() => ReferenceCountedDisposable state, Document document, SnapshotSpan range, - CodeActionOptions options, + CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var order in Orderings) @@ -458,7 +458,7 @@ await InvokeBelowInputPriorityAsync(() => private async Task TryGetRefactoringSuggestedActionCategoryAsync( Document document, TextSpan? selection, - CodeActionOptions options, + CodeActionOptionsProvider options, CancellationToken cancellationToken) { using var state = _state.TryAddReference(); @@ -630,7 +630,7 @@ private void OnSuggestedActionsChanged(Workspace currentWorkspace, DocumentId? c if (document == null) return null; - var options = GlobalOptions.GetCodeActionOptions(document.Project.Language); + var options = GlobalOptions.GetCodeActionOptionsProvider(); using var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); var linkedToken = linkedTokenSource.Token; diff --git a/src/EditorFeatures/Core/CodeActions/CodeActionOptionsStorage.cs b/src/EditorFeatures/Core/CodeActions/CodeActionOptionsStorage.cs index 6597b935ba6ca..3c453445d267d 100644 --- a/src/EditorFeatures/Core/CodeActions/CodeActionOptionsStorage.cs +++ b/src/EditorFeatures/Core/CodeActions/CodeActionOptionsStorage.cs @@ -32,5 +32,11 @@ internal static CodeActionOptionsProvider GetCodeActionOptionsProvider(this IGlo var cache = ImmutableDictionary.Empty; return language => ImmutableInterlocked.GetOrAdd(ref cache, language, (language, options) => GetCodeActionOptions(options, language), globalOptions); } + + internal static CodeActionOptionsProvider GetBlockingCodeActionOptionsProvider(this IGlobalOptionService globalOptions) + { + var cache = ImmutableDictionary.Empty; + return language => ImmutableInterlocked.GetOrAdd(ref cache, language, (language, options) => GetBlockingCodeActionOptions(options, language), globalOptions); + } } } diff --git a/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/CodeActionHelpers.cs b/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/CodeActionHelpers.cs index 3b12bbabee444..b1b91e3e78fe3 100644 --- a/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/CodeActionHelpers.cs +++ b/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/CodeActionHelpers.cs @@ -35,7 +35,7 @@ public static async Task GetVSCodeActionsAsync( CodeActionParams request, CodeActionsCache codeActionsCache, Document document, - CodeActionOptions options, + CodeActionOptionsProvider options, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, CancellationToken cancellationToken) @@ -186,7 +186,7 @@ public static async Task> GetCodeActionsAsync( CodeActionsCache codeActionsCache, Document document, LSP.Range selection, - CodeActionOptions options, + CodeActionOptionsProvider options, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, CancellationToken cancellationToken) @@ -242,7 +242,7 @@ private static CodeAction GetNestedActionsFromActionSet(IUnifiedSuggestedAction private static async ValueTask> GetActionSetsAsync( Document document, - CodeActionOptions options, + CodeActionOptionsProvider options, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, LSP.Range selection, diff --git a/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/CodeActionResolveHandler.cs b/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/CodeActionResolveHandler.cs index 46b40d708f983..a6f1aee4fb089 100644 --- a/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/CodeActionResolveHandler.cs +++ b/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/CodeActionResolveHandler.cs @@ -66,7 +66,7 @@ public CodeActionResolveHandler( var data = ((JToken)codeAction.Data!).ToObject(); Assumes.Present(data); - var options = _globalOptions.GetCodeActionOptions(document.Project.Language); + var options = _globalOptions.GetCodeActionOptionsProvider(); var codeActions = await CodeActionHelpers.GetCodeActionsAsync( _codeActionsCache, diff --git a/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/CodeActionsHandler.cs b/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/CodeActionsHandler.cs index c059f005a7ee0..065082667a321 100644 --- a/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/CodeActionsHandler.cs +++ b/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/CodeActionsHandler.cs @@ -57,7 +57,7 @@ public CodeActionsHandler( var document = context.Document; Contract.ThrowIfNull(document); - var options = _globalOptions.GetCodeActionOptions(document.Project.Language); + var options = _globalOptions.GetCodeActionOptionsProvider(); var codeActions = await CodeActionHelpers.GetVSCodeActionsAsync( request, _codeActionsCache, document, options, _codeFixService, _codeRefactoringService, cancellationToken).ConfigureAwait(false); diff --git a/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/RunCodeActionHandler.cs b/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/RunCodeActionHandler.cs index 1e82bc010dc39..2529f8a318e1c 100644 --- a/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/RunCodeActionHandler.cs +++ b/src/EditorFeatures/Core/LanguageServer/Handlers/CodeActions/RunCodeActionHandler.cs @@ -74,7 +74,7 @@ public override async Task HandleRequestAsync(LSP.ExecuteCommandParams r var runRequest = ((JToken)request.Arguments.Single()).ToObject(); Assumes.Present(runRequest); - var options = _globalOptions.GetCodeActionOptions(document.Project.Language); + var options = _globalOptions.GetCodeActionOptionsProvider(); var codeActions = await CodeActionHelpers.GetCodeActionsAsync( _codeActionsCache, document, runRequest.Range, options, _codeFixService, _codeRefactoringService, cancellationToken).ConfigureAwait(false); diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionTest.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionTest.cs index 023b11dcc86d1..1b7958ac53889 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionTest.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionTest.cs @@ -56,7 +56,7 @@ internal async Task GetCodeRefactoringAsync( var span = documentsWithSelections.Single().SelectedSpans.Single(); var actions = ArrayBuilder<(CodeAction, TextSpan?)>.GetInstance(); var document = workspace.CurrentSolution.GetDocument(documentsWithSelections.Single().Id); - var context = new CodeRefactoringContext(document, span, (a, t) => actions.Add((a, t)), parameters.codeActionOptions, CancellationToken.None); + var context = new CodeRefactoringContext(document, span, (a, t) => actions.Add((a, t)), _ => parameters.codeActionOptions, CancellationToken.None); await provider.ComputeRefactoringsAsync(context); var result = actions.Count > 0 ? new CodeRefactoring(provider, actions.ToImmutable()) : null; diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs index 0faa7975eae94..5f93510ae57a1 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs @@ -109,7 +109,7 @@ protected override AnalyzerOptions GetAnalyzerOptions(Project project) => new WorkspaceAnalyzerOptions(base.GetAnalyzerOptions(project), project.Solution, _sharedState.IdeAnalyzerOptions); protected override CodeFixContext CreateCodeFixContext(Document document, TextSpan span, ImmutableArray diagnostics, Action> registerCodeFix, CancellationToken cancellationToken) - => new(document, span, diagnostics, registerCodeFix, _sharedState.CodeActionOptions, cancellationToken); + => new(document, span, diagnostics, registerCodeFix, _ => _sharedState.CodeActionOptions, cancellationToken); protected override FixAllContext CreateFixAllContext( Document? document, diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs b/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs index 3ac1980cbdccf..6b7caeb9cd7d9 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs @@ -210,7 +210,7 @@ protected static Document GetDocumentAndAnnotatedSpan(TestWorkspace workspace, o diagnostic.Location.SourceSpan, ImmutableArray.Create(diagnostic), (a, d) => fixes.Add(new CodeFix(document.Project, a, d)), - options, + _ => options, CancellationToken.None); await fixer.RegisterCodeFixesAsync(context); diff --git a/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs b/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs index 1d52b68e86a61..b31a5166a4a26 100644 --- a/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs +++ b/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs @@ -62,7 +62,7 @@ public async Task TestGetFirstDiagnosticWithFixAsync() var project = workspace.CurrentSolution.Projects.Single().AddAnalyzerReference(reference); var document = project.Documents.Single(); var unused = await fixService.GetMostSevereFixAsync( - document, TextSpan.FromBounds(0, 0), CodeActionRequestPriority.None, CodeActionOptions.Default, CancellationToken.None); + document, TextSpan.FromBounds(0, 0), CodeActionRequestPriority.None, _ => CodeActionOptions.Default, CancellationToken.None); var fixer1 = (MockFixer)fixers.Single().Value; var fixer2 = (MockFixer)reference.Fixer!; @@ -91,7 +91,7 @@ public async Task TestGetFixesAsyncWithDuplicateDiagnostics() // Verify that we do not crash when computing fixes. var options = CodeActionOptions.Default; - _ = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), options, CancellationToken.None); + _ = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), _ => options, CancellationToken.None); // Verify that code fix is invoked with both the diagnostics in the context, // i.e. duplicate diagnostics are not silently discarded by the CodeFixService. @@ -118,7 +118,7 @@ public async Task TestGetFixesAsyncHasNoDuplicateConfigurationActions() // Verify registered configuration code actions do not have duplicates. var options = CodeActionOptions.Default; - var fixCollections = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), options, CancellationToken.None); + var fixCollections = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), _ => options, CancellationToken.None); var codeActions = fixCollections.SelectMany(c => c.Fixes.Select(f => f.Action)).ToImmutableArray(); Assert.Equal(7, codeActions.Length); var uniqueTitles = new HashSet(); @@ -152,14 +152,14 @@ public async Task TestGetFixesAsyncForFixableAndNonFixableAnalyzersAsync() // Verify only analyzerWithFix is executed when GetFixesAsync is invoked with 'CodeActionRequestPriority.Normal'. _ = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), - priority: CodeActionRequestPriority.Normal, options, + priority: CodeActionRequestPriority.Normal, _ => options, addOperationScope: _ => null, cancellationToken: CancellationToken.None); Assert.True(analyzerWithFix.ReceivedCallback); Assert.False(analyzerWithoutFix.ReceivedCallback); // Verify both analyzerWithFix and analyzerWithoutFix are executed when GetFixesAsync is invoked with 'CodeActionRequestPriority.Lowest'. _ = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), - priority: CodeActionRequestPriority.Lowest, options, + priority: CodeActionRequestPriority.Lowest, _ => options, addOperationScope: _ => null, cancellationToken: CancellationToken.None); Assert.True(analyzerWithFix.ReceivedCallback); Assert.True(analyzerWithoutFix.ReceivedCallback); @@ -190,7 +190,7 @@ public async Task TestGetFixesAsyncForDocumentDiagnosticAnalyzerAsync() var options = CodeActionOptions.Default; _ = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), - priority: CodeActionRequestPriority.Normal, options, + priority: CodeActionRequestPriority.Normal, _ => options, addOperationScope: _ => null, cancellationToken: CancellationToken.None); Assert.True(documentDiagnosticAnalyzer.ReceivedCallback); } @@ -275,7 +275,7 @@ private static async Task> GetAddedFixesAsync( var project = workspace.CurrentSolution.Projects.Single().AddAnalyzerReference(reference); document = project.Documents.Single(); var options = CodeActionOptions.Default; - var fixes = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), options, CancellationToken.None); + var fixes = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), _ => options, CancellationToken.None); if (exception) { @@ -300,7 +300,7 @@ private static async Task GetFirstDiagnosticWithFixWithExceptionValidationAsync( GetDocumentAndExtensionManager(tuple.analyzerService, workspace, out var document, out var extensionManager); var unused = await tuple.codeFixService.GetMostSevereFixAsync( - document, TextSpan.FromBounds(0, 0), CodeActionRequestPriority.None, CodeActionOptions.Default, CancellationToken.None); + document, TextSpan.FromBounds(0, 0), CodeActionRequestPriority.None, _ => CodeActionOptions.Default, CancellationToken.None); Assert.True(extensionManager.IsDisabled(codefix)); Assert.False(extensionManager.IsIgnored(codefix)); Assert.True(errorReported); @@ -692,7 +692,7 @@ private static async Task> GetNuGetAndVsixCode var document = project.Documents.Single(); var options = CodeActionOptions.Default; - return await fixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), options, CancellationToken.None); + return await fixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), _ => options, CancellationToken.None); } private sealed class NuGetCodeFixProvider : AbstractNuGetOrVsixCodeFixProvider diff --git a/src/EditorFeatures/Test/CodeRefactorings/CodeRefactoringServiceTest.cs b/src/EditorFeatures/Test/CodeRefactorings/CodeRefactoringServiceTest.cs index 43d84445e200f..26631818d7ff2 100644 --- a/src/EditorFeatures/Test/CodeRefactorings/CodeRefactoringServiceTest.cs +++ b/src/EditorFeatures/Test/CodeRefactorings/CodeRefactoringServiceTest.cs @@ -45,7 +45,7 @@ public async Task TestProjectRefactoringAsync() var project = workspace.CurrentSolution.Projects.Single().AddAnalyzerReference(reference); var document = project.Documents.Single(); var options = CodeActionOptions.Default; - var refactorings = await refactoringService.GetRefactoringsAsync(document, TextSpan.FromBounds(0, 0), options, CancellationToken.None); + var refactorings = await refactoringService.GetRefactoringsAsync(document, TextSpan.FromBounds(0, 0), _ => options, CancellationToken.None); var stubRefactoringAction = refactorings.Single(refactoring => refactoring.CodeActions.FirstOrDefault().action?.Title == nameof(StubRefactoring)); Assert.True(stubRefactoringAction is object); @@ -69,7 +69,7 @@ private static async Task VerifyRefactoringDisabledAsync() var document = project.Documents.Single(); var extensionManager = (EditorLayerExtensionManager.ExtensionManager)document.Project.Solution.Workspace.Services.GetRequiredService(); var options = CodeActionOptions.Default; - var result = await refactoringService.GetRefactoringsAsync(document, TextSpan.FromBounds(0, 0), options, CancellationToken.None); + var result = await refactoringService.GetRefactoringsAsync(document, TextSpan.FromBounds(0, 0), _ => options, CancellationToken.None); Assert.True(extensionManager.IsDisabled(codeRefactoring)); Assert.False(extensionManager.IsIgnored(codeRefactoring)); diff --git a/src/EditorFeatures/Test2/CodeFixes/CodeFixServiceTests.vb b/src/EditorFeatures/Test2/CodeFixes/CodeFixServiceTests.vb index cc37902c4d5e1..bfd0869878f87 100644 --- a/src/EditorFeatures/Test2/CodeFixes/CodeFixServiceTests.vb +++ b/src/EditorFeatures/Test2/CodeFixes/CodeFixServiceTests.vb @@ -77,7 +77,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests Dim fixes = Await codefixService.GetFixesAsync( document, (Await document.GetSyntaxRootAsync()).FullSpan, - options, + Function(language) options, CancellationToken.None) Assert.Equal(0, fixes.Count()) @@ -93,7 +93,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests fixes = Await codefixService.GetFixesAsync( document, (Await document.GetSyntaxRootAsync()).FullSpan, - options, + Function(language) options, CancellationToken.None) Assert.Equal(1, fixes.Count()) @@ -103,7 +103,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests fixes = Await codefixService.GetFixesAsync( document, (Await document.GetSyntaxRootAsync()).FullSpan, - options, + Function(language) options, CancellationToken.None) Assert.Equal(0, fixes.Count()) @@ -154,7 +154,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests Dim fixes = Await codefixService.GetFixesAsync( document, (Await document.GetSyntaxRootAsync()).FullSpan, - options, + Function(language) options, CancellationToken.None) Assert.Equal(0, fixes.Count()) @@ -170,7 +170,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests fixes = Await codefixService.GetFixesAsync( document, (Await document.GetSyntaxRootAsync()).FullSpan, - options, + Function(language) options, CancellationToken.None) Assert.Equal(0, fixes.Count()) diff --git a/src/EditorFeatures/Test2/SyncNamespaces/SyncNamespacesServiceTests.vb b/src/EditorFeatures/Test2/SyncNamespaces/SyncNamespacesServiceTests.vb index 19e4ca34cac16..ec88c170c044a 100644 --- a/src/EditorFeatures/Test2/SyncNamespaces/SyncNamespacesServiceTests.vb +++ b/src/EditorFeatures/Test2/SyncNamespaces/SyncNamespacesServiceTests.vb @@ -40,7 +40,7 @@ namespace Test.Namespace.App Dim document = project.Documents.Single() Dim syncService = project.GetLanguageService(Of ISyncNamespacesService)() - Dim newSolution = Await syncService.SyncNamespacesAsync(ImmutableArray.Create(project), CodeActionOptions.Default, CancellationToken.None) + Dim newSolution = Await syncService.SyncNamespacesAsync(ImmutableArray.Create(project), Function(language) CodeActionOptions.Default, CancellationToken.None) Dim solutionChanges = workspace.CurrentSolution.GetChanges(newSolution) @@ -76,7 +76,7 @@ namespace Test Dim document = project.Documents.Single() Dim syncService = project.GetLanguageService(Of ISyncNamespacesService)() - Dim newSolution = Await syncService.SyncNamespacesAsync(projects, CodeActionOptions.Default, CancellationToken.None) + Dim newSolution = Await syncService.SyncNamespacesAsync(projects, Function(language) CodeActionOptions.Default, CancellationToken.None) Dim solutionChanges = workspace.CurrentSolution.GetChanges(newSolution) Dim projectChanges = solutionChanges.GetProjectChanges().Single() @@ -133,7 +133,7 @@ namespace Test2.Namespace.App Dim project = projects(0) Dim syncService = project.GetLanguageService(Of ISyncNamespacesService)() - Dim newSolution = Await syncService.SyncNamespacesAsync(projects, CodeActionOptions.Default, CancellationToken.None) + Dim newSolution = Await syncService.SyncNamespacesAsync(projects, Function(language) CodeActionOptions.Default, CancellationToken.None) Dim solutionChanges = workspace.CurrentSolution.GetChanges(newSolution) @@ -187,7 +187,7 @@ namespace Test2.Namespace.App Dim document = project.Documents.Single() Dim syncService = project.GetLanguageService(Of ISyncNamespacesService)() - Dim newSolution = Await syncService.SyncNamespacesAsync(projects, CodeActionOptions.Default, CancellationToken.None) + Dim newSolution = Await syncService.SyncNamespacesAsync(projects, Function(language) CodeActionOptions.Default, CancellationToken.None) Dim solutionChanges = workspace.CurrentSolution.GetChanges(newSolution) Dim projectChanges = solutionChanges.GetProjectChanges().Single() @@ -252,7 +252,7 @@ namespace Test2.Namespace Dim document2 = project2.Documents.Single() Dim syncService = project.GetLanguageService(Of ISyncNamespacesService)() - Dim newSolution = Await syncService.SyncNamespacesAsync(projects, CodeActionOptions.Default, CancellationToken.None) + Dim newSolution = Await syncService.SyncNamespacesAsync(projects, Function(language) CodeActionOptions.Default, CancellationToken.None) Dim solutionChanges = workspace.CurrentSolution.GetChanges(newSolution) Dim projectChanges = solutionChanges.GetProjectChanges().ToImmutableArray() diff --git a/src/EditorFeatures/VisualBasicTest/Formatting/CodeCleanUpTests.vb b/src/EditorFeatures/VisualBasicTest/Formatting/CodeCleanUpTests.vb index 52a83d318c9f8..060c2eae8e2c1 100644 --- a/src/EditorFeatures/VisualBasicTest/Formatting/CodeCleanUpTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Formatting/CodeCleanUpTests.vb @@ -365,7 +365,7 @@ End Class document, enabledDiagnostics, New ProgressTracker, - options, + Function(language) options, formattingOptions, CancellationToken.None) diff --git a/src/Features/CSharp/Portable/ImplementInterface/CSharpImplementInterfaceCodeFixProvider.cs b/src/Features/CSharp/Portable/ImplementInterface/CSharpImplementInterfaceCodeFixProvider.cs index 34e68a1f1bd02..676af4f7ba025 100644 --- a/src/Features/CSharp/Portable/ImplementInterface/CSharpImplementInterfaceCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/ImplementInterface/CSharpImplementInterfaceCodeFixProvider.cs @@ -54,7 +54,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) var actions = token.Parent.GetAncestorsOrThis() .Where(_interfaceName) - .Select(n => service.GetCodeActions(document, context.Options.ImplementTypeOptions, model, n, cancellationToken)) + .Select(n => service.GetCodeActions(document, context.Options(document.Project.Language).ImplementTypeOptions, model, n, cancellationToken)) .FirstOrDefault(a => !a.IsEmpty); if (actions.IsDefaultOrEmpty) diff --git a/src/Features/Core/Portable/AddImport/AbstractAddImportCodeFixProvider.cs b/src/Features/Core/Portable/AddImport/AbstractAddImportCodeFixProvider.cs index 25fcf19a4d6f3..2d12603c7e556 100644 --- a/src/Features/Core/Portable/AddImport/AbstractAddImportCodeFixProvider.cs +++ b/src/Features/Core/Portable/AddImport/AbstractAddImportCodeFixProvider.cs @@ -55,7 +55,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) var addImportService = document.GetRequiredLanguageService(); var services = document.Project.Solution.Workspace.Services; - var searchOptions = context.Options.SearchOptions; + var searchOptions = context.Options(document.Project.Language).SearchOptions; var symbolSearchService = _symbolSearchService ?? services.GetRequiredService(); @@ -75,7 +75,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) var addImportOptions = new AddImportOptions( searchOptions, - context.Options.HideAdvancedMembers, + context.Options(document.Project.Language).HideAdvancedMembers, placement); var fixesForDiagnostic = await addImportService.GetFixesForDiagnosticsAsync( diff --git a/src/Features/Core/Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs b/src/Features/Core/Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs index 376f536c68e23..94c8901b70553 100644 --- a/src/Features/Core/Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs +++ b/src/Features/Core/Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs @@ -52,7 +52,7 @@ protected async Task> GetAddPackagesCodeActionsAsync( var codeActions = ArrayBuilder.GetInstance(); if (symbolSearchService != null && installerService != null && - context.Options.SearchOptions.SearchNuGetPackages && + context.Options(document.Project.Language).SearchOptions.SearchNuGetPackages && installerService.IsEnabled(document.Project.Id)) { var packageSources = PackageSourceHelper.GetPackageSources(installerService.TryGetPackageSources()); diff --git a/src/Features/Core/Portable/CodeRefactorings/AddMissingImports/AbstractAddMissingImportsRefactoringProvider.cs b/src/Features/Core/Portable/CodeRefactorings/AddMissingImports/AbstractAddMissingImportsRefactoringProvider.cs index b7f78d536b1ea..df26d9b289e2b 100644 --- a/src/Features/Core/Portable/CodeRefactorings/AddMissingImports/AbstractAddMissingImportsRefactoringProvider.cs +++ b/src/Features/Core/Portable/CodeRefactorings/AddMissingImports/AbstractAddMissingImportsRefactoringProvider.cs @@ -40,7 +40,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte var addMissingImportsService = document.GetLanguageService(); var placement = await AddImportPlacementOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); - var options = new AddMissingImportsOptions(context.Options.HideAdvancedMembers, placement); + var options = new AddMissingImportsOptions(context.Options(document.Project.Language).HideAdvancedMembers, placement); var analysis = await addMissingImportsService.AnalyzeAsync(document, textSpan, options, cancellationToken).ConfigureAwait(false); if (!analysis.CanAddMissingImports) diff --git a/src/Features/Core/Portable/CodeRefactorings/CodeRefactoringService.cs b/src/Features/Core/Portable/CodeRefactorings/CodeRefactoringService.cs index 66211617436c9..fd5b54aa4c790 100644 --- a/src/Features/Core/Portable/CodeRefactorings/CodeRefactoringService.cs +++ b/src/Features/Core/Portable/CodeRefactorings/CodeRefactoringService.cs @@ -84,7 +84,7 @@ private ConcatImmutableArray GetProviders(Document docu public async Task HasRefactoringsAsync( Document document, TextSpan state, - CodeActionOptions options, + CodeActionOptionsProvider options, CancellationToken cancellationToken) { var extensionManager = document.Project.Solution.Workspace.Services.GetRequiredService(); @@ -110,7 +110,7 @@ public async Task> GetRefactoringsAsync( Document document, TextSpan state, CodeActionRequestPriority priority, - CodeActionOptions options, + CodeActionOptionsProvider options, Func addOperationScope, CancellationToken cancellationToken) { @@ -149,7 +149,7 @@ public async Task> GetRefactoringsAsync( CodeRefactoringProvider provider, CodeChangeProviderMetadata? providerMetadata, IExtensionManager extensionManager, - CodeActionOptions options, + CodeActionOptionsProvider options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/Features/Core/Portable/CodeRefactorings/ExtractMethod/AbstractExtractMethodCodeRefactoringProvider.cs b/src/Features/Core/Portable/CodeRefactorings/ExtractMethod/AbstractExtractMethodCodeRefactoringProvider.cs index f06b818d280c8..aae685a87be61 100644 --- a/src/Features/Core/Portable/CodeRefactorings/ExtractMethod/AbstractExtractMethodCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/CodeRefactorings/ExtractMethod/AbstractExtractMethodCodeRefactoringProvider.cs @@ -56,7 +56,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte return; } - var options = context.Options.ExtractMethodOptions; + var options = context.Options(document.Project.Language).ExtractMethodOptions; var actions = await GetCodeActionsAsync(document, textSpan, options, cancellationToken).ConfigureAwait(false); context.RegisterRefactorings(actions); } diff --git a/src/Features/Core/Portable/CodeRefactorings/ICodeRefactoringService.cs b/src/Features/Core/Portable/CodeRefactorings/ICodeRefactoringService.cs index 0e43a48d39e56..2bae2385a216f 100644 --- a/src/Features/Core/Portable/CodeRefactorings/ICodeRefactoringService.cs +++ b/src/Features/Core/Portable/CodeRefactorings/ICodeRefactoringService.cs @@ -13,14 +13,14 @@ namespace Microsoft.CodeAnalysis.CodeRefactorings { internal interface ICodeRefactoringService { - Task HasRefactoringsAsync(Document document, TextSpan textSpan, CodeActionOptions options, CancellationToken cancellationToken); + Task HasRefactoringsAsync(Document document, TextSpan textSpan, CodeActionOptionsProvider options, CancellationToken cancellationToken); - Task> GetRefactoringsAsync(Document document, TextSpan textSpan, CodeActionRequestPriority priority, CodeActionOptions options, Func addOperationScope, CancellationToken cancellationToken); + Task> GetRefactoringsAsync(Document document, TextSpan textSpan, CodeActionRequestPriority priority, CodeActionOptionsProvider options, Func addOperationScope, CancellationToken cancellationToken); } internal static class ICodeRefactoringServiceExtensions { - public static Task> GetRefactoringsAsync(this ICodeRefactoringService service, Document document, TextSpan state, CodeActionOptions options, CancellationToken cancellationToken) + public static Task> GetRefactoringsAsync(this ICodeRefactoringService service, Document document, TextSpan state, CodeActionOptionsProvider options, CancellationToken cancellationToken) => service.GetRefactoringsAsync(document, state, CodeActionRequestPriority.None, options, addOperationScope: _ => null, cancellationToken); } } diff --git a/src/Features/Core/Portable/FullyQualify/AbstractFullyQualifyCodeFixProvider.cs b/src/Features/Core/Portable/FullyQualify/AbstractFullyQualifyCodeFixProvider.cs index 9fb65c4415f99..6b7f4a4bb3cf6 100644 --- a/src/Features/Core/Portable/FullyQualify/AbstractFullyQualifyCodeFixProvider.cs +++ b/src/Features/Core/Portable/FullyQualify/AbstractFullyQualifyCodeFixProvider.cs @@ -63,7 +63,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) return; } - var hideAdvancedMembers = context.Options.HideAdvancedMembers; + var hideAdvancedMembers = context.Options(document.Project.Language).HideAdvancedMembers; var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); var matchingTypes = await GetMatchingTypesAsync(document, semanticModel, node, hideAdvancedMembers, cancellationToken).ConfigureAwait(false); diff --git a/src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs b/src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs index 6ffd69cef3acb..b15c4fd3d2640 100644 --- a/src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs +++ b/src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs @@ -42,7 +42,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) return; var data = await ImplementAbstractClassData.TryGetDataAsync( - document, classNode, GetClassIdentifier(classNode), context.Options.ImplementTypeOptions, cancellationToken).ConfigureAwait(false); + document, classNode, GetClassIdentifier(classNode), context.Options(document.Project.Language).ImplementTypeOptions, cancellationToken).ConfigureAwait(false); if (data == null) return; diff --git a/src/Features/Core/Portable/SpellCheck/AbstractSpellCheckCodeFixProvider.cs b/src/Features/Core/Portable/SpellCheck/AbstractSpellCheckCodeFixProvider.cs index e2dca078ac380..d2752c63438fc 100644 --- a/src/Features/Core/Portable/SpellCheck/AbstractSpellCheckCodeFixProvider.cs +++ b/src/Features/Core/Portable/SpellCheck/AbstractSpellCheckCodeFixProvider.cs @@ -118,7 +118,7 @@ private async Task CreateSpellCheckCodeIssueAsync( // - We believe spell-check should only compare what you have typed to what symbol would be offered here. var options = CompletionOptions.Default with { - HideAdvancedMembers = context.Options.HideAdvancedMembers, + HideAdvancedMembers = context.Options(document.Project.Language).HideAdvancedMembers, SnippetsBehavior = SnippetsRule.NeverInclude, ShowItemsFromUnimportedNamespaces = false, TargetTypedCompletionFilter = false, diff --git a/src/Features/Core/Portable/SyncNamespaces/AbstractSyncNamespacesSevice.cs b/src/Features/Core/Portable/SyncNamespaces/AbstractSyncNamespacesSevice.cs index 7be9e5ac3a36d..8c416119c0c31 100644 --- a/src/Features/Core/Portable/SyncNamespaces/AbstractSyncNamespacesSevice.cs +++ b/src/Features/Core/Portable/SyncNamespaces/AbstractSyncNamespacesSevice.cs @@ -30,7 +30,7 @@ internal abstract class AbstractSyncNamespacesSevice public async Task SyncNamespacesAsync( ImmutableArray projects, - CodeActionOptions options, + CodeActionOptionsProvider options, CancellationToken cancellationToken) { // all projects must be of the same language @@ -92,7 +92,7 @@ private static async Task GetFixAllContextAsync( Solution solution, CodeFixProvider codeFixProvider, ImmutableDictionary> diagnosticsByProject, - CodeActionOptions options, + CodeActionOptionsProvider options, CancellationToken cancellationToken) { var diagnosticProvider = new DiagnosticProvider(diagnosticsByProject); @@ -126,7 +126,7 @@ private static async Task GetFixAllContextAsync( codeActionEquivalenceKey: action?.EquivalenceKey!, // FixAllState supports null equivalence key. This should still be supported. diagnosticIds: codeFixProvider.FixableDiagnosticIds, fixAllDiagnosticProvider: diagnosticProvider, - _ => options), + options), new ProgressTracker(), cancellationToken); } diff --git a/src/Features/Core/Portable/SyncNamespaces/ISyncNamespacesService.cs b/src/Features/Core/Portable/SyncNamespaces/ISyncNamespacesService.cs index a408b4f60b5c7..25b6accc6c5ba 100644 --- a/src/Features/Core/Portable/SyncNamespaces/ISyncNamespacesService.cs +++ b/src/Features/Core/Portable/SyncNamespaces/ISyncNamespacesService.cs @@ -16,6 +16,6 @@ internal interface ISyncNamespacesService : ILanguageService /// This will update documents in the specified projects so that their namespace matches the RootNamespace /// and their relative folder path. /// - Task SyncNamespacesAsync(ImmutableArray projects, CodeActionOptions options, CancellationToken cancellationToken); + Task SyncNamespacesAsync(ImmutableArray projects, CodeActionOptionsProvider options, CancellationToken cancellationToken); } } diff --git a/src/Features/Core/Portable/Wrapping/AbstractWrappingCodeRefactoringProvider.cs b/src/Features/Core/Portable/Wrapping/AbstractWrappingCodeRefactoringProvider.cs index e252c490e5dd1..f0e74dbfd704b 100644 --- a/src/Features/Core/Portable/Wrapping/AbstractWrappingCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/Wrapping/AbstractWrappingCodeRefactoringProvider.cs @@ -45,7 +45,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte var token = root.FindToken(position); var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); - var options = GetWrappingOptions(configOptions, context.Options); + var options = GetWrappingOptions(configOptions, context.Options(document.Project.Language)); foreach (var node in token.GetRequiredParent().AncestorsAndSelf()) { diff --git a/src/Features/LanguageServer/Protocol/Features/CodeCleanup/AbstractCodeCleanupService.cs b/src/Features/LanguageServer/Protocol/Features/CodeCleanup/AbstractCodeCleanupService.cs index 869c6252a9aee..e33dc3fa44493 100644 --- a/src/Features/LanguageServer/Protocol/Features/CodeCleanup/AbstractCodeCleanupService.cs +++ b/src/Features/LanguageServer/Protocol/Features/CodeCleanup/AbstractCodeCleanupService.cs @@ -33,7 +33,7 @@ public async Task CleanupAsync( Document document, EnabledDiagnosticOptions enabledDiagnostics, IProgressTracker progressTracker, - CodeActionOptions options, + CodeActionOptionsProvider options, SyntaxFormattingOptions formattingOptions, CancellationToken cancellationToken) { @@ -104,7 +104,7 @@ private static async Task RemoveSortUsingsAsync( private async Task ApplyCodeFixesAsync( Document document, ImmutableArray enabledDiagnosticSets, - IProgressTracker progressTracker, CodeActionOptions options, CancellationToken cancellationToken) + IProgressTracker progressTracker, CodeActionOptionsProvider options, CancellationToken cancellationToken) { // Add a progress item for each enabled option we're going to fixup. progressTracker.AddItems(enabledDiagnosticSets.Length); @@ -125,7 +125,7 @@ private async Task ApplyCodeFixesAsync( } private async Task ApplyCodeFixesForSpecificDiagnosticIdsAsync( - Document document, ImmutableArray diagnosticIds, IProgressTracker progressTracker, CodeActionOptions options, CancellationToken cancellationToken) + Document document, ImmutableArray diagnosticIds, IProgressTracker progressTracker, CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnosticId in diagnosticIds) { @@ -139,7 +139,7 @@ private async Task ApplyCodeFixesForSpecificDiagnosticIdsAsync( return document; } - private async Task ApplyCodeFixesForSpecificDiagnosticIdAsync(Document document, string diagnosticId, IProgressTracker progressTracker, CodeActionOptions options, CancellationToken cancellationToken) + private async Task ApplyCodeFixesForSpecificDiagnosticIdAsync(Document document, string diagnosticId, IProgressTracker progressTracker, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var tree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var textSpan = new TextSpan(0, tree.Length); diff --git a/src/Features/LanguageServer/Protocol/Features/CodeCleanup/ICodeCleanupService.cs b/src/Features/LanguageServer/Protocol/Features/CodeCleanup/ICodeCleanupService.cs index f4f09fde674be..970ea7f08dd7f 100644 --- a/src/Features/LanguageServer/Protocol/Features/CodeCleanup/ICodeCleanupService.cs +++ b/src/Features/LanguageServer/Protocol/Features/CodeCleanup/ICodeCleanupService.cs @@ -13,7 +13,7 @@ namespace Microsoft.CodeAnalysis.CodeCleanup { internal interface ICodeCleanupService : ILanguageService { - Task CleanupAsync(Document document, EnabledDiagnosticOptions enabledDiagnostics, IProgressTracker progressTracker, CodeActionOptions options, SyntaxFormattingOptions formattingOptions, CancellationToken cancellationToken); + Task CleanupAsync(Document document, EnabledDiagnosticOptions enabledDiagnostics, IProgressTracker progressTracker, CodeActionOptionsProvider options, SyntaxFormattingOptions formattingOptions, CancellationToken cancellationToken); EnabledDiagnosticOptions GetAllDiagnostics(); } } diff --git a/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.cs b/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.cs index a6a97a32601fc..28ba566834b18 100644 --- a/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.cs +++ b/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.cs @@ -98,7 +98,7 @@ public CodeFixService( } public async Task GetMostSevereFixAsync( - Document document, TextSpan range, CodeActionRequestPriority priority, CodeActionOptions options, CancellationToken cancellationToken) + Document document, TextSpan range, CodeActionRequestPriority priority, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var (allDiagnostics, upToDate) = await _diagnosticService.TryGetDiagnosticsForSpanAsync( document, range, GetShouldIncludeDiagnosticPredicate(document, priority), @@ -155,7 +155,7 @@ public async IAsyncEnumerable StreamFixesAsync( Document document, TextSpan range, CodeActionRequestPriority priority, - CodeActionOptions options, + CodeActionOptionsProvider options, Func addOperationScope, [EnumeratorCancellation] CancellationToken cancellationToken) { @@ -231,7 +231,7 @@ private static SortedDictionary> ConvertToMap( } public async Task GetDocumentFixAllForIdInSpanAsync( - Document document, TextSpan range, string diagnosticId, CodeActionOptions options, CancellationToken cancellationToken) + Document document, TextSpan range, string diagnosticId, CodeActionOptionsProvider options, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -326,7 +326,7 @@ private async IAsyncEnumerable StreamFixesAsync( SortedDictionary> spanToDiagnostics, bool fixAllForInSpan, CodeActionRequestPriority priority, - CodeActionOptions options, + CodeActionOptionsProvider options, Func addOperationScope, [EnumeratorCancellation] CancellationToken cancellationToken) { @@ -489,7 +489,7 @@ void AddAllFixers( } private static async Task> GetCodeFixesAsync( - Document document, TextSpan span, CodeFixProvider fixer, CodeChangeProviderMetadata? fixerMetadata, CodeActionOptions options, + Document document, TextSpan span, CodeFixProvider fixer, CodeChangeProviderMetadata? fixerMetadata, CodeActionOptionsProvider options, ImmutableArray diagnostics, Dictionary> uniqueDiagosticToEquivalenceKeysMap, Dictionary<(Diagnostic diagnostic, string? equivalenceKey), CodeFixProvider> diagnosticAndEquivalenceKeyToFixersMap, @@ -574,7 +574,7 @@ private async IAsyncEnumerable StreamConfigurationFixesAsync( TextSpan diagnosticsSpan, IEnumerable diagnostics, PooledHashSet registeredConfigurationFixTitles, - CodeActionOptions options, + CodeActionOptionsProvider options, [EnumeratorCancellation] CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -614,7 +614,7 @@ private async IAsyncEnumerable StreamConfigurationFixesAsync( TCodeFixProvider fixer, Func hasFix, Func, Task>> getFixes, - CodeActionOptions options, + CodeActionOptionsProvider options, CancellationToken cancellationToken) where TCodeFixProvider : notnull { @@ -666,11 +666,7 @@ await diagnosticsWithSameSpan.OrderByDescending(d => d.Severity) fixes[0].Action.EquivalenceKey, diagnosticIds, diagnosticProvider, - codeActionOptionsProvider: language => - { - Contract.ThrowIfFalse(language == document.Project.Language); - return options; - }); + options); supportedScopes = fixAllProviderInfo.SupportedScopes; } diff --git a/src/Features/LanguageServer/Protocol/Features/CodeFixes/ICodeFixService.cs b/src/Features/LanguageServer/Protocol/Features/CodeFixes/ICodeFixService.cs index 381d37b9a6639..0a872e0815ebe 100644 --- a/src/Features/LanguageServer/Protocol/Features/CodeFixes/ICodeFixService.cs +++ b/src/Features/LanguageServer/Protocol/Features/CodeFixes/ICodeFixService.cs @@ -16,28 +16,28 @@ namespace Microsoft.CodeAnalysis.CodeFixes { internal interface ICodeFixService { - IAsyncEnumerable StreamFixesAsync(Document document, TextSpan textSpan, CodeActionRequestPriority priority, CodeActionOptions options, Func addOperationScope, CancellationToken cancellationToken); + IAsyncEnumerable StreamFixesAsync(Document document, TextSpan textSpan, CodeActionRequestPriority priority, CodeActionOptionsProvider options, Func addOperationScope, CancellationToken cancellationToken); /// /// Similar to except that instead of streaming all results, this ends with the /// first. This will also attempt to return a fix for an error first, but will fall back to any fix if that /// does not succeed. /// - Task GetMostSevereFixAsync(Document document, TextSpan range, CodeActionRequestPriority priority, CodeActionOptions options, CancellationToken cancellationToken); + Task GetMostSevereFixAsync(Document document, TextSpan range, CodeActionRequestPriority priority, CodeActionOptionsProvider options, CancellationToken cancellationToken); - Task GetDocumentFixAllForIdInSpanAsync(Document document, TextSpan textSpan, string diagnosticId, CodeActionOptions options, CancellationToken cancellationToken); + Task GetDocumentFixAllForIdInSpanAsync(Document document, TextSpan textSpan, string diagnosticId, CodeActionOptionsProvider options, CancellationToken cancellationToken); CodeFixProvider? GetSuppressionFixer(string language, IEnumerable diagnosticIds); } internal static class ICodeFixServiceExtensions { - public static IAsyncEnumerable StreamFixesAsync(this ICodeFixService service, Document document, TextSpan range, CodeActionOptions options, CancellationToken cancellationToken) + public static IAsyncEnumerable StreamFixesAsync(this ICodeFixService service, Document document, TextSpan range, CodeActionOptionsProvider options, CancellationToken cancellationToken) => service.StreamFixesAsync(document, range, CodeActionRequestPriority.None, options, addOperationScope: _ => null, cancellationToken); - public static Task> GetFixesAsync(this ICodeFixService service, Document document, TextSpan range, CodeActionOptions options, CancellationToken cancellationToken) + public static Task> GetFixesAsync(this ICodeFixService service, Document document, TextSpan range, CodeActionOptionsProvider options, CancellationToken cancellationToken) => service.StreamFixesAsync(document, range, options, cancellationToken).ToImmutableArrayAsync(cancellationToken); - public static Task> GetFixesAsync(this ICodeFixService service, Document document, TextSpan textSpan, CodeActionRequestPriority priority, CodeActionOptions options, Func addOperationScope, CancellationToken cancellationToken) + public static Task> GetFixesAsync(this ICodeFixService service, Document document, TextSpan textSpan, CodeActionRequestPriority priority, CodeActionOptionsProvider options, Func addOperationScope, CancellationToken cancellationToken) => service.StreamFixesAsync(document, textSpan, priority, options, addOperationScope, cancellationToken).ToImmutableArrayAsync(cancellationToken); } } diff --git a/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActionsSource.cs b/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActionsSource.cs index 2a71deeebb727..488b5a9656ebe 100644 --- a/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActionsSource.cs +++ b/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActionsSource.cs @@ -36,7 +36,7 @@ public static async ValueTask> GetFilt Document document, TextSpan selection, CodeActionRequestPriority priority, - CodeActionOptions options, + CodeActionOptionsProvider options, Func addOperationScope, CancellationToken cancellationToken) { @@ -411,7 +411,7 @@ public static async Task> GetFilterAnd Document document, TextSpan selection, CodeActionRequestPriority priority, - CodeActionOptions options, + CodeActionOptionsProvider options, Func addOperationScope, bool filterOutsideSelection, CancellationToken cancellationToken) diff --git a/src/Features/VisualBasic/Portable/ImplementInterface/VisualBasicImplementInterfaceCodeFixProvider.vb b/src/Features/VisualBasic/Portable/ImplementInterface/VisualBasicImplementInterfaceCodeFixProvider.vb index 07412631d3d9c..41e153d3a8c24 100644 --- a/src/Features/VisualBasic/Portable/ImplementInterface/VisualBasicImplementInterfaceCodeFixProvider.vb +++ b/src/Features/VisualBasic/Portable/ImplementInterface/VisualBasicImplementInterfaceCodeFixProvider.vb @@ -61,7 +61,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ImplementInterface Dim service = document.GetLanguageService(Of IImplementInterfaceService)() Dim actions = service.GetCodeActions( document, - context.Options.ImplementTypeOptions, + context.Options(document.Project.Language).ImplementTypeOptions, Await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(False), typeNode, cancellationToken) diff --git a/src/Tools/ExternalAccess/OmniSharp/CodeActions/OmniSharpCodeFixContextFactory.cs b/src/Tools/ExternalAccess/OmniSharp/CodeActions/OmniSharpCodeFixContextFactory.cs index 091695050adb7..65dc921a7f9f3 100644 --- a/src/Tools/ExternalAccess/OmniSharp/CodeActions/OmniSharpCodeFixContextFactory.cs +++ b/src/Tools/ExternalAccess/OmniSharp/CodeActions/OmniSharpCodeFixContextFactory.cs @@ -23,7 +23,7 @@ public static CodeFixContext CreateCodeFixContext( Action> registerCodeFix, OmniSharpCodeActionOptions options, CancellationToken cancellationToken) - => new(document, span, diagnostics, registerCodeFix, options.GetCodeActionOptions(), cancellationToken); + => new(document, span, diagnostics, registerCodeFix, _ => options.GetCodeActionOptions(), cancellationToken); public static CodeRefactoringContext CreateCodeRefactoringContext( Document document, @@ -31,7 +31,7 @@ public static CodeRefactoringContext CreateCodeRefactoringContext( Action registerRefactoring, OmniSharpCodeActionOptions options, CancellationToken cancellationToken) - => new(document, span, registerRefactoring, options.GetCodeActionOptions(), cancellationToken); + => new(document, span, registerRefactoring, _ => options.GetCodeActionOptions(), cancellationToken); public static FixAllContext CreateFixAllContext( Document? document, diff --git a/src/VisualStudio/Core/Def/CodeCleanup/AbstractCodeCleanUpFixer.cs b/src/VisualStudio/Core/Def/CodeCleanup/AbstractCodeCleanUpFixer.cs index 262cf75512eec..f235a0fc5db71 100644 --- a/src/VisualStudio/Core/Def/CodeCleanup/AbstractCodeCleanUpFixer.cs +++ b/src/VisualStudio/Core/Def/CodeCleanup/AbstractCodeCleanUpFixer.cs @@ -355,7 +355,7 @@ private static async Task FixDocumentAsync( var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); return await codeCleanupService.CleanupAsync( - document, enabledDiagnostics, progressTracker, ideOptions, formattingOptions, cancellationToken).ConfigureAwait(false); + document, enabledDiagnostics, progressTracker, _ => ideOptions, formattingOptions, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/VisualStudio/Core/Def/SyncNamespaces/SyncNamespacesCommandHandler.cs b/src/VisualStudio/Core/Def/SyncNamespaces/SyncNamespacesCommandHandler.cs index b5b17572123e8..42862d66cca04 100644 --- a/src/VisualStudio/Core/Def/SyncNamespaces/SyncNamespacesCommandHandler.cs +++ b/src/VisualStudio/Core/Def/SyncNamespaces/SyncNamespacesCommandHandler.cs @@ -132,7 +132,7 @@ private void SyncNamespaces(ImmutableArray projects) } var syncService = projects[0].GetRequiredLanguageService(); - var options = _globalOptions.GetCodeActionOptions(projects[0].Language); + var options = _globalOptions.GetCodeActionOptionsProvider(); Solution? solution = null; var status = _threadOperationExecutor.Execute(ServicesVSResources.Sync_Namespaces, ServicesVSResources.Updating_namspaces, allowCancellation: true, showProgress: true, (operationContext) => diff --git a/src/Workspaces/Core/Portable/CodeFixes/CodeFixContext.cs b/src/Workspaces/Core/Portable/CodeFixes/CodeFixContext.cs index 47a020c75426f..62ebe6c86ce69 100644 --- a/src/Workspaces/Core/Portable/CodeFixes/CodeFixContext.cs +++ b/src/Workspaces/Core/Portable/CodeFixes/CodeFixContext.cs @@ -16,7 +16,9 @@ namespace Microsoft.CodeAnalysis.CodeFixes /// /// Context for code fixes provided by a . /// +#pragma warning disable CS0612 // Type or member is obsolete public readonly struct CodeFixContext : ITypeScriptCodeFixContext +#pragma warning restore { private readonly Document _document; private readonly TextSpan _span; @@ -45,8 +47,17 @@ namespace Microsoft.CodeAnalysis.CodeFixes /// public CancellationToken CancellationToken => _cancellationToken; - internal readonly CodeActionOptions Options; - bool ITypeScriptCodeFixContext.IsBlocking => Options.IsBlocking; + /// + /// IDE supplied options to use for settings not specified in the corresponding editorconfig file. + /// + /// + /// Provider to allow code fix to update documents across multiple projects that differ in language (and hence language specific options). + /// + internal readonly CodeActionOptionsProvider Options; + + [Obsolete] + bool ITypeScriptCodeFixContext.IsBlocking + => Options("TypeScript").IsBlocking; /// /// Creates a code fix context to be passed into method. @@ -75,7 +86,7 @@ public CodeFixContext( span, VerifyDiagnosticsArgument(diagnostics, span), registerCodeFix ?? throw new ArgumentNullException(nameof(registerCodeFix)), - CodeActionOptions.Default, + _ => CodeActionOptions.Default, cancellationToken) { } @@ -100,7 +111,7 @@ public CodeFixContext( (diagnostic ?? throw new ArgumentNullException(nameof(diagnostic))).Location.SourceSpan, ImmutableArray.Create(diagnostic), registerCodeFix ?? throw new ArgumentNullException(nameof(registerCodeFix)), - CodeActionOptions.Default, + _ => CodeActionOptions.Default, cancellationToken) { } @@ -110,7 +121,7 @@ internal CodeFixContext( TextSpan span, ImmutableArray diagnostics, Action> registerCodeFix, - CodeActionOptions options, + CodeActionOptionsProvider options, CancellationToken cancellationToken) { Debug.Assert(diagnostics.Any(d => d.Location.SourceSpan == span)); @@ -201,6 +212,7 @@ private static ImmutableArray VerifyDiagnosticsArgument(ImmutableArr } } + [Obsolete] internal interface ITypeScriptCodeFixContext { bool IsBlocking { get; } diff --git a/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/BatchFixAllProvider.cs b/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/BatchFixAllProvider.cs index f6c139870894b..334020fdc431a 100644 --- a/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/BatchFixAllProvider.cs +++ b/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/BatchFixAllProvider.cs @@ -146,7 +146,7 @@ private static async Task> GetAllChangedDocumentsInDiag foreach (var diagnostic in orderedDiagnostics) { var document = solution.GetRequiredDocument(diagnostic.Location.SourceTree!); - var options = fixAllContext.State.CodeActionOptionsProvider(document.Project.Language) with { IsBlocking = false }; + var options = new CodeActionOptionsProvider(language => fixAllContext.State.CodeActionOptionsProvider(language) with { IsBlocking = false }); cancellationToken.ThrowIfCancellationRequested(); tasks.Add(Task.Run(async () => diff --git a/src/Workspaces/Core/Portable/CodeRefactorings/CodeRefactoringContext.cs b/src/Workspaces/Core/Portable/CodeRefactorings/CodeRefactoringContext.cs index 09e1442f9d76b..c2a3f38862c1d 100644 --- a/src/Workspaces/Core/Portable/CodeRefactorings/CodeRefactoringContext.cs +++ b/src/Workspaces/Core/Portable/CodeRefactorings/CodeRefactoringContext.cs @@ -12,7 +12,9 @@ namespace Microsoft.CodeAnalysis.CodeRefactorings /// /// Context for code refactorings provided by a . /// +#pragma warning disable CS0612 // Type or member is obsolete public readonly struct CodeRefactoringContext : ITypeScriptCodeRefactoringContext +#pragma warning restore { /// /// Document corresponding to the to refactor. @@ -29,8 +31,11 @@ namespace Microsoft.CodeAnalysis.CodeRefactorings /// public CancellationToken CancellationToken { get; } - internal readonly CodeActionOptions Options; - bool ITypeScriptCodeRefactoringContext.IsBlocking => Options.IsBlocking; + internal readonly CodeActionOptionsProvider Options; + + [Obsolete] + bool ITypeScriptCodeRefactoringContext.IsBlocking + => Options("TypeScript").IsBlocking; private readonly Action _registerRefactoring; @@ -42,7 +47,7 @@ public CodeRefactoringContext( TextSpan span, Action registerRefactoring, CancellationToken cancellationToken) - : this(document, span, (action, textSpan) => registerRefactoring(action), CodeActionOptions.Default, cancellationToken) + : this(document, span, (action, textSpan) => registerRefactoring(action), _ => CodeActionOptions.Default, cancellationToken) { } /// @@ -52,7 +57,7 @@ internal CodeRefactoringContext( Document document, TextSpan span, Action registerRefactoring, - CodeActionOptions options, + CodeActionOptionsProvider options, CancellationToken cancellationToken) { // NOTE/TODO: Don't make this overload public & obsolete the `Action registerRefactoring` @@ -99,6 +104,7 @@ internal void Deconstruct(out Document document, out TextSpan span, out Cancella } } + [Obsolete] internal interface ITypeScriptCodeRefactoringContext { bool IsBlocking { get; } diff --git a/src/Workspaces/Core/Portable/ExternalAccess/VSTypeScript/Api/VSTypeScriptCodeFixContextExtensions.cs b/src/Workspaces/Core/Portable/ExternalAccess/VSTypeScript/Api/VSTypeScriptCodeFixContextExtensions.cs index 3dd5d9a7150cc..d1e9c7113d511 100644 --- a/src/Workspaces/Core/Portable/ExternalAccess/VSTypeScript/Api/VSTypeScriptCodeFixContextExtensions.cs +++ b/src/Workspaces/Core/Portable/ExternalAccess/VSTypeScript/Api/VSTypeScriptCodeFixContextExtensions.cs @@ -2,16 +2,21 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; -using System.Text; using Microsoft.CodeAnalysis.CodeFixes; +using Microsoft.CodeAnalysis.CodeRefactorings; namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api { internal static class VSTypeScriptCodeFixContextExtensions { public static bool IsBlocking(this CodeFixContext context) +#pragma warning disable CS0612 // Type or member is obsolete => ((ITypeScriptCodeFixContext)context).IsBlocking; +#pragma warning restore + + public static bool IsBlocking(this CodeRefactoringContext context) +#pragma warning disable CS0612 // Type or member is obsolete + => ((ITypeScriptCodeRefactoringContext)context).IsBlocking; +#pragma warning restore } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/SyntaxEditorBasedCodeFixProvider.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/SyntaxEditorBasedCodeFixProvider.cs index 299f2931ad2f8..58c129b2e3e05 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/SyntaxEditorBasedCodeFixProvider.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/SyntaxEditorBasedCodeFixProvider.cs @@ -70,7 +70,7 @@ protected Func> GetDocumentUpdater(CodeFixCont #if CODE_STYLE var optionsProvider = s_codeStyleOptionsProvider; #else - var optionsProvider = new CodeActionOptionsProvider(_ => context.Options); + var optionsProvider = context.Options; #endif var diagnostics = ImmutableArray.Create(diagnostic ?? context.Diagnostics[0]);