From 18b6fe04eb823cb4bd96dad17c38cc854d7d7f01 Mon Sep 17 00:00:00 2001 From: tmat Date: Tue, 9 Jul 2024 12:32:57 -0700 Subject: [PATCH 1/3] Remove fallback options 2 --- .../ExtractInterfaceCommandHandler.cs | 3 +-- .../MoveType/MoveTypeTests.MoveScope.cs | 2 +- .../MoveToNamespace/MoveToNamespaceTests.cs | 1 - .../IntelliCode/IntentProcessor.cs | 4 +-- .../AbstractExtractInterfaceCommandHandler.cs | 6 +---- .../AbstractMoveToNamespaceTests.cs | 1 - .../ExtractInterfaceTestState.cs | 6 +---- .../TestExtractInterfaceOptions.cs | 4 +-- .../ExtractInterfaceCommandHandler.vb | 7 +++-- .../ExtractInterface/ExtractInterfaceTests.vb | 4 +-- ...gularConstructorCodeRefactoringProvider.cs | 5 ++-- ...tringToRawStringCodeRefactoringProvider.cs | 1 - ...tructorParameterCodeRefactoringProvider.cs | 9 +++---- ...ParameterCodeRefactoringProvider_Update.cs | 3 --- ...calForExpressionCodeRefactoringProvider.cs | 1 - .../MoveType/AbstractMoveTypeService.State.cs | 9 +++---- .../MoveType/AbstractMoveTypeService.cs | 16 +++++------ .../MoveType/IMoveTypeService.cs | 4 +-- .../MoveTypeCodeRefactoringProvider.cs | 2 +- .../AbstractExtractInterfaceService.cs | 16 ++++------- .../ExtractInterfaceCodeAction.cs | 1 - ...ExtractInterfaceCodeRefactoringProvider.cs | 2 +- .../ExtractInterfaceOptionsResult.cs | 5 +--- .../ExtractInterfaceTypeAnalysisResult.cs | 6 +---- .../IExtractInterfaceOptionsService.cs | 1 - ...terfaceService.DisposePatternCodeAction.cs | 27 +++---------------- ...ddParameterCheckCodeRefactoringProvider.cs | 2 -- ...erCodeRefactoringProviderMemberCreation.cs | 3 +-- ...tializeParameterCodeRefactoringProvider.cs | 6 ++--- .../Portable/Intents/IntentDataProvider.cs | 6 +---- ...calForExpressionCodeRefactoringProvider.cs | 9 +++---- ...deAction.MoveItemsToNamespaceCodeAction.cs | 6 ++--- ...odeAction.MoveTypeToNamespaceCodeAction.cs | 6 ++--- .../AbstractMoveToNamespaceCodeAction.cs | 11 +++----- .../AbstractMoveToNamespaceService.cs | 12 +++------ .../MoveToNamespaceCodeActionProvider.cs | 2 +- ...OmniSharpExtractInterfaceOptionsService.cs | 4 +-- ...calForExpressionCodeRefactoringProvider.vb | 2 +- ...ualStudioExtractInterfaceOptionsService.cs | 4 +-- 39 files changed, 65 insertions(+), 154 deletions(-) diff --git a/src/EditorFeatures/CSharp/ExtractInterface/ExtractInterfaceCommandHandler.cs b/src/EditorFeatures/CSharp/ExtractInterface/ExtractInterfaceCommandHandler.cs index 5e43d72ea629c..07bbb3bed9a43 100644 --- a/src/EditorFeatures/CSharp/ExtractInterface/ExtractInterfaceCommandHandler.cs +++ b/src/EditorFeatures/CSharp/ExtractInterface/ExtractInterfaceCommandHandler.cs @@ -8,7 +8,6 @@ using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.ExtractInterface; using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Options; using Microsoft.VisualStudio.Commanding; using Microsoft.VisualStudio.Utilities; @@ -19,6 +18,6 @@ namespace Microsoft.CodeAnalysis.CSharp.ExtractInterface; [Name(PredefinedCommandHandlerNames.ExtractInterface)] [method: ImportingConstructor] [method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] -internal sealed class ExtractInterfaceCommandHandler(IThreadingContext threadingContext, IGlobalOptionService globalOptions) : AbstractExtractInterfaceCommandHandler(threadingContext, globalOptions) +internal sealed class ExtractInterfaceCommandHandler(IThreadingContext threadingContext) : AbstractExtractInterfaceCommandHandler(threadingContext) { } diff --git a/src/EditorFeatures/CSharpTest/CodeActions/MoveType/MoveTypeTests.MoveScope.cs b/src/EditorFeatures/CSharpTest/CodeActions/MoveType/MoveTypeTests.MoveScope.cs index 8455401641543..fa203ef7f5a51 100644 --- a/src/EditorFeatures/CSharpTest/CodeActions/MoveType/MoveTypeTests.MoveScope.cs +++ b/src/EditorFeatures/CSharpTest/CodeActions/MoveType/MoveTypeTests.MoveScope.cs @@ -921,7 +921,7 @@ private async Task TestNamespaceMove(string originalCode, string expectedCode, b var moveTypeService = documentToModify.GetLanguageService(); Assert.NotNull(moveTypeService); - var modifiedSolution = await moveTypeService.GetModifiedSolutionAsync(documentToModify, textSpan, MoveTypeOperationKind.MoveTypeNamespaceScope, CodeActionOptions.DefaultProvider, CancellationToken.None).ConfigureAwait(false); + var modifiedSolution = await moveTypeService.GetModifiedSolutionAsync(documentToModify, textSpan, MoveTypeOperationKind.MoveTypeNamespaceScope, CancellationToken.None).ConfigureAwait(false); if (expectOperation) { diff --git a/src/EditorFeatures/CSharpTest/MoveToNamespace/MoveToNamespaceTests.cs b/src/EditorFeatures/CSharpTest/MoveToNamespace/MoveToNamespaceTests.cs index 255ed90b7cea8..9fd69aa3ff078 100644 --- a/src/EditorFeatures/CSharpTest/MoveToNamespace/MoveToNamespaceTests.cs +++ b/src/EditorFeatures/CSharpTest/MoveToNamespace/MoveToNamespaceTests.cs @@ -1259,7 +1259,6 @@ void Method() { } var actions = await testState.MoveToNamespaceService.GetCodeActionsAsync( testState.InvocationDocument, testState.TestInvocationDocument.SelectedSpans.Single(), - CodeActionOptions.DefaultProvider, CancellationToken.None); Assert.Empty(actions); diff --git a/src/EditorFeatures/Core/ExternalAccess/IntelliCode/IntentProcessor.cs b/src/EditorFeatures/Core/ExternalAccess/IntelliCode/IntentProcessor.cs index a203d93579f91..167901893a26a 100644 --- a/src/EditorFeatures/Core/ExternalAccess/IntelliCode/IntentProcessor.cs +++ b/src/EditorFeatures/Core/ExternalAccess/IntelliCode/IntentProcessor.cs @@ -66,9 +66,7 @@ public async Task> ComputeIntentsAsync(IntentReques originalDocument, selectionTextSpan, currentDocument, - new IntentDataProvider( - intentRequestContext.IntentData, - _globalOptions.CreateProvider()), + new IntentDataProvider(intentRequestContext.IntentData), cancellationToken).ConfigureAwait(false); if (results.IsDefaultOrEmpty) diff --git a/src/EditorFeatures/Core/ExtractInterface/AbstractExtractInterfaceCommandHandler.cs b/src/EditorFeatures/Core/ExtractInterface/AbstractExtractInterfaceCommandHandler.cs index e8d41a90a87a8..da0268fd88eea 100644 --- a/src/EditorFeatures/Core/ExtractInterface/AbstractExtractInterfaceCommandHandler.cs +++ b/src/EditorFeatures/Core/ExtractInterface/AbstractExtractInterfaceCommandHandler.cs @@ -9,7 +9,6 @@ using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Navigation; using Microsoft.CodeAnalysis.Notification; -using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.VisualStudio.Commanding; using Microsoft.VisualStudio.Text; @@ -20,12 +19,10 @@ namespace Microsoft.CodeAnalysis.ExtractInterface; internal abstract class AbstractExtractInterfaceCommandHandler : ICommandHandler { private readonly IThreadingContext _threadingContext; - private readonly IGlobalOptionService _globalOptions; - protected AbstractExtractInterfaceCommandHandler(IThreadingContext threadingContext, IGlobalOptionService globalOptions) + protected AbstractExtractInterfaceCommandHandler(IThreadingContext threadingContext) { _threadingContext = threadingContext; - _globalOptions = globalOptions; } public string DisplayName => EditorFeaturesResources.Extract_Interface; @@ -71,7 +68,6 @@ public bool ExecuteCommand(ExtractInterfaceCommandArgs args, CommandExecutionCon var result = await extractInterfaceService.ExtractInterfaceAsync( document, caretPoint.Value.Position, - _globalOptions.CreateProvider(), (errorMessage, severity) => workspace.Services.GetService().SendNotification(errorMessage, severity: severity), CancellationToken.None).ConfigureAwait(true); diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/MoveToNamespace/AbstractMoveToNamespaceTests.cs b/src/EditorFeatures/DiagnosticsTestUtilities/MoveToNamespace/AbstractMoveToNamespaceTests.cs index 391982e60e319..75395d6d39b86 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/MoveToNamespace/AbstractMoveToNamespaceTests.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/MoveToNamespace/AbstractMoveToNamespaceTests.cs @@ -48,7 +48,6 @@ public async Task TestMoveToNamespaceAsync( var actions = await testState.MoveToNamespaceService.GetCodeActionsAsync( testState.InvocationDocument, testState.TestInvocationDocument.SelectedSpans.Single(), - CodeActionOptions.DefaultProvider, CancellationToken.None); var operationTasks = actions diff --git a/src/EditorFeatures/TestUtilities/ExtractInterface/ExtractInterfaceTestState.cs b/src/EditorFeatures/TestUtilities/ExtractInterface/ExtractInterfaceTestState.cs index c466125a9c7ac..1874449ca25d0 100644 --- a/src/EditorFeatures/TestUtilities/ExtractInterface/ExtractInterfaceTestState.cs +++ b/src/EditorFeatures/TestUtilities/ExtractInterface/ExtractInterfaceTestState.cs @@ -77,7 +77,6 @@ public Task GetTypeAnalysisResultAsync(TypeD ExtractFromDocument, _testDocument.CursorPosition.Value, typeDiscoveryRule, - Workspace.GlobalOptions.CreateProvider(), CancellationToken.None); } @@ -86,7 +85,6 @@ public Task ExtractViaCommandAsync() return ExtractInterfaceService.ExtractInterfaceAsync( ExtractFromDocument, _testDocument.CursorPosition.Value, - Workspace.GlobalOptions.CreateProvider(), (errorMessage, severity) => { this.ErrorMessage = errorMessage; @@ -100,7 +98,6 @@ public async Task ExtractViaCodeAction() var actions = await ExtractInterfaceService.GetExtractInterfaceCodeActionAsync( ExtractFromDocument, new TextSpan(_testDocument.CursorPosition.Value, 1), - Workspace.GlobalOptions.CreateProvider(), CancellationToken.None); var action = actions.Single(); @@ -111,8 +108,7 @@ public async Task ExtractViaCodeAction() options.IncludedMembers, options.InterfaceName, options.FileName, - ExtractInterfaceOptionsResult.ExtractLocation.SameFile, - options.FallbackOptions); + ExtractInterfaceOptionsResult.ExtractLocation.SameFile); var operations = await action.GetOperationsAsync( this.OriginalSolution, changedOptions, CodeAnalysisProgress.None, CancellationToken.None); diff --git a/src/EditorFeatures/TestUtilities/ExtractInterface/TestExtractInterfaceOptions.cs b/src/EditorFeatures/TestUtilities/ExtractInterface/TestExtractInterfaceOptions.cs index 1bb576e0423d2..01a72da76d171 100644 --- a/src/EditorFeatures/TestUtilities/ExtractInterface/TestExtractInterfaceOptions.cs +++ b/src/EditorFeatures/TestUtilities/ExtractInterface/TestExtractInterfaceOptions.cs @@ -47,7 +47,6 @@ public Task GetExtractInterfaceOptionsAsync( string defaultNamespace, string generatedNameTypeParameterSuffix, string languageName, - CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) { this.AllExtractableMembers = extractableMembers; @@ -63,8 +62,7 @@ public Task GetExtractInterfaceOptionsAsync( includedMembers: (ChosenMembers ?? AllExtractableMembers).AsImmutable(), interfaceName: ChosenInterfaceName ?? defaultInterfaceName, fileName: ChosenFileName ?? defaultInterfaceName, - location: SameFile ? ExtractInterfaceOptionsResult.ExtractLocation.SameFile : ExtractInterfaceOptionsResult.ExtractLocation.NewFile, - fallbackOptions); + location: SameFile ? ExtractInterfaceOptionsResult.ExtractLocation.SameFile : ExtractInterfaceOptionsResult.ExtractLocation.NewFile); return Task.FromResult(result); } diff --git a/src/EditorFeatures/VisualBasic/ExtractInterface/ExtractInterfaceCommandHandler.vb b/src/EditorFeatures/VisualBasic/ExtractInterface/ExtractInterfaceCommandHandler.vb index 9bd7809a0a15d..a28b8d6d11934 100644 --- a/src/EditorFeatures/VisualBasic/ExtractInterface/ExtractInterfaceCommandHandler.vb +++ b/src/EditorFeatures/VisualBasic/ExtractInterface/ExtractInterfaceCommandHandler.vb @@ -4,12 +4,11 @@ Imports System.ComponentModel.Composition Imports System.Diagnostics.CodeAnalysis -Imports Microsoft.CodeAnalysis.ExtractInterface Imports Microsoft.CodeAnalysis.Editor Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities +Imports Microsoft.CodeAnalysis.ExtractInterface Imports Microsoft.VisualStudio.Commanding Imports Microsoft.VisualStudio.Utilities -Imports Microsoft.CodeAnalysis.Options Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractInterface @@ -20,8 +19,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractInterface - Public Sub New(threadingContext As IThreadingContext, globalOptions As IGlobalOptionService) - MyBase.New(threadingContext, globalOptions) + Public Sub New(threadingContext As IThreadingContext) + MyBase.New(threadingContext) End Sub End Class End Namespace diff --git a/src/EditorFeatures/VisualBasicTest/ExtractInterface/ExtractInterfaceTests.vb b/src/EditorFeatures/VisualBasicTest/ExtractInterface/ExtractInterfaceTests.vb index f225b6ba7f82e..ec1f5bfb377b1 100644 --- a/src/EditorFeatures/VisualBasicTest/ExtractInterface/ExtractInterfaceTests.vb +++ b/src/EditorFeatures/VisualBasicTest/ExtractInterface/ExtractInterfaceTests.vb @@ -1286,9 +1286,7 @@ End Namespace Dim textView = workspace.Documents.Single().GetTextView() - Dim handler = New ExtractInterfaceCommandHandler( - workspace.GetService(Of IThreadingContext), - workspace.GlobalOptions) + Dim handler = New ExtractInterfaceCommandHandler(workspace.GetService(Of IThreadingContext)) Dim state = handler.GetCommandState(New ExtractInterfaceCommandArgs(textView, textView.TextBuffer)) Assert.True(state.IsUnspecified) diff --git a/src/Features/CSharp/Portable/ConvertPrimaryToRegularConstructor/ConvertPrimaryToRegularConstructorCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/ConvertPrimaryToRegularConstructor/ConvertPrimaryToRegularConstructorCodeRefactoringProvider.cs index f602fc0a057ac..83c9afc98ef22 100644 --- a/src/Features/CSharp/Portable/ConvertPrimaryToRegularConstructor/ConvertPrimaryToRegularConstructorCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/ConvertPrimaryToRegularConstructor/ConvertPrimaryToRegularConstructorCodeRefactoringProvider.cs @@ -57,7 +57,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte context.RegisterRefactoring(CodeAction.Create( CSharpFeaturesResources.Convert_to_regular_constructor, - cancellationToken => ConvertAsync(document, typeDeclaration, typeDeclaration.ParameterList, context.Options, cancellationToken), + cancellationToken => ConvertAsync(document, typeDeclaration, typeDeclaration.ParameterList, cancellationToken), nameof(CSharpFeaturesResources.Convert_to_regular_constructor)), triggerSpan); } @@ -66,7 +66,6 @@ private static async Task ConvertAsync( Document document, TypeDeclarationSyntax typeDeclaration, ParameterListSyntax parameterList, - CodeActionOptionsProvider optionsProvider, CancellationToken cancellationToken) { var compilation = await document.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); @@ -75,6 +74,7 @@ private static async Task ConvertAsync( var semanticModel = await GetSemanticModelAsync(document).ConfigureAwait(false); var contextInfo = await document.GetCodeGenerationInfoAsync(CodeGenerationContext.Default, cancellationToken).ConfigureAwait(false); + var formattingOptions = await document.GetSyntaxFormattingOptionsAsync(cancellationToken).ConfigureAwait(false); // The naming rule we need to follow if we synthesize new private fields. var fieldNameRule = await document.GetApplicableNamingRuleAsync( @@ -379,7 +379,6 @@ async Task RewritePrimaryConstructorParameterReferencesAsync() void FixParameterAndBaseArgumentListIndentation() { var currentRoot = mainDocumentEditor.GetChangedRoot(); - var formattingOptions = optionsProvider.GetOptions(document.Project.Services).CleanupOptions.FormattingOptions; var indentationOptions = new IndentationOptions(formattingOptions); var formattedRoot = Formatter.Format(currentRoot, SyntaxAnnotation.ElasticAnnotation, solution.Services, formattingOptions, cancellationToken); diff --git a/src/Features/CSharp/Portable/ConvertToRawString/ConvertStringToRawStringCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/ConvertToRawString/ConvertStringToRawStringCodeRefactoringProvider.cs index fb7e0ac174695..90c1735d4be85 100644 --- a/src/Features/CSharp/Portable/ConvertToRawString/ConvertStringToRawStringCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/ConvertToRawString/ConvertStringToRawStringCodeRefactoringProvider.cs @@ -76,7 +76,6 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte if (token.Parent is not ExpressionSyntax parentExpression) return; - var options = context.Options; var formattingOptions = await document.GetSyntaxFormattingOptionsAsync(cancellationToken).ConfigureAwait(false); var parsedDocument = await ParsedDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false); diff --git a/src/Features/CSharp/Portable/InitializeParameter/CSharpInitializeMemberFromPrimaryConstructorParameterCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/InitializeParameter/CSharpInitializeMemberFromPrimaryConstructorParameterCodeRefactoringProvider.cs index 07158eeb295dc..39c7e84ef890e 100644 --- a/src/Features/CSharp/Portable/InitializeParameter/CSharpInitializeMemberFromPrimaryConstructorParameterCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/InitializeParameter/CSharpInitializeMemberFromPrimaryConstructorParameterCodeRefactoringProvider.cs @@ -68,7 +68,6 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte // Haven't initialized any fields/properties with this parameter. Offer to assign to an existing matching // field/prop if we can find one, or add a new field/prop if we can't. - var fallbackOptions = context.Options; var rules = await document.GetNamingRulesAsync(cancellationToken).ConfigureAwait(false); var parameterNameParts = IdentifierNameParts.CreateIdentifierNameParts(parameter, rules); if (parameterNameParts.BaseName == "") @@ -157,10 +156,10 @@ IEnumerable HandleNoExistingFieldOrProperty() var fieldAction = CreateCodeAction( string.Format(FeaturesResources.Create_and_assign_field_0, field.Name), - cancellationToken => AddMultipleMembersAsync(document, typeDeclaration, [parameter], [field], fallbackOptions, cancellationToken)); + cancellationToken => AddMultipleMembersAsync(document, typeDeclaration, [parameter], [field], cancellationToken)); var propertyAction = CreateCodeAction( string.Format(FeaturesResources.Create_and_assign_property_0, property.Name), - cancellationToken => AddMultipleMembersAsync(document, typeDeclaration, [parameter], [property], fallbackOptions, cancellationToken)); + cancellationToken => AddMultipleMembersAsync(document, typeDeclaration, [parameter], [property], cancellationToken)); yield return siblingFieldOrProperty is IFieldSymbol ? fieldAction : propertyAction; yield return siblingFieldOrProperty is IFieldSymbol ? propertyAction : fieldAction; @@ -170,10 +169,10 @@ IEnumerable HandleNoExistingFieldOrProperty() { var allFieldsAction = CodeAction.Create( FeaturesResources.Create_and_assign_remaining_as_fields, - cancellationToken => AddMultipleMembersAsync(document, typeDeclaration, parameters, parameters.SelectAsArray(CreateField), fallbackOptions, cancellationToken)); + cancellationToken => AddMultipleMembersAsync(document, typeDeclaration, parameters, parameters.SelectAsArray(CreateField), cancellationToken)); var allPropertiesAction = CodeAction.Create( FeaturesResources.Create_and_assign_remaining_as_properties, - cancellationToken => AddMultipleMembersAsync(document, typeDeclaration, parameters, parameters.SelectAsArray(CreateProperty), fallbackOptions, cancellationToken)); + cancellationToken => AddMultipleMembersAsync(document, typeDeclaration, parameters, parameters.SelectAsArray(CreateProperty), cancellationToken)); yield return siblingFieldOrProperty is IFieldSymbol ? allFieldsAction : allPropertiesAction; yield return siblingFieldOrProperty is IFieldSymbol ? allPropertiesAction : allFieldsAction; diff --git a/src/Features/CSharp/Portable/InitializeParameter/CSharpInitializeMemberFromPrimaryConstructorParameterCodeRefactoringProvider_Update.cs b/src/Features/CSharp/Portable/InitializeParameter/CSharpInitializeMemberFromPrimaryConstructorParameterCodeRefactoringProvider_Update.cs index 9cd99f371eedd..21de8b268e97f 100644 --- a/src/Features/CSharp/Portable/InitializeParameter/CSharpInitializeMemberFromPrimaryConstructorParameterCodeRefactoringProvider_Update.cs +++ b/src/Features/CSharp/Portable/InitializeParameter/CSharpInitializeMemberFromPrimaryConstructorParameterCodeRefactoringProvider_Update.cs @@ -30,7 +30,6 @@ private static async Task AddMultipleMembersAsync( TypeDeclarationSyntax typeDeclaration, ImmutableArray parameters, ImmutableArray fieldsOrProperties, - CodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) { Debug.Assert(parameters.Length >= 1); @@ -66,7 +65,6 @@ private static async Task AddMultipleMembersAsync( currentTypeDeclaration, currentParameter, fieldOrProperty, - fallbackOptions, cancellationToken).ConfigureAwait(false); } @@ -81,7 +79,6 @@ static async Task AddSingleMemberAsync( TypeDeclarationSyntax typeDeclaration, IParameterSymbol parameter, ISymbol fieldOrProperty, - CodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) { var project = document.Project; diff --git a/src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceLocalForExpressionCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceLocalForExpressionCodeRefactoringProvider.cs index ad85222af598f..7d96adc036d07 100644 --- a/src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceLocalForExpressionCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceLocalForExpressionCodeRefactoringProvider.cs @@ -88,7 +88,6 @@ protected override ExpressionStatementSyntax FixupDeconstruction( protected override async Task CreateTupleDeconstructionAsync( Document document, - CodeActionOptionsProvider optionsProvider, INamedTypeSymbol tupleType, ExpressionSyntax expression, CancellationToken cancellationToken) diff --git a/src/Features/Core/Portable/CodeRefactorings/MoveType/AbstractMoveTypeService.State.cs b/src/Features/Core/Portable/CodeRefactorings/MoveType/AbstractMoveTypeService.State.cs index c3df9cc5a74c4..3de31e50f3ba9 100644 --- a/src/Features/Core/Portable/CodeRefactorings/MoveType/AbstractMoveTypeService.State.cs +++ b/src/Features/Core/Portable/CodeRefactorings/MoveType/AbstractMoveTypeService.State.cs @@ -7,7 +7,6 @@ using System.IO; using System.Linq; using System.Threading; -using Microsoft.CodeAnalysis.CodeCleanup; using Microsoft.CodeAnalysis.LanguageService; using Microsoft.CodeAnalysis.Shared.Extensions; @@ -18,24 +17,22 @@ internal abstract partial class AbstractMoveTypeService public static SyntaxAnnotation NamespaceScopeMovedAnnotation = new(nameof(MoveTypeOperationKind.MoveTypeNamespaceScope)); - public abstract Task GetModifiedSolutionAsync(Document document, TextSpan textSpan, MoveTypeOperationKind operationKind, CodeCleanupOptionsProvider fallbackOptions, CancellationToken cancellationToken); - public abstract Task> GetRefactoringAsync(Document document, TextSpan textSpan, CodeCleanupOptionsProvider fallbackOptions, CancellationToken cancellationToken); + public abstract Task GetModifiedSolutionAsync(Document document, TextSpan textSpan, MoveTypeOperationKind operationKind, CancellationToken cancellationToken); + public abstract Task> GetRefactoringAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken); } internal abstract partial class AbstractMoveTypeService : @@ -42,9 +42,9 @@ internal abstract partial class AbstractMoveTypeService> GetRefactoringAsync( - Document document, TextSpan textSpan, CodeCleanupOptionsProvider fallbackOptions, CancellationToken cancellationToken) + Document document, TextSpan textSpan, CancellationToken cancellationToken) { - var state = await CreateStateAsync(document, textSpan, fallbackOptions, cancellationToken).ConfigureAwait(false); + var state = await CreateStateAsync(document, textSpan, cancellationToken).ConfigureAwait(false); if (state == null) { @@ -55,9 +55,9 @@ public override async Task> GetRefactoringAsync( return actions; } - public override async Task GetModifiedSolutionAsync(Document document, TextSpan textSpan, MoveTypeOperationKind operationKind, CodeCleanupOptionsProvider fallbackOptions, CancellationToken cancellationToken) + public override async Task GetModifiedSolutionAsync(Document document, TextSpan textSpan, MoveTypeOperationKind operationKind, CancellationToken cancellationToken) { - var state = await CreateStateAsync(document, textSpan, fallbackOptions, cancellationToken).ConfigureAwait(false); + var state = await CreateStateAsync(document, textSpan, cancellationToken).ConfigureAwait(false); if (state == null) { @@ -79,7 +79,7 @@ public override async Task GetModifiedSolutionAsync(Document document, protected abstract Task GetRelevantNodeAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken); - private async Task CreateStateAsync(Document document, TextSpan textSpan, CodeCleanupOptionsProvider fallbackOptions, CancellationToken cancellationToken) + private async Task CreateStateAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken) { var nodeToAnalyze = await GetRelevantNodeAsync(document, textSpan, cancellationToken).ConfigureAwait(false); if (nodeToAnalyze == null) @@ -88,7 +88,7 @@ private async Task CreateStateAsync(Document document, TextSpan textSpan, } var semanticDocument = await SemanticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false); - return State.Generate(semanticDocument, nodeToAnalyze, fallbackOptions, cancellationToken); + return State.Generate(semanticDocument, nodeToAnalyze, cancellationToken); } private ImmutableArray CreateActions(State state, CancellationToken cancellationToken) diff --git a/src/Features/Core/Portable/CodeRefactorings/MoveType/IMoveTypeService.cs b/src/Features/Core/Portable/CodeRefactorings/MoveType/IMoveTypeService.cs index bec8a8a4f3846..23c02bfa1ca52 100644 --- a/src/Features/Core/Portable/CodeRefactorings/MoveType/IMoveTypeService.cs +++ b/src/Features/Core/Portable/CodeRefactorings/MoveType/IMoveTypeService.cs @@ -16,7 +16,7 @@ namespace Microsoft.CodeAnalysis.CodeRefactorings.MoveType; internal interface IMoveTypeService : ILanguageService { - Task> GetRefactoringAsync(Document document, TextSpan textSpan, CodeCleanupOptionsProvider fallbackOptions, CancellationToken cancellationToken); + Task> GetRefactoringAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken); - Task GetModifiedSolutionAsync(Document document, TextSpan textSpan, MoveTypeOperationKind operationKind, CodeCleanupOptionsProvider fallbackOptions, CancellationToken cancellationToken); + Task GetModifiedSolutionAsync(Document document, TextSpan textSpan, MoveTypeOperationKind operationKind, CancellationToken cancellationToken); } diff --git a/src/Features/Core/Portable/CodeRefactorings/MoveType/MoveTypeCodeRefactoringProvider.cs b/src/Features/Core/Portable/CodeRefactorings/MoveType/MoveTypeCodeRefactoringProvider.cs index c33cb8c371203..acf73a0697624 100644 --- a/src/Features/Core/Portable/CodeRefactorings/MoveType/MoveTypeCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/CodeRefactorings/MoveType/MoveTypeCodeRefactoringProvider.cs @@ -29,7 +29,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte return; var service = document.GetRequiredLanguageService(); - var actions = await service.GetRefactoringAsync(document, textSpan, context.Options, cancellationToken).ConfigureAwait(false); + var actions = await service.GetRefactoringAsync(document, textSpan, cancellationToken).ConfigureAwait(false); context.RegisterRefactorings(actions); } } diff --git a/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs b/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs index 757f30f9b1531..a87d8135ad542 100644 --- a/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs +++ b/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs @@ -48,9 +48,9 @@ protected abstract Task UpdateMembersWithExplicitImplementationsAsync( internal abstract bool ShouldIncludeAccessibilityModifier(SyntaxNode typeNode); - public async Task> GetExtractInterfaceCodeActionAsync(Document document, TextSpan span, CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) + public async Task> GetExtractInterfaceCodeActionAsync(Document document, TextSpan span, CancellationToken cancellationToken) { - var typeAnalysisResult = await AnalyzeTypeAtPositionAsync(document, span.Start, TypeDiscoveryRule.TypeNameOnly, fallbackOptions, cancellationToken).ConfigureAwait(false); + var typeAnalysisResult = await AnalyzeTypeAtPositionAsync(document, span.Start, TypeDiscoveryRule.TypeNameOnly, cancellationToken).ConfigureAwait(false); return typeAnalysisResult.CanExtractInterface ? [new ExtractInterfaceCodeAction(this, typeAnalysisResult)] @@ -60,7 +60,6 @@ public async Task> GetExtractInterfac public async Task ExtractInterfaceAsync( Document documentWithTypeToExtractFrom, int position, - CleanCodeGenerationOptionsProvider fallbackOptions, Action errorHandler, CancellationToken cancellationToken) { @@ -68,7 +67,6 @@ public async Task ExtractInterfaceAsync( documentWithTypeToExtractFrom, position, TypeDiscoveryRule.TypeDeclaration, - fallbackOptions, cancellationToken).ConfigureAwait(false); if (!typeAnalysisResult.CanExtractInterface) @@ -77,14 +75,13 @@ public async Task ExtractInterfaceAsync( return new ExtractInterfaceResult(succeeded: false); } - return await ExtractInterfaceFromAnalyzedTypeAsync(typeAnalysisResult, fallbackOptions, cancellationToken).ConfigureAwait(false); + return await ExtractInterfaceFromAnalyzedTypeAsync(typeAnalysisResult, cancellationToken).ConfigureAwait(false); } public async Task AnalyzeTypeAtPositionAsync( Document document, int position, TypeDiscoveryRule typeDiscoveryRule, - CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) { var typeNode = await GetTypeDeclarationAsync(document, position, typeDiscoveryRule, cancellationToken).ConfigureAwait(false); @@ -110,10 +107,10 @@ public async Task AnalyzeTypeAtPositionAsync return new ExtractInterfaceTypeAnalysisResult(errorMessage); } - return new ExtractInterfaceTypeAnalysisResult(document, typeNode, typeToExtractFrom, extractableMembers, fallbackOptions); + return new ExtractInterfaceTypeAnalysisResult(document, typeNode, typeToExtractFrom, extractableMembers); } - public async Task ExtractInterfaceFromAnalyzedTypeAsync(ExtractInterfaceTypeAnalysisResult refactoringResult, CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) + public async Task ExtractInterfaceFromAnalyzedTypeAsync(ExtractInterfaceTypeAnalysisResult refactoringResult, CancellationToken cancellationToken) { var containingNamespaceDisplay = refactoringResult.TypeToExtractFrom.ContainingNamespace.IsGlobalNamespace ? string.Empty @@ -124,7 +121,6 @@ public async Task ExtractInterfaceFromAnalyzedTypeAsync( refactoringResult.TypeToExtractFrom, refactoringResult.ExtractableMembers, containingNamespaceDisplay, - fallbackOptions, cancellationToken).ConfigureAwait(false); if (extractInterfaceOptions.IsCancelled) @@ -261,7 +257,6 @@ internal static async Task GetExtractInterfaceOpt INamedTypeSymbol type, IEnumerable extractableMembers, string containingNamespace, - CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) { var conflictingTypeNames = type.ContainingNamespace.GetAllTypes(cancellationToken).Select(t => t.Name); @@ -282,7 +277,6 @@ internal static async Task GetExtractInterfaceOpt containingNamespace, generatedNameTypeParameterSuffix, document.Project.Language, - fallbackOptions, cancellationToken).ConfigureAwait(false); } diff --git a/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceCodeAction.cs b/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceCodeAction.cs index c1aa2679f3f9a..c64eefa52fa33 100644 --- a/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceCodeAction.cs +++ b/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceCodeAction.cs @@ -27,7 +27,6 @@ public override object GetOptions(CancellationToken cancellationToken) _typeAnalysisResult.TypeToExtractFrom, _typeAnalysisResult.ExtractableMembers, containingNamespaceDisplay, - _typeAnalysisResult.FallbackOptions, cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); } diff --git a/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceCodeRefactoringProvider.cs b/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceCodeRefactoringProvider.cs index f91cd107aebe2..94d92966ba688 100644 --- a/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceCodeRefactoringProvider.cs @@ -27,7 +27,7 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex { var (document, textSpan, cancellationToken) = context; var service = document.GetLanguageService(); - var actions = await service.GetExtractInterfaceCodeActionAsync(document, textSpan, context.Options, cancellationToken).ConfigureAwait(false); + var actions = await service.GetExtractInterfaceCodeActionAsync(document, textSpan, cancellationToken).ConfigureAwait(false); context.RegisterRefactorings(actions); } } diff --git a/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceOptionsResult.cs b/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceOptionsResult.cs index b2b0bf0b36726..f186245b92dc7 100644 --- a/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceOptionsResult.cs +++ b/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceOptionsResult.cs @@ -5,7 +5,6 @@ #nullable disable using System.Collections.Immutable; -using Microsoft.CodeAnalysis.CodeGeneration; namespace Microsoft.CodeAnalysis.ExtractInterface; @@ -24,15 +23,13 @@ public enum ExtractLocation public string InterfaceName { get; } public string FileName { get; } public ExtractLocation Location { get; } - public CleanCodeGenerationOptionsProvider FallbackOptions { get; } - public ExtractInterfaceOptionsResult(bool isCancelled, ImmutableArray includedMembers, string interfaceName, string fileName, ExtractLocation location, CleanCodeGenerationOptionsProvider fallbackOptions) + public ExtractInterfaceOptionsResult(bool isCancelled, ImmutableArray includedMembers, string interfaceName, string fileName, ExtractLocation location) { IsCancelled = isCancelled; IncludedMembers = includedMembers; InterfaceName = interfaceName; Location = location; - FallbackOptions = fallbackOptions; FileName = fileName; } diff --git a/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceTypeAnalysisResult.cs b/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceTypeAnalysisResult.cs index e8f4f5035db1b..de7bc70976ace 100644 --- a/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceTypeAnalysisResult.cs +++ b/src/Features/Core/Portable/ExtractInterface/ExtractInterfaceTypeAnalysisResult.cs @@ -5,7 +5,6 @@ #nullable disable using System.Collections.Generic; -using Microsoft.CodeAnalysis.CodeGeneration; namespace Microsoft.CodeAnalysis.ExtractInterface; @@ -16,22 +15,19 @@ internal sealed class ExtractInterfaceTypeAnalysisResult public readonly SyntaxNode TypeNode; public readonly INamedTypeSymbol TypeToExtractFrom; public readonly IEnumerable ExtractableMembers; - public readonly CleanCodeGenerationOptionsProvider FallbackOptions; public readonly string ErrorMessage; public ExtractInterfaceTypeAnalysisResult( Document documentToExtractFrom, SyntaxNode typeNode, INamedTypeSymbol typeToExtractFrom, - IEnumerable extractableMembers, - CleanCodeGenerationOptionsProvider fallbackOptions) + IEnumerable extractableMembers) { CanExtractInterface = true; DocumentToExtractFrom = documentToExtractFrom; TypeNode = typeNode; TypeToExtractFrom = typeToExtractFrom; ExtractableMembers = extractableMembers; - FallbackOptions = fallbackOptions; } public ExtractInterfaceTypeAnalysisResult(string errorMessage) diff --git a/src/Features/Core/Portable/ExtractInterface/IExtractInterfaceOptionsService.cs b/src/Features/Core/Portable/ExtractInterface/IExtractInterfaceOptionsService.cs index eb4f5821eb6ea..321916dd932b3 100644 --- a/src/Features/Core/Portable/ExtractInterface/IExtractInterfaceOptionsService.cs +++ b/src/Features/Core/Portable/ExtractInterface/IExtractInterfaceOptionsService.cs @@ -25,6 +25,5 @@ Task GetExtractInterfaceOptionsAsync( string defaultNamespace, string generatedNameTypeParameterSuffix, string languageName, - CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken); } diff --git a/src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.DisposePatternCodeAction.cs b/src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.DisposePatternCodeAction.cs index 2a4a3598d0c5e..53e7d8f5634a1 100644 --- a/src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.DisposePatternCodeAction.cs +++ b/src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.DisposePatternCodeAction.cs @@ -318,27 +318,7 @@ private IMethodSymbol CreateDisposeInterfaceMethod( return result; } - /// - /// This helper is implementing access to the editorconfig option. This would usually be done via but - /// we do not have access to here since the code action implementation is also used to implement . - /// TODO: remove - see https://github.com/dotnet/roslyn/issues/60990. - /// - public async ValueTask GetAccessibilityModifiersRequiredAsync(Document document, CancellationToken cancellationToken) - { - var syntaxTree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); - var configOptions = document.Project.AnalyzerOptions.AnalyzerConfigOptionsProvider.GetOptions(syntaxTree); - - if (configOptions.TryGetEditorConfigOption>(CodeStyleOptions2.AccessibilityModifiersRequired, out var value)) - { - return value.Value; - } - - var fallbackFormattingOptions = await ((OptionsProvider)Options.FallbackOptions).GetOptionsAsync(document.Project.Services, cancellationToken).ConfigureAwait(false); - - return fallbackFormattingOptions.AccessibilityModifiersRequired; - } - - private async Task CreateDisposedValueFieldAsync( + private static async Task CreateDisposedValueFieldAsync( Document document, INamedTypeSymbol containingType, CancellationToken cancellationToken) @@ -346,11 +326,10 @@ private async Task CreateDisposedValueFieldAsync( var rule = await document.GetApplicableNamingRuleAsync( SymbolKind.Field, Accessibility.Private, cancellationToken).ConfigureAwait(false); - var requireAccessiblity = await GetAccessibilityModifiersRequiredAsync(document, cancellationToken).ConfigureAwait(false); - + var options = await document.GetSyntaxFormattingOptionsAsync(cancellationToken).ConfigureAwait(false); var compilation = await document.Project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false); var boolType = compilation.GetSpecialType(SpecialType.System_Boolean); - var accessibilityLevel = requireAccessiblity is AccessibilityModifiersRequired.Never or AccessibilityModifiersRequired.OmitIfDefault + var accessibilityLevel = options.AccessibilityModifiersRequired is AccessibilityModifiersRequired.Never or AccessibilityModifiersRequired.OmitIfDefault ? Accessibility.NotApplicable : Accessibility.Private; diff --git a/src/Features/Core/Portable/InitializeParameter/AbstractAddParameterCheckCodeRefactoringProvider.cs b/src/Features/Core/Portable/InitializeParameter/AbstractAddParameterCheckCodeRefactoringProvider.cs index 6bf4ec9fcb46e..3fb4cc930394f 100644 --- a/src/Features/Core/Portable/InitializeParameter/AbstractAddParameterCheckCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/InitializeParameter/AbstractAddParameterCheckCodeRefactoringProvider.cs @@ -55,7 +55,6 @@ protected override async Task> GetRefactoringsForAllP IBlockOperation? blockStatementOpt, ImmutableArray listOfParameterNodes, TextSpan parameterSpan, - CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) { // List to keep track of the valid parameters @@ -87,7 +86,6 @@ protected override async Task> GetRefactoringsForSing SyntaxNode functionDeclaration, IMethodSymbol methodSymbol, IBlockOperation? blockStatementOpt, - CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) { var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs b/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs index 4007137e18a60..20f2aff096efe 100644 --- a/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs +++ b/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs @@ -52,7 +52,7 @@ internal abstract partial class AbstractInitializeMemberFromParameterCodeRefacto protected sealed override Task> GetRefactoringsForAllParametersAsync( Document document, SyntaxNode functionDeclaration, IMethodSymbol method, IBlockOperation? blockStatementOpt, ImmutableArray listOfParameterNodes, TextSpan parameterSpan, - CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) + CancellationToken cancellationToken) { return SpecializedTasks.EmptyImmutableArray(); } @@ -64,7 +64,6 @@ protected sealed override async Task> GetRefactorings SyntaxNode constructorDeclaration, IMethodSymbol method, IBlockOperation? blockStatement, - CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) { // Only supported for constructor parameters. diff --git a/src/Features/Core/Portable/InitializeParameter/AbstractInitializeParameterCodeRefactoringProvider.cs b/src/Features/Core/Portable/InitializeParameter/AbstractInitializeParameterCodeRefactoringProvider.cs index b0865227daffa..cbdfd876cbb9c 100644 --- a/src/Features/Core/Portable/InitializeParameter/AbstractInitializeParameterCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/InitializeParameter/AbstractInitializeParameterCodeRefactoringProvider.cs @@ -42,7 +42,6 @@ protected abstract Task> GetRefactoringsForAllParamet IBlockOperation? blockStatement, ImmutableArray listOfParameterNodes, TextSpan parameterSpan, - CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken); protected abstract Task> GetRefactoringsForSingleParameterAsync( @@ -52,7 +51,6 @@ protected abstract Task> GetRefactoringsForSinglePara SyntaxNode functionDeclaration, IMethodSymbol methodSymbol, IBlockOperation? blockStatement, - CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken); protected abstract void InsertStatement( @@ -104,7 +102,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte // Ok. Looks like the selected parameter could be refactored. Defer to subclass to // actually determine if there are any viable refactorings here. var refactorings = await GetRefactoringsForSingleParameterAsync( - document, selectedParameter, parameter, functionDeclaration, methodSymbol, blockStatementOpt, context.Options, cancellationToken).ConfigureAwait(false); + document, selectedParameter, parameter, functionDeclaration, methodSymbol, blockStatementOpt, cancellationToken).ConfigureAwait(false); context.RegisterRefactorings(refactorings, context.Span); } @@ -125,7 +123,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte // actually determine if there are any viable refactorings here. var refactorings = await GetRefactoringsForAllParametersAsync( document, functionDeclaration, methodSymbol, blockStatementOpt, - listOfPotentiallyValidParametersNodes.ToImmutable(), selectedParameter.Span, context.Options, cancellationToken).ConfigureAwait(false); + listOfPotentiallyValidParametersNodes.ToImmutable(), selectedParameter.Span, cancellationToken).ConfigureAwait(false); context.RegisterRefactorings(refactorings, context.Span); } diff --git a/src/Features/Core/Portable/Intents/IntentDataProvider.cs b/src/Features/Core/Portable/Intents/IntentDataProvider.cs index 1b7c06fa111e5..737a21de6ccfd 100644 --- a/src/Features/Core/Portable/Intents/IntentDataProvider.cs +++ b/src/Features/Core/Portable/Intents/IntentDataProvider.cs @@ -5,14 +5,12 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; -using Microsoft.CodeAnalysis.CodeGeneration; using Microsoft.CodeAnalysis.ErrorReporting; namespace Microsoft.CodeAnalysis.Features.Intents; internal sealed class IntentDataProvider( - string? serializedIntentData, - CleanCodeGenerationOptionsProvider fallbackOptions) + string? serializedIntentData) { private static readonly Lazy s_serializerOptions = new Lazy(() => { @@ -24,8 +22,6 @@ internal sealed class IntentDataProvider( return serializerOptions; }); - public readonly CleanCodeGenerationOptionsProvider FallbackOptions = fallbackOptions; - private readonly string? _serializedIntentData = serializedIntentData; public T? GetIntentData() where T : class diff --git a/src/Features/Core/Portable/IntroduceVariable/AbstractIntroduceLocalForExpressionCodeRefactoringProvider.cs b/src/Features/Core/Portable/IntroduceVariable/AbstractIntroduceLocalForExpressionCodeRefactoringProvider.cs index a2ca5e25247a8..7805add83558e 100644 --- a/src/Features/Core/Portable/IntroduceVariable/AbstractIntroduceLocalForExpressionCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/IntroduceVariable/AbstractIntroduceLocalForExpressionCodeRefactoringProvider.cs @@ -28,7 +28,7 @@ internal abstract class AbstractIntroduceLocalForExpressionCodeRefactoringProvid protected abstract TLocalDeclarationStatementSyntax FixupLocalDeclaration(TExpressionStatementSyntax expressionStatement, TLocalDeclarationStatementSyntax localDeclaration); protected abstract TExpressionStatementSyntax FixupDeconstruction(TExpressionStatementSyntax expressionStatement, TExpressionStatementSyntax localDeclaration); protected abstract Task CreateTupleDeconstructionAsync( - Document document, CodeActionOptionsProvider optionsProvider, INamedTypeSymbol tupleType, TExpressionSyntax expression, CancellationToken cancellationToken); + Document document, INamedTypeSymbol tupleType, TExpressionSyntax expression, CancellationToken cancellationToken); public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContext context) { @@ -55,7 +55,7 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex context.RegisterRefactoring( CodeAction.Create( string.Format(FeaturesResources.Deconstruct_locals_for_0, nodeString), - cancellationToken => IntroduceLocalAsync(document, context.Options, expressionStatement, type, deconstruct: true, cancellationToken), + cancellationToken => IntroduceLocalAsync(document, expressionStatement, type, deconstruct: true, cancellationToken), nameof(FeaturesResources.Deconstruct_locals_for_0) + "_" + nodeString), expressionStatement.Span); } @@ -63,7 +63,7 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex context.RegisterRefactoring( CodeAction.Create( string.Format(FeaturesResources.Introduce_local_for_0, nodeString), - cancellationToken => IntroduceLocalAsync(document, context.Options, expressionStatement, type, deconstruct: false, cancellationToken), + cancellationToken => IntroduceLocalAsync(document, expressionStatement, type, deconstruct: false, cancellationToken), nameof(FeaturesResources.Introduce_local_for_0) + "_" + nodeString), expressionStatement.Span); } @@ -78,7 +78,6 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex private async Task IntroduceLocalAsync( Document document, - CodeActionOptionsProvider optionsProvider, TExpressionStatementSyntax expressionStatement, ITypeSymbol type, bool deconstruct, @@ -112,7 +111,7 @@ async Task CreateLocalDeclarationAsync() { Contract.ThrowIfNull(type); return await this.CreateTupleDeconstructionAsync( - document, optionsProvider, (INamedTypeSymbol)type, expression, cancellationToken).ConfigureAwait(false); + document, (INamedTypeSymbol)type, expression, cancellationToken).ConfigureAwait(false); } else { diff --git a/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.MoveItemsToNamespaceCodeAction.cs b/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.MoveItemsToNamespaceCodeAction.cs index 1e71055214629..6982779ebe024 100644 --- a/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.MoveItemsToNamespaceCodeAction.cs +++ b/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.MoveItemsToNamespaceCodeAction.cs @@ -2,14 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.CodeAnalysis.CodeCleanup; - namespace Microsoft.CodeAnalysis.MoveToNamespace; internal abstract partial class AbstractMoveToNamespaceCodeAction { - private sealed class MoveItemsToNamespaceCodeAction(IMoveToNamespaceService changeNamespaceService, MoveToNamespaceAnalysisResult analysisResult, CodeCleanupOptionsProvider cleanupOptions) - : AbstractMoveToNamespaceCodeAction(changeNamespaceService, analysisResult, cleanupOptions) + private sealed class MoveItemsToNamespaceCodeAction(IMoveToNamespaceService changeNamespaceService, MoveToNamespaceAnalysisResult analysisResult) + : AbstractMoveToNamespaceCodeAction(changeNamespaceService, analysisResult) { public override string Title => FeaturesResources.Move_contents_to_namespace; } diff --git a/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.MoveTypeToNamespaceCodeAction.cs b/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.MoveTypeToNamespaceCodeAction.cs index 92ae0fd4a6584..9cb514dc1950e 100644 --- a/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.MoveTypeToNamespaceCodeAction.cs +++ b/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.MoveTypeToNamespaceCodeAction.cs @@ -2,14 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.CodeAnalysis.CodeCleanup; - namespace Microsoft.CodeAnalysis.MoveToNamespace; internal abstract partial class AbstractMoveToNamespaceCodeAction { - private class MoveTypeToNamespaceCodeAction(IMoveToNamespaceService changeNamespaceService, MoveToNamespaceAnalysisResult analysisResult, CodeCleanupOptionsProvider cleanupOptions) - : AbstractMoveToNamespaceCodeAction(changeNamespaceService, analysisResult, cleanupOptions) + private class MoveTypeToNamespaceCodeAction(IMoveToNamespaceService changeNamespaceService, MoveToNamespaceAnalysisResult analysisResult) + : AbstractMoveToNamespaceCodeAction(changeNamespaceService, analysisResult) { public override string Title => FeaturesResources.Move_to_namespace; } diff --git a/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.cs b/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.cs index 92160bfe57ea4..2f6670716e166 100644 --- a/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.cs +++ b/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.cs @@ -17,12 +17,10 @@ namespace Microsoft.CodeAnalysis.MoveToNamespace; internal abstract partial class AbstractMoveToNamespaceCodeAction( IMoveToNamespaceService moveToNamespaceService, - MoveToNamespaceAnalysisResult analysisResult, - CodeCleanupOptionsProvider cleanupOptions) : CodeActionWithOptions + MoveToNamespaceAnalysisResult analysisResult) : CodeActionWithOptions { private readonly IMoveToNamespaceService _moveToNamespaceService = moveToNamespaceService; private readonly MoveToNamespaceAnalysisResult _moveToNamespaceAnalysisResult = analysisResult; - private readonly CodeCleanupOptionsProvider _cleanupOptions = cleanupOptions; /// /// This code action does notify clients about the rename it performs. However, this is an optional part of @@ -50,7 +48,6 @@ protected sealed override async Task> ComputeOp var moveToNamespaceResult = await _moveToNamespaceService.MoveToNamespaceAsync( _moveToNamespaceAnalysisResult, moveToNamespaceOptions.Namespace, - _cleanupOptions, cancellationToken).ConfigureAwait(false); if (moveToNamespaceResult.Succeeded) @@ -89,11 +86,11 @@ private static ImmutableArray CreateRenameOperations(MoveTo return operations.ToImmutableAndClear(); } - public static AbstractMoveToNamespaceCodeAction Generate(IMoveToNamespaceService changeNamespaceService, MoveToNamespaceAnalysisResult analysisResult, CodeCleanupOptionsProvider cleanupOptions) + public static AbstractMoveToNamespaceCodeAction Generate(IMoveToNamespaceService changeNamespaceService, MoveToNamespaceAnalysisResult analysisResult) => analysisResult.Container switch { - MoveToNamespaceAnalysisResult.ContainerType.NamedType => new MoveTypeToNamespaceCodeAction(changeNamespaceService, analysisResult, cleanupOptions), - MoveToNamespaceAnalysisResult.ContainerType.Namespace => new MoveItemsToNamespaceCodeAction(changeNamespaceService, analysisResult, cleanupOptions), + MoveToNamespaceAnalysisResult.ContainerType.NamedType => new MoveTypeToNamespaceCodeAction(changeNamespaceService, analysisResult), + MoveToNamespaceAnalysisResult.ContainerType.Namespace => new MoveItemsToNamespaceCodeAction(changeNamespaceService, analysisResult), _ => throw ExceptionUtilities.UnexpectedValue(analysisResult.Container) }; } diff --git a/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceService.cs b/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceService.cs index 28fd071e5eca4..ef0bc9927970e 100644 --- a/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceService.cs +++ b/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceService.cs @@ -25,9 +25,9 @@ namespace Microsoft.CodeAnalysis.MoveToNamespace; internal interface IMoveToNamespaceService : ILanguageService { - Task> GetCodeActionsAsync(Document document, TextSpan span, CodeCleanupOptionsProvider options, CancellationToken cancellationToken); + Task> GetCodeActionsAsync(Document document, TextSpan span, CancellationToken cancellationToken); Task AnalyzeTypeAtPositionAsync(Document document, int position, CancellationToken cancellationToken); - Task MoveToNamespaceAsync(MoveToNamespaceAnalysisResult analysisResult, string targetNamespace, CodeCleanupOptionsProvider options, CancellationToken cancellationToken); + Task MoveToNamespaceAsync(MoveToNamespaceAnalysisResult analysisResult, string targetNamespace, CancellationToken cancellationToken); MoveToNamespaceOptionsResult GetChangeNamespaceOptions(Document document, string defaultNamespace, ImmutableArray namespaces); IMoveToNamespaceOptionsService OptionsService { get; } } @@ -50,7 +50,6 @@ protected AbstractMoveToNamespaceService(IMoveToNamespaceOptionsService moveToNa public async Task> GetCodeActionsAsync( Document document, TextSpan span, - CodeCleanupOptionsProvider cleanupOptions, CancellationToken cancellationToken) { // Code actions cannot be completed without the options needed @@ -61,7 +60,7 @@ public async Task> GetCodeActi if (typeAnalysisResult.CanPerform) { - return [AbstractMoveToNamespaceCodeAction.Generate(this, typeAnalysisResult, cleanupOptions)]; + return [AbstractMoveToNamespaceCodeAction.Generate(this, typeAnalysisResult)]; } } @@ -168,7 +167,6 @@ private static bool ContainsMultipleTypesInSpine(SyntaxNode node) public Task MoveToNamespaceAsync( MoveToNamespaceAnalysisResult analysisResult, string targetNamespace, - CodeCleanupOptionsProvider fallbackOptions, CancellationToken cancellationToken) { if (!analysisResult.CanPerform) @@ -179,7 +177,7 @@ public Task MoveToNamespaceAsync( return analysisResult.Container switch { MoveToNamespaceAnalysisResult.ContainerType.Namespace => MoveItemsInNamespaceAsync(analysisResult.Document, analysisResult.SyntaxNode, targetNamespace, cancellationToken), - MoveToNamespaceAnalysisResult.ContainerType.NamedType => MoveTypeToNamespaceAsync(analysisResult.Document, analysisResult.SyntaxNode, targetNamespace, fallbackOptions, cancellationToken), + MoveToNamespaceAnalysisResult.ContainerType.NamedType => MoveTypeToNamespaceAsync(analysisResult.Document, analysisResult.SyntaxNode, targetNamespace, cancellationToken), _ => throw new InvalidOperationException(), }; } @@ -237,7 +235,6 @@ private static async Task MoveTypeToNamespaceAsync( Document document, SyntaxNode container, string targetNamespace, - CodeCleanupOptionsProvider fallbackOptions, CancellationToken cancellationToken) { var moveTypeService = document.GetLanguageService(); @@ -254,7 +251,6 @@ private static async Task MoveTypeToNamespaceAsync( document, moveSpan, MoveTypeOperationKind.MoveTypeNamespaceScope, - fallbackOptions, cancellationToken).ConfigureAwait(false); var modifiedDocument = modifiedSolution.GetDocument(document.Id); diff --git a/src/Features/Core/Portable/MoveToNamespace/MoveToNamespaceCodeActionProvider.cs b/src/Features/Core/Portable/MoveToNamespace/MoveToNamespaceCodeActionProvider.cs index 69f0f92755726..fff1e8a521add 100644 --- a/src/Features/Core/Portable/MoveToNamespace/MoveToNamespaceCodeActionProvider.cs +++ b/src/Features/Core/Portable/MoveToNamespace/MoveToNamespaceCodeActionProvider.cs @@ -27,7 +27,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte { var (document, textSpan, cancellationToken) = context; var moveToNamespaceService = document.GetLanguageService(); - var actions = await moveToNamespaceService.GetCodeActionsAsync(document, textSpan, context.Options, cancellationToken).ConfigureAwait(false); + var actions = await moveToNamespaceService.GetCodeActionsAsync(document, textSpan, cancellationToken).ConfigureAwait(false); context.RegisterRefactorings(actions); } } diff --git a/src/Features/ExternalAccess/OmniSharp/Internal/ExtractInterface/OmniSharpExtractInterfaceOptionsService.cs b/src/Features/ExternalAccess/OmniSharp/Internal/ExtractInterface/OmniSharpExtractInterfaceOptionsService.cs index 13fc5e88d8888..2c9fd983a6aa3 100644 --- a/src/Features/ExternalAccess/OmniSharp/Internal/ExtractInterface/OmniSharpExtractInterfaceOptionsService.cs +++ b/src/Features/ExternalAccess/OmniSharp/Internal/ExtractInterface/OmniSharpExtractInterfaceOptionsService.cs @@ -43,7 +43,6 @@ public async Task GetExtractInterfaceOptionsAsync string defaultNamespace, string generatedNameTypeParameterSuffix, string languageName, - CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) { var result = await _omniSharpExtractInterfaceOptionsService.GetExtractInterfaceOptionsAsync(extractableMembers, defaultInterfaceName).ConfigureAwait(false); @@ -52,8 +51,7 @@ public async Task GetExtractInterfaceOptionsAsync result.IncludedMembers, result.InterfaceName, result.FileName, - (ExtractInterfaceOptionsResult.ExtractLocation)result.Location, - fallbackOptions); + (ExtractInterfaceOptionsResult.ExtractLocation)result.Location); } } } diff --git a/src/Features/VisualBasic/Portable/IntroduceVariable/VisualBasicIntroduceLocalForExpressionCodeRefactoringProvider.vb b/src/Features/VisualBasic/Portable/IntroduceVariable/VisualBasicIntroduceLocalForExpressionCodeRefactoringProvider.vb index 26d7f0c62c887..5f3a1ce573cfe 100644 --- a/src/Features/VisualBasic/Portable/IntroduceVariable/VisualBasicIntroduceLocalForExpressionCodeRefactoringProvider.vb +++ b/src/Features/VisualBasic/Portable/IntroduceVariable/VisualBasicIntroduceLocalForExpressionCodeRefactoringProvider.vb @@ -48,7 +48,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.IntroduceVariable Throw ExceptionUtilities.Unreachable() End Function - Protected Overrides Function CreateTupleDeconstructionAsync(document As Document, optionsProvider As CodeActionOptionsProvider, tupleType As INamedTypeSymbol, expression As ExpressionSyntax, cancellationToken As CancellationToken) As Task(Of ExpressionStatementSyntax) + Protected Overrides Function CreateTupleDeconstructionAsync(document As Document, tupleType As INamedTypeSymbol, expression As ExpressionSyntax, cancellationToken As CancellationToken) As Task(Of ExpressionStatementSyntax) Throw New NotImplementedException() End Function End Class diff --git a/src/VisualStudio/Core/Def/ExtractInterface/VisualStudioExtractInterfaceOptionsService.cs b/src/VisualStudio/Core/Def/ExtractInterface/VisualStudioExtractInterfaceOptionsService.cs index f41f6fde4282d..fd7fb9dcead35 100644 --- a/src/VisualStudio/Core/Def/ExtractInterface/VisualStudioExtractInterfaceOptionsService.cs +++ b/src/VisualStudio/Core/Def/ExtractInterface/VisualStudioExtractInterfaceOptionsService.cs @@ -50,7 +50,6 @@ public async Task GetExtractInterfaceOptionsAsync string defaultNamespace, string generatedNameTypeParameterSuffix, string languageName, - CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) { using var cancellationTokenSource = new CancellationTokenSource(); @@ -90,8 +89,7 @@ public async Task GetExtractInterfaceOptionsAsync includedMembers: includedMembers.AsImmutable(), interfaceName: viewModel.DestinationViewModel.TypeName.Trim(), fileName: viewModel.DestinationViewModel.FileName.Trim(), - location: GetLocation(viewModel.DestinationViewModel.Destination), - fallbackOptions); + location: GetLocation(viewModel.DestinationViewModel.Destination)); } else { From ffd81eb6cf447dd7d5cf60234964324afbc5a97d Mon Sep 17 00:00:00 2001 From: tmat Date: Tue, 9 Jul 2024 14:17:49 -0700 Subject: [PATCH 2/3] Remove DoNotPutOutOrRefOnStructOn extract method option --- .../ExtractMethod/ExtractMethodBase.cs | 21 ++-- .../ExtractMethod/ExtractMethodTests.cs | 37 +----- .../ExtractMethodCommandHandler.cs | 53 +------- .../Test/Options/GlobalOptionsTests.cs | 1 - .../ExtractMethodTests.DataFlowAnalysis.vb | 116 ------------------ .../ExtractMethodTests.LanguageInteraction.vb | 32 +---- .../ExtractMethod/ExtractMethodTests.vb | 26 ++-- .../CSharpExtractMethodService.cs | 4 +- .../CSharpSelectionResult.ExpressionResult.cs | 3 +- .../CSharpSelectionResult.StatementResult.cs | 3 +- .../ExtractMethod/CSharpSelectionResult.cs | 8 +- .../ExtractMethod/CSharpSelectionValidator.cs | 4 +- ...actExtractMethodCodeRefactoringProvider.cs | 2 +- .../AbstractExtractMethodService.cs | 4 +- .../ExtractMethod/MethodExtractor.Analyzer.cs | 32 ----- .../Portable/ExtractMethod/SelectionResult.cs | 3 - .../ExtractMethod/SelectionValidator.cs | 4 +- .../VisualBasicExtractMethodService.vb | 3 +- .../VisualBasicSelectionResult.vb | 4 - .../VisualBasicSelectionValidator.vb | 6 +- .../Options/CodeActionOptionsStorage.cs | 1 - .../Options/ExtractMethodOptionsStorage.cs | 15 --- .../Options/AdvancedOptionPageControl.xaml.cs | 3 - .../AutomationObject.ExtractMethod.cs | 6 - .../Def/Options/VisualStudioOptionStorage.cs | 1 - .../Options/AdvancedOptionPageControl.xaml | 8 -- .../Options/AdvancedOptionPageControl.xaml.vb | 3 - .../AutomationObject.ExtractMethod.vb | 9 -- .../ExtractMethod/ExtractMethodOptions.cs | 22 +--- .../CoreTest/Remote/ServiceDescriptorTests.cs | 1 - .../CoreTestUtilities/VBOptionsFactory.cs | 5 +- .../Core/CodeFixes/CodeActionOptions.cs | 2 - 32 files changed, 40 insertions(+), 402 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs b/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs index dbf74460c43ef..c370c7cf0e1e5 100644 --- a/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs +++ b/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs @@ -24,7 +24,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ExtractMethod; [UseExportProvider] public class ExtractMethodBase { - protected static async Task ExpectExtractMethodToFailAsync(string codeWithMarker, bool dontPutOutOrRefOnStruct = true, string[] features = null) + protected static async Task ExpectExtractMethodToFailAsync(string codeWithMarker, string[] features = null) { ParseOptions parseOptions = null; if (features != null) @@ -36,20 +36,19 @@ protected static async Task ExpectExtractMethodToFailAsync(string codeWithMarker using var workspace = EditorTestWorkspace.CreateCSharp(codeWithMarker, parseOptions: parseOptions); var testDocument = workspace.Documents.First(); var textSpan = testDocument.SelectedSpans.Single(); - var treeAfterExtractMethod = await ExtractMethodAsync(workspace, testDocument, succeed: false, dontPutOutOrRefOnStruct: dontPutOutOrRefOnStruct); + var treeAfterExtractMethod = await ExtractMethodAsync(workspace, testDocument, succeed: false); } protected static async Task ExpectExtractMethodToFailAsync( string codeWithMarker, string expected, - bool dontPutOutOrRefOnStruct = true, CSharpParseOptions parseOptions = null) { using var workspace = EditorTestWorkspace.CreateCSharp(codeWithMarker, parseOptions: parseOptions); var testDocument = workspace.Documents.Single(); var subjectBuffer = testDocument.GetTextBuffer(); - var tree = await ExtractMethodAsync(workspace, testDocument, succeed: false, dontPutOutOrRefOnStruct: dontPutOutOrRefOnStruct); + var tree = await ExtractMethodAsync(workspace, testDocument, succeed: false); using (var edit = subjectBuffer.CreateEdit()) { @@ -77,7 +76,6 @@ protected static async Task TestExtractMethodAsync( string codeWithMarker, string expected, bool temporaryFailing = false, - bool dontPutOutOrRefOnStruct = true, CSharpParseOptions parseOptions = null) { using var workspace = EditorTestWorkspace.CreateCSharp(codeWithMarker, parseOptions: parseOptions); @@ -85,8 +83,7 @@ protected static async Task TestExtractMethodAsync( var subjectBuffer = testDocument.GetTextBuffer(); var tree = await ExtractMethodAsync( - workspace, testDocument, - dontPutOutOrRefOnStruct: dontPutOutOrRefOnStruct); + workspace, testDocument); using (var edit = subjectBuffer.CreateEdit()) { @@ -116,8 +113,7 @@ protected static async Task TestExtractMethodAsync( protected static async Task ExtractMethodAsync( EditorTestWorkspace workspace, EditorTestHostDocument testDocument, - bool succeed = true, - bool dontPutOutOrRefOnStruct = true) + bool succeed = true) { var document = workspace.CurrentSolution.GetDocument(testDocument.Id); Assert.NotNull(document); @@ -126,11 +122,10 @@ protected static async Task ExtractMethodAsync( { CodeGenerationOptions = CodeGenerationOptions.GetDefault(document.Project.Services), CodeCleanupOptions = CodeCleanupOptions.GetDefault(document.Project.Services), - ExtractOptions = new() { DoNotPutOutOrRefOnStruct = dontPutOutOrRefOnStruct } }; var semanticDocument = await SemanticDocument.CreateAsync(document, CancellationToken.None); - var validator = new CSharpSelectionValidator(semanticDocument, testDocument.SelectedSpans.Single(), options.ExtractOptions, localFunction: false); + var validator = new CSharpSelectionValidator(semanticDocument, testDocument.SelectedSpans.Single(), localFunction: false); var (selectedCode, status) = await validator.GetValidSelectionAsync(CancellationToken.None); if (!succeed && status.Failed) @@ -173,7 +168,7 @@ protected static async Task TestSelectionAsync(string codeWithMarker, bool expec Assert.NotNull(document); var semanticDocument = await SemanticDocument.CreateAsync(document, CancellationToken.None); - var validator = new CSharpSelectionValidator(semanticDocument, textSpanOverride ?? namedSpans["b"].Single(), ExtractMethodOptions.Default, localFunction: false); + var validator = new CSharpSelectionValidator(semanticDocument, textSpanOverride ?? namedSpans["b"].Single(), localFunction: false); var (result, status) = await validator.GetValidSelectionAsync(CancellationToken.None); if (expectedFail) @@ -201,7 +196,7 @@ protected static async Task IterateAllAsync(string code) foreach (var node in iterator) { - var validator = new CSharpSelectionValidator(semanticDocument, node.Span, ExtractMethodOptions.Default, localFunction: false); + var validator = new CSharpSelectionValidator(semanticDocument, node.Span, localFunction: false); var (_, status) = await validator.GetValidSelectionAsync(CancellationToken.None); // check the obvious case diff --git a/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodTests.cs b/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodTests.cs index 2ace095ac04fb..6b59deb117a8e 100644 --- a/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodTests.cs +++ b/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodTests.cs @@ -10973,41 +10973,6 @@ public async Task Hello() await ExpectExtractMethodToFailAsync(code); } - [Fact] - public async Task TestDoNotPutOutOrRefForStructOff() - { - var code = - """ - using System.Threading.Tasks; - - namespace ClassLibrary9 - { - public struct S - { - public int I; - } - - public class Class1 - { - private async Task Test() - { - S s = new S(); - s.I = 10; - - [|int i = await Task.Run(() => - { - var i2 = s.I; - return Test(); - });|] - - return i; - } - } - } - """; - await ExpectExtractMethodToFailAsync(code, dontPutOutOrRefOnStruct: false); - } - [Fact] public async Task TestDoNotPutOutOrRefForStructOn() { @@ -11075,7 +11040,7 @@ private async Task NewMethod(S s) } """; - await TestExtractMethodAsync(code, expected, dontPutOutOrRefOnStruct: true); + await TestExtractMethodAsync(code, expected); } [Theory] diff --git a/src/EditorFeatures/Core/ExtractMethod/ExtractMethodCommandHandler.cs b/src/EditorFeatures/Core/ExtractMethod/ExtractMethodCommandHandler.cs index 496c549a99e77..6d08010693760 100644 --- a/src/EditorFeatures/Core/ExtractMethod/ExtractMethodCommandHandler.cs +++ b/src/EditorFeatures/Core/ExtractMethod/ExtractMethodCommandHandler.cs @@ -139,13 +139,13 @@ private async Task ExecuteWorkerAsync( if (document is null) return; - var options = await document.GetExtractMethodGenerationOptionsAsync(_globalOptions, cancellationToken).ConfigureAwait(false); + var options = await document.GetExtractMethodGenerationOptionsAsync(cancellationToken).ConfigureAwait(false); var result = await ExtractMethodService.ExtractMethodAsync( document, span, localFunction: false, options, cancellationToken).ConfigureAwait(false); Contract.ThrowIfNull(result); result = await NotifyUserIfNecessaryAsync( - document, span, options, result, cancellationToken).ConfigureAwait(false); + document, result, cancellationToken).ConfigureAwait(false); if (result is null) return; @@ -186,7 +186,7 @@ private void ApplyChange_OnUIThread( } private async Task NotifyUserIfNecessaryAsync( - Document document, TextSpan span, ExtractMethodGenerationOptions options, ExtractMethodResult result, CancellationToken cancellationToken) + Document document, ExtractMethodResult result, CancellationToken cancellationToken) { // If we succeeded without any problems, just proceed without notifying the user. if (result is { Succeeded: true, Reasons.Length: 0 }) @@ -198,31 +198,9 @@ private void ApplyChange_OnUIThread( if (notificationService is null) return null; - // The initial extract method failed, or it succeeded with warning reasons. Attempt again with - // different options to see if we get better results. - var alternativeResult = await TryWithoutMakingValueTypesRefAsync( - document, span, result, options, cancellationToken).ConfigureAwait(false); - // We're about to show an notification to the user. Switch to the ui thread to do so. await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); - if (alternativeResult is { Succeeded: true, Reasons.Length: 0 }) - { - if (!notificationService.ConfirmMessageBox( - EditorFeaturesResources.Extract_method_encountered_the_following_issues + Environment.NewLine + Environment.NewLine + - string.Join(Environment.NewLine, result.Reasons) + Environment.NewLine + Environment.NewLine + - EditorFeaturesResources.We_can_fix_the_error_by_not_making_struct_out_ref_parameter_s_Do_you_want_to_proceed, - title: EditorFeaturesResources.Extract_Method, - severity: NotificationSeverity.Error)) - { - // We handled the command, displayed a notification and did not produce code. - return null; - } - - // Otherwise, prefer the new approach that has less problems. - return alternativeResult; - } - // The alternative approach wasn't better. If we failed, just let the user know and bail out. Otherwise, // if we succeeded with messages, tell the user and let them decide if they want to proceed or not. if (!result.Succeeded) @@ -253,29 +231,4 @@ private void ApplyChange_OnUIThread( return result; } - - private static async Task TryWithoutMakingValueTypesRefAsync( - Document document, TextSpan span, ExtractMethodResult result, ExtractMethodGenerationOptions options, CancellationToken cancellationToken) - { - if (options.ExtractOptions.DoNotPutOutOrRefOnStruct || !result.Reasons.IsSingle()) - return null; - - var reason = result.Reasons.FirstOrDefault(); - var length = FeaturesResources.Asynchronous_method_cannot_have_ref_out_parameters_colon_bracket_0_bracket.IndexOf(':'); - if (reason != null && length > 0 && reason.IndexOf(FeaturesResources.Asynchronous_method_cannot_have_ref_out_parameters_colon_bracket_0_bracket[..length], 0, length, StringComparison.Ordinal) >= 0) - { - var newResult = await ExtractMethodService.ExtractMethodAsync( - document, - span, - localFunction: false, - options with { ExtractOptions = options.ExtractOptions with { DoNotPutOutOrRefOnStruct = true } }, - cancellationToken).ConfigureAwait(false); - - // retry succeeded, return new result - if (newResult.Succeeded) - return newResult; - } - - return null; - } } diff --git a/src/EditorFeatures/Test/Options/GlobalOptionsTests.cs b/src/EditorFeatures/Test/Options/GlobalOptionsTests.cs index 2c874f7679800..cd13e03ce2f14 100644 --- a/src/EditorFeatures/Test/Options/GlobalOptionsTests.cs +++ b/src/EditorFeatures/Test/Options/GlobalOptionsTests.cs @@ -191,7 +191,6 @@ public void ReadingOptionsFromGlobalOptions(string language) VerifyDataMembersHaveNonDefaultValues(globalOptions.GetAutoFormattingOptions(language), AutoFormattingOptions.Default, language); VerifyDataMembersHaveNonDefaultValues(globalOptions.GetBlockStructureOptions(language, isMetadataAsSource: false), BlockStructureOptions.Default, language); VerifyDataMembersHaveNonDefaultValues(globalOptions.GetDocumentationCommentOptions(globalOptions.GetLineFormattingOptions(language), language), DocumentationCommentOptions.Default, language); - VerifyDataMembersHaveNonDefaultValues(globalOptions.GetExtractMethodOptions(language), ExtractMethodOptions.Default, language); VerifyDataMembersHaveNonDefaultValues(globalOptions.GetImplementTypeOptions(language), ImplementTypeOptions.Default, language); VerifyDataMembersHaveNonDefaultValues(globalOptions.GetMetadataAsSourceOptions(), MetadataAsSourceOptions.Default, language); VerifyDataMembersHaveNonDefaultValues(globalOptions.GetSignatureHelpOptions(language), SignatureHelpOptions.Default, language); diff --git a/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.DataFlowAnalysis.vb b/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.DataFlowAnalysis.vb index ca4c71b7864ee..5cd0b172040b1 100644 --- a/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.DataFlowAnalysis.vb +++ b/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.DataFlowAnalysis.vb @@ -5831,122 +5831,6 @@ End Module Await TestExtractMethodAsync(code, expected) End Function - - - Public Async Function TestStructure1() As Task - Dim code = Structure XType - Public Y As YType -End Structure - -Structure YType - Public Z As ZType -End Structure - -Structure ZType - Public Value As Integer -End Structure - -Module Program - Sub Main(args As String()) - Dim x As XType - - Dim value = [|x.Y|].Z.Value - With x - .Y.Z.Value += 1 - End With - End Sub -End Module - Dim expected = Structure XType - Public Y As YType -End Structure - -Structure YType - Public Z As ZType -End Structure - -Structure ZType - Public Value As Integer -End Structure - -Module Program - Sub Main(args As String()) - Dim x As XType - - Dim value = GetY(x).Z.Value - With x - .Y.Z.Value += 1 - End With - End Sub - - Private Function GetY(ByRef x As XType) As YType - Return x.Y - End Function -End Module - Await TestExtractMethodAsync(code, expected, dontPutOutOrRefOnStruct:=False) - End Function - - - Public Async Function TestStructure2() As Task - Dim code = Imports System -Imports System.Collections.Generic -Imports System.Linq - -Structure SSSS3 - Public A As String - Public B As Integer -End Structure - -Structure SSSS2 - Public S3 As SSSS3 -End Structure - -Structure SSSS - Public S2 As SSSS2 -End Structure - -Structure SSS - Public S As SSSS -End Structure - -Class Clazz - Sub TEST() - Dim x As New SSS() - [|x.S|].S2.S3.A = "1" - End Sub -End Class - Dim expected = Imports System -Imports System.Collections.Generic -Imports System.Linq - -Structure SSSS3 - Public A As String - Public B As Integer -End Structure - -Structure SSSS2 - Public S3 As SSSS3 -End Structure - -Structure SSSS - Public S2 As SSSS2 -End Structure - -Structure SSS - Public S As SSSS -End Structure - -Class Clazz - Sub TEST() - Dim x As New SSS() - GetS(x).S2.S3.A = "1" - End Sub - - Private Shared Function GetS(ByRef x As SSS) As SSSS - Return x.S - End Function -End Class - Await TestExtractMethodAsync(code, expected, dontPutOutOrRefOnStruct:=False) - End Function End Class End Class End Namespace diff --git a/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.LanguageInteraction.vb b/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.LanguageInteraction.vb index b2aa1f15e63ea..60c7582d541a0 100644 --- a/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.LanguageInteraction.vb +++ b/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.LanguageInteraction.vb @@ -3247,36 +3247,6 @@ End Module Await TestExtractMethodAsync(code, expected) End Function - - Public Async Function TestDoNotPutOutOrRefOnStructOff() As Task - Dim code = - -Imports System.Threading.Tasks - -Namespace ClassLibrary9 - Public Structure S - Public I As Integer - End Structure - - Public Class Class1 - Public Async Function Test() As Task(Of Integer) - Dim s = New S() - s.I = 10 - - [|Dim i = Await Task.Run(Function() - Dim i2 = s.I - Return Test() - End Function)|] - - Return i - End Function - End Class -End Namespace - - - Await ExpectExtractMethodToFailAsync(code, dontPutOutOrRefOnStruct:=False) - End Function - Public Async Function TestDoNotPutOutOrRefOnStructOn() As Task Dim code = @@ -3332,7 +3302,7 @@ Namespace ClassLibrary9 End Class End Namespace - Await TestExtractMethodAsync(code, expected, dontPutOutOrRefOnStruct:=True) + Await TestExtractMethodAsync(code, expected) End Function diff --git a/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.vb b/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.vb index 90cc85ab1c821..ef0e156145c7a 100644 --- a/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.vb +++ b/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.vb @@ -8,8 +8,6 @@ Imports Microsoft.CodeAnalysis Imports Microsoft.CodeAnalysis.CodeCleanup Imports Microsoft.CodeAnalysis.CodeGeneration Imports Microsoft.CodeAnalysis.Editor.UnitTests.Extensions -Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces -Imports Microsoft.CodeAnalysis.ExtractMethod Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.Text.Shared.Extensions Imports Microsoft.CodeAnalysis.UnitTests @@ -20,13 +18,13 @@ Imports Microsoft.VisualStudio.Text Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ExtractMethod <[UseExportProvider]> Partial Public Class ExtractMethodTests - Protected Shared Async Function ExpectExtractMethodToFailAsync(codeWithMarker As XElement, Optional dontPutOutOrRefOnStruct As Boolean = True) As Tasks.Task + Protected Shared Async Function ExpectExtractMethodToFailAsync(codeWithMarker As XElement) As Tasks.Task Dim codeWithoutMarker As String = Nothing Dim textSpan As TextSpan MarkupTestFile.GetSpan(codeWithMarker.NormalizedValue, codeWithoutMarker, textSpan) Using workspace = EditorTestWorkspace.CreateVisualBasic(codeWithoutMarker) - Dim treeAfterExtractMethod = Await ExtractMethodAsync(workspace, workspace.Documents.First(), textSpan, succeeded:=False, dontPutOutOrRefOnStruct:=dontPutOutOrRefOnStruct) + Dim treeAfterExtractMethod = Await ExtractMethodAsync(workspace, workspace.Documents.First(), textSpan, succeeded:=False) End Using End Function @@ -46,7 +44,6 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ExtractMethod codeWithMarker As String, expected As String, Optional temporaryFailing As Boolean = False, - Optional dontPutOutOrRefOnStruct As Boolean = True, Optional metadataReference As String = Nothing ) As Tasks.Task @@ -58,7 +55,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ExtractMethod Dim subjectBuffer = document.GetTextBuffer() Dim textSpan = document.SelectedSpans.First() - Dim tree = Await ExtractMethodAsync(workspace, workspace.Documents.First(), textSpan, dontPutOutOrRefOnStruct:=dontPutOutOrRefOnStruct) + Dim tree = Await ExtractMethodAsync(workspace, workspace.Documents.First(), textSpan) Using edit = subjectBuffer.CreateEdit() edit.Replace(0, edit.Snapshot.Length, tree.ToFullString()) @@ -81,28 +78,24 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ExtractMethod codeWithMarker As XElement, expected As XElement, Optional temporaryFailing As Boolean = False, - Optional dontPutOutOrRefOnStruct As Boolean = True, Optional metadataReference As String = Nothing ) As Tasks.Task - Await TestExtractMethodAsync(codeWithMarker.NormalizedValue, expected.NormalizedValue, temporaryFailing, dontPutOutOrRefOnStruct, metadataReference) + Await TestExtractMethodAsync(codeWithMarker.NormalizedValue, expected.NormalizedValue, temporaryFailing, metadataReference) End Function Private Shared Async Function ExtractMethodAsync( workspace As EditorTestWorkspace, testDocument As EditorTestHostDocument, textSpan As TextSpan, - Optional succeeded As Boolean = True, - Optional dontPutOutOrRefOnStruct As Boolean = True) As Tasks.Task(Of SyntaxNode) + Optional succeeded As Boolean = True) As Task(Of SyntaxNode) Dim snapshotSpan = textSpan.ToSnapshotSpan(testDocument.GetTextBuffer().CurrentSnapshot) Dim document = workspace.CurrentSolution.GetDocument(testDocument.Id) Assert.NotNull(document) - Dim extractOptions = New ExtractMethodOptions() With {.DoNotPutOutOrRefOnStruct = dontPutOutOrRefOnStruct} - Dim sdocument = Await SemanticDocument.CreateAsync(document, CancellationToken.None) - Dim validator = New VisualBasicSelectionValidator(sdocument, snapshotSpan.Span.ToTextSpan(), extractOptions) + Dim validator = New VisualBasicSelectionValidator(sdocument, snapshotSpan.Span.ToTextSpan()) Dim tuple = Await validator.GetValidSelectionAsync(CancellationToken.None) Dim selectedCode = tuple.Item1 @@ -114,8 +107,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ExtractMethod ' extract method Dim extractGenerationOptions = VBOptionsFactory.CreateExtractMethodGenerationOptions( CodeGenerationOptions.GetDefault(document.Project.Services), - CodeCleanupOptions.GetDefault(document.Project.Services), - extractOptions) + CodeCleanupOptions.GetDefault(document.Project.Services)) Dim extractor = New VisualBasicMethodExtractor(selectedCode, extractGenerationOptions) Dim result = extractor.ExtractMethod(status, CancellationToken.None) @@ -145,7 +137,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ExtractMethod Assert.NotNull(document) Dim sdocument = Await SemanticDocument.CreateAsync(document, CancellationToken.None) - Dim validator = New VisualBasicSelectionValidator(sdocument, namedSpans("b").Single(), ExtractMethodOptions.Default) + Dim validator = New VisualBasicSelectionValidator(sdocument, namedSpans("b").Single()) Dim tuple = Await validator.GetValidSelectionAsync(CancellationToken.None) Dim result = tuple.Item1 Dim status = tuple.Item2 @@ -180,7 +172,7 @@ End Class For Each node In iterator Try - Dim validator = New VisualBasicSelectionValidator(sdocument, node.Span, ExtractMethodOptions.Default) + Dim validator = New VisualBasicSelectionValidator(sdocument, node.Span) Dim tuple = Await validator.GetValidSelectionAsync(CancellationToken.None) Dim result = tuple.Item1 Dim status = tuple.Item2 diff --git a/src/Features/CSharp/Portable/ExtractMethod/CSharpExtractMethodService.cs b/src/Features/CSharp/Portable/ExtractMethod/CSharpExtractMethodService.cs index f3f4f4e58269e..3d44fda77430b 100644 --- a/src/Features/CSharp/Portable/ExtractMethod/CSharpExtractMethodService.cs +++ b/src/Features/CSharp/Portable/ExtractMethod/CSharpExtractMethodService.cs @@ -22,8 +22,8 @@ internal sealed class CSharpExtractMethodService() : AbstractExtractMethodServic StatementSyntax, ExpressionSyntax> { - protected override CSharpSelectionValidator CreateSelectionValidator(SemanticDocument document, TextSpan textSpan, ExtractMethodOptions options, bool localFunction) - => new(document, textSpan, options, localFunction); + protected override CSharpSelectionValidator CreateSelectionValidator(SemanticDocument document, TextSpan textSpan, bool localFunction) + => new(document, textSpan, localFunction); protected override CSharpMethodExtractor CreateMethodExtractor(CSharpSelectionResult selectionResult, ExtractMethodGenerationOptions options, bool localFunction) => new(selectionResult, options, localFunction); diff --git a/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.ExpressionResult.cs b/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.ExpressionResult.cs index 03124561276a5..46fc988d86f19 100644 --- a/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.ExpressionResult.cs +++ b/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.ExpressionResult.cs @@ -18,13 +18,12 @@ internal partial class CSharpSelectionResult private class ExpressionResult( TextSpan originalSpan, TextSpan finalSpan, - ExtractMethodOptions options, bool selectionInExpression, SemanticDocument document, SyntaxAnnotation firstTokenAnnotation, SyntaxAnnotation lastTokenAnnotation, bool selectionChanged) : CSharpSelectionResult( - originalSpan, finalSpan, options, selectionInExpression, document, firstTokenAnnotation, lastTokenAnnotation, selectionChanged) + originalSpan, finalSpan, selectionInExpression, document, firstTokenAnnotation, lastTokenAnnotation, selectionChanged) { public override bool ContainingScopeHasAsyncKeyword() => false; diff --git a/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.StatementResult.cs b/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.StatementResult.cs index 72feb50438609..6a5d7d34f4ab0 100644 --- a/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.StatementResult.cs +++ b/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.StatementResult.cs @@ -18,13 +18,12 @@ internal partial class CSharpSelectionResult private class StatementResult( TextSpan originalSpan, TextSpan finalSpan, - ExtractMethodOptions options, bool selectionInExpression, SemanticDocument document, SyntaxAnnotation firstTokenAnnotation, SyntaxAnnotation lastTokenAnnotation, bool selectionChanged) : CSharpSelectionResult( - originalSpan, finalSpan, options, selectionInExpression, document, firstTokenAnnotation, lastTokenAnnotation, selectionChanged) + originalSpan, finalSpan, selectionInExpression, document, firstTokenAnnotation, lastTokenAnnotation, selectionChanged) { public override bool ContainingScopeHasAsyncKeyword() { diff --git a/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.cs b/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.cs index 32625c75f94ce..dc66109b8074d 100644 --- a/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.cs +++ b/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.cs @@ -24,7 +24,6 @@ internal abstract partial class CSharpSelectionResult : SelectionResult CreateAsync( TextSpan originalSpan, TextSpan finalSpan, - ExtractMethodOptions options, bool selectionInExpression, SemanticDocument document, SyntaxToken firstToken, @@ -49,13 +48,13 @@ public static async Task CreateAsync( if (selectionInExpression) { return new ExpressionResult( - originalSpan, finalSpan, options, selectionInExpression, + originalSpan, finalSpan, selectionInExpression, newDocument, firstTokenAnnotation, lastTokenAnnotation, selectionChanged); } else { return new StatementResult( - originalSpan, finalSpan, options, selectionInExpression, + originalSpan, finalSpan, selectionInExpression, newDocument, firstTokenAnnotation, lastTokenAnnotation, selectionChanged); } } @@ -63,13 +62,12 @@ public static async Task CreateAsync( protected CSharpSelectionResult( TextSpan originalSpan, TextSpan finalSpan, - ExtractMethodOptions options, bool selectionInExpression, SemanticDocument document, SyntaxAnnotation firstTokenAnnotation, SyntaxAnnotation lastTokenAnnotation, bool selectionChanged) - : base(originalSpan, finalSpan, options, selectionInExpression, + : base(originalSpan, finalSpan, selectionInExpression, document, firstTokenAnnotation, lastTokenAnnotation, selectionChanged) { } diff --git a/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionValidator.cs b/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionValidator.cs index 1e0195d297e03..d1588027fd7b5 100644 --- a/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionValidator.cs +++ b/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionValidator.cs @@ -23,8 +23,7 @@ namespace Microsoft.CodeAnalysis.CSharp.ExtractMethod; internal partial class CSharpSelectionValidator( SemanticDocument document, TextSpan textSpan, - ExtractMethodOptions options, - bool localFunction) : SelectionValidator(document, textSpan, options) + bool localFunction) : SelectionValidator(document, textSpan) { private readonly bool _localFunction = localFunction; @@ -75,7 +74,6 @@ internal partial class CSharpSelectionValidator( var result = await CSharpSelectionResult.CreateAsync( selectionInfo.OriginalSpan, selectionInfo.FinalSpan, - Options, selectionInfo.SelectionInExpression, doc, selectionInfo.FirstTokenInFinalSpan, diff --git a/src/Features/Core/Portable/CodeRefactorings/ExtractMethod/AbstractExtractMethodCodeRefactoringProvider.cs b/src/Features/Core/Portable/CodeRefactorings/ExtractMethod/AbstractExtractMethodCodeRefactoringProvider.cs index e58d370f34b55..65f019826fb69 100644 --- a/src/Features/Core/Portable/CodeRefactorings/ExtractMethod/AbstractExtractMethodCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/CodeRefactorings/ExtractMethod/AbstractExtractMethodCodeRefactoringProvider.cs @@ -47,7 +47,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte if (cancellationToken.IsCancellationRequested) return; - var extractOptions = await document.GetExtractMethodGenerationOptionsAsync(context.Options, cancellationToken).ConfigureAwait(false); + var extractOptions = await document.GetExtractMethodGenerationOptionsAsync(cancellationToken).ConfigureAwait(false); var actions = await GetCodeActionsAsync(document, textSpan, extractOptions, cancellationToken).ConfigureAwait(false); context.RegisterRefactorings(actions); diff --git a/src/Features/Core/Portable/ExtractMethod/AbstractExtractMethodService.cs b/src/Features/Core/Portable/ExtractMethod/AbstractExtractMethodService.cs index 233276566dab2..e29634f9a690d 100644 --- a/src/Features/Core/Portable/ExtractMethod/AbstractExtractMethodService.cs +++ b/src/Features/Core/Portable/ExtractMethod/AbstractExtractMethodService.cs @@ -20,7 +20,7 @@ internal abstract class AbstractExtractMethodService< where TStatementSyntax : SyntaxNode where TExpressionSyntax : SyntaxNode { - protected abstract TValidator CreateSelectionValidator(SemanticDocument document, TextSpan textSpan, ExtractMethodOptions options, bool localFunction); + protected abstract TValidator CreateSelectionValidator(SemanticDocument document, TextSpan textSpan, bool localFunction); protected abstract TExtractor CreateMethodExtractor(TSelectionResult selectionResult, ExtractMethodGenerationOptions options, bool localFunction); public async Task ExtractMethodAsync( @@ -32,7 +32,7 @@ public async Task ExtractMethodAsync( { var semanticDocument = await SemanticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false); - var validator = CreateSelectionValidator(semanticDocument, textSpan, options.ExtractOptions, localFunction); + var validator = CreateSelectionValidator(semanticDocument, textSpan, localFunction); var (selectionResult, status) = await validator.GetValidSelectionAsync(cancellationToken).ConfigureAwait(false); if (selectionResult is null) diff --git a/src/Features/Core/Portable/ExtractMethod/MethodExtractor.Analyzer.cs b/src/Features/Core/Portable/ExtractMethod/MethodExtractor.Analyzer.cs index 1e284257313db..6bf5825826a19 100644 --- a/src/Features/Core/Portable/ExtractMethod/MethodExtractor.Analyzer.cs +++ b/src/Features/Core/Portable/ExtractMethod/MethodExtractor.Analyzer.cs @@ -589,12 +589,6 @@ private bool TryGetVariableStyle( return true; } - if (UserDefinedValueType(model.Compilation, type) && !SelectionResult.Options.DoNotPutOutOrRefOnStruct) - { - variableStyle = AlwaysReturn(variableStyle); - return true; - } - // for captured variable, never try to move the decl into extracted method if (captured && variableStyle == VariableStyle.MoveIn) { @@ -653,32 +647,6 @@ private bool SelectionContainsOnlyIdentifierWithSameType(ITypeSymbol type) return type.Equals(SelectionResult.GetContainingScopeType()); } - private static bool UserDefinedValueType(Compilation compilation, ITypeSymbol type) - { - if (!type.IsValueType || type is IPointerTypeSymbol || type.IsEnumType()) - { - return false; - } - - return type.OriginalDefinition.SpecialType == SpecialType.None && !WellKnownFrameworkValueType(compilation, type); - } - - private static bool WellKnownFrameworkValueType(Compilation compilation, ITypeSymbol type) - { - if (!type.IsValueType) - { - return false; - } - - var cancellationTokenType = compilation.GetTypeByMetadataName(typeof(CancellationToken).FullName!); - if (cancellationTokenType != null && cancellationTokenType.Equals(type)) - { - return true; - } - - return false; - } - protected virtual ITypeSymbol GetSymbolType(SemanticModel model, ISymbol symbol) => symbol switch { diff --git a/src/Features/Core/Portable/ExtractMethod/SelectionResult.cs b/src/Features/Core/Portable/ExtractMethod/SelectionResult.cs index 4e13e4cacc33b..63f9bc8fe2e2e 100644 --- a/src/Features/Core/Portable/ExtractMethod/SelectionResult.cs +++ b/src/Features/Core/Portable/ExtractMethod/SelectionResult.cs @@ -24,7 +24,6 @@ internal abstract class SelectionResult protected SelectionResult( TextSpan originalSpan, TextSpan finalSpan, - ExtractMethodOptions options, bool selectionInExpression, SemanticDocument document, SyntaxAnnotation firstTokenAnnotation, @@ -35,7 +34,6 @@ protected SelectionResult( FinalSpan = finalSpan; SelectionInExpression = selectionInExpression; - Options = options; FirstTokenAnnotation = firstTokenAnnotation; LastTokenAnnotation = lastTokenAnnotation; @@ -67,7 +65,6 @@ public ITypeSymbol GetContainingScopeType() public TextSpan OriginalSpan { get; } public TextSpan FinalSpan { get; } - public ExtractMethodOptions Options { get; } public bool SelectionInExpression { get; } public SemanticDocument SemanticDocument { get; private set; } public SyntaxAnnotation FirstTokenAnnotation { get; } diff --git a/src/Features/Core/Portable/ExtractMethod/SelectionValidator.cs b/src/Features/Core/Portable/ExtractMethod/SelectionValidator.cs index 5c542469702a4..9b78f4bc5cb5d 100644 --- a/src/Features/Core/Portable/ExtractMethod/SelectionValidator.cs +++ b/src/Features/Core/Portable/ExtractMethod/SelectionValidator.cs @@ -21,14 +21,12 @@ internal abstract partial class SelectionValidator< TSelectionResult, TStatementSyntax>( SemanticDocument document, - TextSpan textSpan, - ExtractMethodOptions options) + TextSpan textSpan) where TSelectionResult : SelectionResult where TStatementSyntax : SyntaxNode { protected readonly SemanticDocument SemanticDocument = document; protected readonly TextSpan OriginalSpan = textSpan; - protected readonly ExtractMethodOptions Options = options; public bool ContainsValidSelection => !OriginalSpan.IsEmpty; diff --git a/src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicExtractMethodService.vb b/src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicExtractMethodService.vb index 34f796db8974e..46be28488cb77 100644 --- a/src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicExtractMethodService.vb +++ b/src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicExtractMethodService.vb @@ -25,9 +25,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod Protected Overrides Function CreateSelectionValidator(document As SemanticDocument, textSpan As TextSpan, - options As ExtractMethodOptions, localFunction As Boolean) As VisualBasicSelectionValidator - Return New VisualBasicSelectionValidator(document, textSpan, options) + Return New VisualBasicSelectionValidator(document, textSpan) End Function Protected Overrides Function CreateMethodExtractor(selectionResult As VisualBasicSelectionResult, options As ExtractMethodGenerationOptions, localFunction As Boolean) As VisualBasicMethodExtractor diff --git a/src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicSelectionResult.vb b/src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicSelectionResult.vb index 8324b7c4b49b4..41804ce0d728a 100644 --- a/src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicSelectionResult.vb +++ b/src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicSelectionResult.vb @@ -20,7 +20,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod Public Shared Async Function CreateResultAsync( originalSpan As TextSpan, finalSpan As TextSpan, - options As ExtractMethodOptions, selectionInExpression As Boolean, document As SemanticDocument, firstToken As SyntaxToken, @@ -40,7 +39,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod Return New VisualBasicSelectionResult( originalSpan, finalSpan, - options, selectionInExpression, newDocument, firstAnnotation, @@ -51,7 +49,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod Private Sub New( originalSpan As TextSpan, finalSpan As TextSpan, - options As ExtractMethodOptions, selectionInExpression As Boolean, document As SemanticDocument, firstTokenAnnotation As SyntaxAnnotation, @@ -61,7 +58,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod MyBase.New( originalSpan, finalSpan, - options, selectionInExpression, document, firstTokenAnnotation, diff --git a/src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicSelectionValidator.vb b/src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicSelectionValidator.vb index 9c8c2bce8415b..2e2493d1c85f9 100644 --- a/src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicSelectionValidator.vb +++ b/src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicSelectionValidator.vb @@ -16,9 +16,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod Inherits SelectionValidator(Of VisualBasicSelectionResult, ExecutableStatementSyntax) Public Sub New(document As SemanticDocument, - textSpan As TextSpan, - options As ExtractMethodOptions) - MyBase.New(document, textSpan, options) + textSpan As TextSpan) + MyBase.New(document, textSpan) End Sub Public Overrides Async Function GetValidSelectionAsync(cancellationToken As CancellationToken) As Task(Of (VisualBasicSelectionResult, OperationStatus)) @@ -65,7 +64,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod Dim result = Await VisualBasicSelectionResult.CreateResultAsync( selectionInfo.OriginalSpan, selectionInfo.FinalSpan, - Me.Options, selectionInfo.SelectionInExpression, Me.SemanticDocument, selectionInfo.FirstTokenInFinalSpan, diff --git a/src/LanguageServer/Protocol/Features/Options/CodeActionOptionsStorage.cs b/src/LanguageServer/Protocol/Features/Options/CodeActionOptionsStorage.cs index 920cef56787a6..36c8c144b80b7 100644 --- a/src/LanguageServer/Protocol/Features/Options/CodeActionOptionsStorage.cs +++ b/src/LanguageServer/Protocol/Features/Options/CodeActionOptionsStorage.cs @@ -25,7 +25,6 @@ public static CodeActionOptions GetCodeActionOptions(this IGlobalOptionService g CodeStyleOptions = globalOptions.GetCodeStyleOptions(languageServices), SearchOptions = globalOptions.GetSymbolSearchOptions(languageServices.Language), ImplementTypeOptions = globalOptions.GetImplementTypeOptions(languageServices.Language), - ExtractMethodOptions = globalOptions.GetExtractMethodOptions(languageServices.Language), HideAdvancedMembers = globalOptions.GetOption(CompletionOptionsStorage.HideAdvancedMembers, languageServices.Language), }; diff --git a/src/LanguageServer/Protocol/Features/Options/ExtractMethodOptionsStorage.cs b/src/LanguageServer/Protocol/Features/Options/ExtractMethodOptionsStorage.cs index 2f42247133d35..b90833ba6f108 100644 --- a/src/LanguageServer/Protocol/Features/Options/ExtractMethodOptionsStorage.cs +++ b/src/LanguageServer/Protocol/Features/Options/ExtractMethodOptionsStorage.cs @@ -2,8 +2,6 @@ // 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.Threading; -using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeCleanup; using Microsoft.CodeAnalysis.CodeGeneration; using Microsoft.CodeAnalysis.Host; @@ -13,23 +11,10 @@ namespace Microsoft.CodeAnalysis.ExtractMethod; internal static class ExtractMethodOptionsStorage { - public static ExtractMethodOptions GetExtractMethodOptions(this IGlobalOptionService globalOptions, string language) - => new() - { - DoNotPutOutOrRefOnStruct = globalOptions.GetOption(DoNotPutOutOrRefOnStruct, language) - }; - public static ExtractMethodGenerationOptions GetExtractMethodGenerationOptions(this IGlobalOptionService globalOptions, LanguageServices languageServices) => new() { CodeGenerationOptions = globalOptions.GetCodeGenerationOptions(languageServices), CodeCleanupOptions = globalOptions.GetCodeCleanupOptions(languageServices), - ExtractOptions = globalOptions.GetExtractMethodOptions(languageServices.Language), }; - - public static ValueTask GetExtractMethodGenerationOptionsAsync(this Document document, IGlobalOptionService globalOptions, CancellationToken cancellationToken) - => document.GetExtractMethodGenerationOptionsAsync(globalOptions.GetExtractMethodGenerationOptions(document.Project.Services), cancellationToken); - - public static readonly PerLanguageOption2 DoNotPutOutOrRefOnStruct = new( - "dotnet_extract_method_no_ref_or_out_structs", ExtractMethodOptions.Default.DoNotPutOutOrRefOnStruct); } diff --git a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs index e1f3a16d5540a..bc1f1776e0b25 100644 --- a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs +++ b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs @@ -169,9 +169,6 @@ public AdvancedOptionPageControl(OptionStore optionStore, IComponentModel compon // Classifications BindToOption(Editor_color_scheme, ColorSchemeOptionsStorage.ColorScheme); - // Extract Method - BindToOption(DontPutOutOrRefOnStruct, ExtractMethodOptionsStorage.DoNotPutOutOrRefOnStruct, LanguageNames.CSharp); - // Implement Interface or Abstract Class BindToOption(with_other_members_of_the_same_kind, ImplementTypeOptionsStorage.InsertionBehavior, ImplementTypeInsertionBehavior.WithOtherMembersOfTheSameKind, LanguageNames.CSharp); BindToOption(at_the_end, ImplementTypeOptionsStorage.InsertionBehavior, ImplementTypeInsertionBehavior.AtTheEnd, LanguageNames.CSharp); diff --git a/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.ExtractMethod.cs b/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.ExtractMethod.cs index 79e9089b91f1b..9a549d8adc5ff 100644 --- a/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.ExtractMethod.cs +++ b/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.ExtractMethod.cs @@ -13,11 +13,5 @@ public int ExtractMethod_AllowBestEffort get { return GetBooleanOption(ExtractMethodPresentationOptionsStorage.AllowBestEffort); } set { SetBooleanOption(ExtractMethodPresentationOptionsStorage.AllowBestEffort, value); } } - - public int ExtractMethod_DoNotPutOutOrRefOnStruct - { - get { return GetBooleanOption(ExtractMethodOptionsStorage.DoNotPutOutOrRefOnStruct); } - set { SetBooleanOption(ExtractMethodOptionsStorage.DoNotPutOutOrRefOnStruct, value); } - } } } diff --git a/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs b/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs index ce33d7af247db..472f357e941a6 100644 --- a/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs +++ b/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs @@ -277,7 +277,6 @@ public bool TryFetch(LocalUserRegistryOptionPersister persister, OptionKey2 opti {"dotnet_enable_code_refactorings", new LocalUserProfileStorage(@"Roslyn\Internal\OnOff\Components", "Code Refactorings")}, {"dotnet_enable_editor_tagger", new LocalUserProfileStorage(@"Roslyn\Internal\OnOff\Components", "Tagger")}, {"dotnet_allow_best_effort_when_extracting_method", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.Allow Best Effort")}, - {"dotnet_extract_method_no_ref_or_out_structs", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.Don't Put Out Or Ref On Strcut")}, {"dotnet_fade_out_unreachable_code", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.FadeOutUnreachableCode")}, {"dotnet_fade_out_unused_imports", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.FadeOutUnusedImports")}, {"dotnet_add_imports_on_paste", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.AddImportsOnPaste2")}, diff --git a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml index 4d71c1c21df4e..f68871213d596 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml +++ b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml @@ -281,14 +281,6 @@ - - - - - - diff --git a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb index 652a983b99296..b83171035715c 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb +++ b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb @@ -162,9 +162,6 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options ' Editor color scheme BindToOption(Editor_color_scheme, ColorSchemeOptionsStorage.ColorScheme) - ' Extract method - BindToOption(DontPutOutOrRefOnStruct, ExtractMethodOptionsStorage.DoNotPutOutOrRefOnStruct, LanguageNames.VisualBasic) - ' Implement Interface or Abstract Class BindToOption(with_other_members_of_the_same_kind, ImplementTypeOptionsStorage.InsertionBehavior, ImplementTypeInsertionBehavior.WithOtherMembersOfTheSameKind, LanguageNames.VisualBasic) BindToOption(at_the_end, ImplementTypeOptionsStorage.InsertionBehavior, ImplementTypeInsertionBehavior.AtTheEnd, LanguageNames.VisualBasic) diff --git a/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.ExtractMethod.vb b/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.ExtractMethod.vb index 4f3631cc2a832..ba33a7ba11940 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.ExtractMethod.vb +++ b/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.ExtractMethod.vb @@ -14,14 +14,5 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options SetBooleanOption(ExtractMethodPresentationOptionsStorage.AllowBestEffort, value) End Set End Property - - Public Property ExtractMethod_DoNotPutOutOrRefOnStruct As Boolean - Get - Return GetBooleanOption(ExtractMethodOptionsStorage.DoNotPutOutOrRefOnStruct) - End Get - Set(value As Boolean) - SetBooleanOption(ExtractMethodOptionsStorage.DoNotPutOutOrRefOnStruct, value) - End Set - End Property End Class End Namespace diff --git a/src/Workspaces/Core/Portable/ExtractMethod/ExtractMethodOptions.cs b/src/Workspaces/Core/Portable/ExtractMethod/ExtractMethodOptions.cs index 8d8f093a6d32e..1eab0a3867d8f 100644 --- a/src/Workspaces/Core/Portable/ExtractMethod/ExtractMethodOptions.cs +++ b/src/Workspaces/Core/Portable/ExtractMethod/ExtractMethodOptions.cs @@ -14,28 +14,14 @@ namespace Microsoft.CodeAnalysis.ExtractMethod; -[DataContract] -internal readonly record struct ExtractMethodOptions -{ - [DataMember] public bool DoNotPutOutOrRefOnStruct { get; init; } = true; - - public ExtractMethodOptions() - { - } - - public static readonly ExtractMethodOptions Default = new(); -} - /// /// All options needed to perform method extraction. -/// Combines global with document specific code generation options. /// [DataContract] internal readonly record struct ExtractMethodGenerationOptions { [DataMember] public required CodeGenerationOptions CodeGenerationOptions { get; init; } [DataMember] public required CodeCleanupOptions CodeCleanupOptions { get; init; } - [DataMember] public ExtractMethodOptions ExtractOptions { get; init; } = ExtractMethodOptions.Default; public static ExtractMethodGenerationOptions GetDefault(LanguageServices languageServices) => new() @@ -54,18 +40,12 @@ public ExtractMethodGenerationOptions() internal static class ExtractMethodGenerationOptionsProviders { - public static async ValueTask GetExtractMethodGenerationOptionsAsync(this Document document, ExtractMethodGenerationOptions? fallbackOptions, CancellationToken cancellationToken) + public static async ValueTask GetExtractMethodGenerationOptionsAsync(this Document document, CancellationToken cancellationToken) { - fallbackOptions ??= ExtractMethodGenerationOptions.GetDefault(document.Project.Services); - return new ExtractMethodGenerationOptions() { CodeGenerationOptions = await document.GetCodeGenerationOptionsAsync(cancellationToken).ConfigureAwait(false), - ExtractOptions = fallbackOptions.Value.ExtractOptions, CodeCleanupOptions = await document.GetCodeCleanupOptionsAsync(cancellationToken).ConfigureAwait(false), }; } - - public static ValueTask GetExtractMethodGenerationOptionsAsync(this Document document, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken) - => document.GetExtractMethodGenerationOptionsAsync(fallbackOptions.GetExtractMethodGenerationOptions(document.Project.Services), cancellationToken); } diff --git a/src/Workspaces/CoreTest/Remote/ServiceDescriptorTests.cs b/src/Workspaces/CoreTest/Remote/ServiceDescriptorTests.cs index ff80b1dd7e4a0..108d7b4727fc4 100644 --- a/src/Workspaces/CoreTest/Remote/ServiceDescriptorTests.cs +++ b/src/Workspaces/CoreTest/Remote/ServiceDescriptorTests.cs @@ -201,7 +201,6 @@ public void OptionsAreMessagePackSerializable_LanguageAgnostic() var messagePackOptions = MessagePackSerializerOptions.Standard.WithResolver(MessagePackFormatters.DefaultResolver); var options = new object[] { - ExtractMethodOptions.Default, AddImportPlacementOptions.Default, LineFormattingOptions.Default, DocumentFormattingOptions.Default, diff --git a/src/Workspaces/CoreTestUtilities/VBOptionsFactory.cs b/src/Workspaces/CoreTestUtilities/VBOptionsFactory.cs index 1f78244e5a48d..41217b64c8ed8 100644 --- a/src/Workspaces/CoreTestUtilities/VBOptionsFactory.cs +++ b/src/Workspaces/CoreTestUtilities/VBOptionsFactory.cs @@ -14,11 +14,10 @@ namespace Microsoft.CodeAnalysis.UnitTests; /// internal static class VBOptionsFactory { - public static ExtractMethodGenerationOptions CreateExtractMethodGenerationOptions(CodeGenerationOptions codeGenerationOptions, CodeCleanupOptions codeCleanupOptions, ExtractMethodOptions extractOptions) + public static ExtractMethodGenerationOptions CreateExtractMethodGenerationOptions(CodeGenerationOptions codeGenerationOptions, CodeCleanupOptions codeCleanupOptions) => new() { CodeGenerationOptions = codeGenerationOptions, - CodeCleanupOptions = codeCleanupOptions, - ExtractOptions = extractOptions + CodeCleanupOptions = codeCleanupOptions }; } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/CodeActionOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/CodeActionOptions.cs index 7434e59e70668..3039a2f85a65a 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/CodeActionOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/CodeActionOptions.cs @@ -42,7 +42,6 @@ internal sealed record class CodeActionOptions [DataMember] public required IdeCodeStyleOptions CodeStyleOptions { get; init; } [DataMember] public SymbolSearchOptions SearchOptions { get; init; } = SymbolSearchOptions.Default; [DataMember] public ImplementTypeOptions ImplementTypeOptions { get; init; } = ImplementTypeOptions.Default; - [DataMember] public ExtractMethodOptions ExtractMethodOptions { get; init; } = ExtractMethodOptions.Default; [DataMember] public bool HideAdvancedMembers { get; init; } = false; public static CodeActionOptions GetDefault(LanguageServices languageServices) @@ -163,7 +162,6 @@ public static ExtractMethodGenerationOptions GetExtractMethodGenerationOptions(t { CodeGenerationOptions = codeActionOptions.CodeGenerationOptions, CodeCleanupOptions = codeActionOptions.CleanupOptions, - ExtractOptions = codeActionOptions.ExtractMethodOptions, }; } #endif From 21fd113dac0dfd1c9dbeb5779ddc65c5b1d6b565 Mon Sep 17 00:00:00 2001 From: Tomas Matousek Date: Tue, 9 Jul 2024 15:56:14 -0700 Subject: [PATCH 3/3] Fix --- .../Core/ExternalAccess/IntelliCode/IntentProcessor.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/EditorFeatures/Core/ExternalAccess/IntelliCode/IntentProcessor.cs b/src/EditorFeatures/Core/ExternalAccess/IntelliCode/IntentProcessor.cs index 167901893a26a..13af115a66219 100644 --- a/src/EditorFeatures/Core/ExternalAccess/IntelliCode/IntentProcessor.cs +++ b/src/EditorFeatures/Core/ExternalAccess/IntelliCode/IntentProcessor.cs @@ -23,11 +23,9 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.IntelliCode; [method: ImportingConstructor] [method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] internal class IntentSourceProvider( - [ImportMany] IEnumerable> lazyIntentProviders, - IGlobalOptionService globalOptions) : IIntentSourceProvider + [ImportMany] IEnumerable> lazyIntentProviders) : IIntentSourceProvider { private readonly ImmutableDictionary<(string LanguageName, string IntentName), Lazy> _lazyIntentProviders = CreateProviderMap(lazyIntentProviders); - private readonly IGlobalOptionService _globalOptions = globalOptions; private static ImmutableDictionary<(string LanguageName, string IntentName), Lazy> CreateProviderMap( IEnumerable> lazyIntentProviders)