diff --git a/eng/Versions.props b/eng/Versions.props index 46e3a8b7dab53..e8b53b60dd046 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -21,7 +21,7 @@ 3.3.3-beta1.21105.3 6.0.0-rc1.21366.2 - 1.1.1-beta1.22081.4 + 1.1.2-beta1.22111.2 0.1.127-beta 4.0.1 diff --git a/global.json b/global.json index ee7e263ef19f1..8b4d21042c9d0 100644 --- a/global.json +++ b/global.json @@ -12,7 +12,7 @@ "xcopy-msbuild": "16.10.0-preview2" }, "msbuild-sdks": { - "Microsoft.DotNet.Arcade.Sdk": "7.0.0-beta.22117.2", - "Microsoft.DotNet.Helix.Sdk": "7.0.0-beta.22117.2" + "Microsoft.DotNet.Arcade.Sdk": "7.0.0-beta.22080.1", + "Microsoft.DotNet.Helix.Sdk": "7.0.0-beta.22080.1" } } diff --git a/src/Analyzers/Core/Analyzers/Helpers/AnalyzerHelper.cs b/src/Analyzers/Core/Analyzers/Helpers/AnalyzerHelper.cs index 4f24050eddc47..b2232b2c2aace 100644 --- a/src/Analyzers/Core/Analyzers/Helpers/AnalyzerHelper.cs +++ b/src/Analyzers/Core/Analyzers/Helpers/AnalyzerHelper.cs @@ -14,11 +14,18 @@ namespace Microsoft.CodeAnalysis.Diagnostics { internal readonly record struct IdeAnalyzerOptions( - bool FadeOutUnusedImports, - bool FadeOutUnreachableCode, - bool ReportInvalidPlaceholdersInStringDotFormatCalls, - bool ReportInvalidRegexPatterns) + bool FadeOutUnusedImports = true, + bool FadeOutUnreachableCode = true, + bool ReportInvalidPlaceholdersInStringDotFormatCalls = true, + bool ReportInvalidRegexPatterns = true) { + public IdeAnalyzerOptions() + : this(FadeOutUnusedImports: true) + { + } + + public static readonly IdeAnalyzerOptions Default = new(); + public static readonly IdeAnalyzerOptions CodeStyleDefault = new( FadeOutUnusedImports: false, FadeOutUnreachableCode: false, @@ -27,11 +34,14 @@ internal readonly record struct IdeAnalyzerOptions( #if !CODE_STYLE public static IdeAnalyzerOptions FromProject(Project project) + => From(project.Solution.Options, project.Language); + + public static IdeAnalyzerOptions From(OptionSet options, string language) => new( - FadeOutUnusedImports: project.Solution.Options.GetOption(Microsoft.CodeAnalysis.Fading.FadingOptions.Metadata.FadeOutUnusedImports, project.Language), - FadeOutUnreachableCode: project.Solution.Options.GetOption(Microsoft.CodeAnalysis.Fading.FadingOptions.Metadata.FadeOutUnreachableCode, project.Language), - ReportInvalidPlaceholdersInStringDotFormatCalls: project.Solution.Options.GetOption(Microsoft.CodeAnalysis.ValidateFormatString.ValidateFormatStringOption.ReportInvalidPlaceholdersInStringDotFormatCalls, project.Language), - ReportInvalidRegexPatterns: project.Solution.Options.GetOption(Microsoft.CodeAnalysis.Features.EmbeddedLanguages.RegularExpressions.LanguageServices.RegularExpressionsOptions.ReportInvalidRegexPatterns, project.Language)); + FadeOutUnusedImports: options.GetOption(Microsoft.CodeAnalysis.Fading.FadingOptions.Metadata.FadeOutUnusedImports, language), + FadeOutUnreachableCode: options.GetOption(Microsoft.CodeAnalysis.Fading.FadingOptions.Metadata.FadeOutUnreachableCode, language), + ReportInvalidPlaceholdersInStringDotFormatCalls: options.GetOption(Microsoft.CodeAnalysis.ValidateFormatString.ValidateFormatStringOption.ReportInvalidPlaceholdersInStringDotFormatCalls, language), + ReportInvalidRegexPatterns: options.GetOption(Microsoft.CodeAnalysis.Features.EmbeddedLanguages.RegularExpressions.LanguageServices.RegularExpressionsOptions.ReportInvalidRegexPatterns, language)); #endif } diff --git a/src/Analyzers/Core/Analyzers/ValidateFormatString/ValidateFormatStringOption.cs b/src/Analyzers/Core/Analyzers/ValidateFormatString/ValidateFormatStringOption.cs index cf5153efb20b5..57fc450317da5 100644 --- a/src/Analyzers/Core/Analyzers/ValidateFormatString/ValidateFormatStringOption.cs +++ b/src/Analyzers/Core/Analyzers/ValidateFormatString/ValidateFormatStringOption.cs @@ -2,6 +2,7 @@ // 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.Diagnostics; using Microsoft.CodeAnalysis.Options; namespace Microsoft.CodeAnalysis.ValidateFormatString @@ -12,7 +13,7 @@ internal class ValidateFormatStringOption new( nameof(ValidateFormatStringOption), nameof(ReportInvalidPlaceholdersInStringDotFormatCalls), - defaultValue: true, + IdeAnalyzerOptions.Default.ReportInvalidPlaceholdersInStringDotFormatCalls, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.WarnOnInvalidStringDotFormatCalls")); } } diff --git a/src/EditorFeatures/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs b/src/EditorFeatures/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs index 2022170660e07..fb42a91d4b811 100644 --- a/src/EditorFeatures/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs +++ b/src/EditorFeatures/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs @@ -5,6 +5,7 @@ #nullable disable using System.Threading.Tasks; +using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CodeStyle; using Microsoft.CodeAnalysis.CSharp; @@ -1468,6 +1469,11 @@ class T : A [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementAbstractClass)] public async Task TestWithGroupingOff1() { + var options = CodeActionOptions.Default with + { + ImplementTypeOptions = new ImplementTypeOptions(InsertionBehavior: ImplementTypeInsertionBehavior.AtTheEnd) + }; + await TestInRegularAndScriptAsync( @"abstract class Base { @@ -1488,7 +1494,7 @@ class Derived : Base void Goo() { } public override int Prop => throw new System.NotImplementedException(); -}", options: Option(ImplementTypeOptions.Metadata.InsertionBehavior, ImplementTypeInsertionBehavior.AtTheEnd)); +}", codeActionOptions: options); } [WorkItem(17274, "https://github.com/dotnet/roslyn/issues/17274")] @@ -1641,6 +1647,11 @@ public override void M2(T? i = null) [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementAbstractClass)] public async Task TestAutoProperties() { + var options = CodeActionOptions.Default with + { + ImplementTypeOptions = new ImplementTypeOptions(InsertionBehavior: ImplementTypeInsertionBehavior.AtTheEnd) + }; + await TestInRegularAndScript1Async( @"abstract class AbstractClass { @@ -1664,9 +1675,7 @@ class C : AbstractClass public override int ReadOnlyProp { get; } public override int ReadWriteProp { get; set; } public override int WriteOnlyProp { set => throw new System.NotImplementedException(); } -}", parameters: new TestParameters(options: Option( - ImplementTypeOptions.Metadata.PropertyGenerationBehavior, - ImplementTypePropertyGenerationBehavior.PreferAutoProperties))); +}", parameters: new TestParameters(codeActionOptions: options)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementAbstractClass)] diff --git a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs index f072bdc5b8417..22a23d37c51f6 100644 --- a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs +++ b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Threading.Tasks; +using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.CodeStyle; using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions; @@ -7286,11 +7287,11 @@ void M() { } public int Prop => throw new System.NotImplementedException(); }", - Options = + CodeActionOptions = CodeActionOptions.Default with { - { ImplementTypeOptions.Metadata.InsertionBehavior, ImplementTypeInsertionBehavior.AtTheEnd }, - }, - }.RunAsync(); + ImplementTypeOptions = new ImplementTypeOptions(InsertionBehavior: ImplementTypeInsertionBehavior.AtTheEnd) + } + }.RunAsync(); } [WorkItem(15387, "https://github.com/dotnet/roslyn/issues/15387")] @@ -7461,10 +7462,10 @@ class Class : IInterface public int ReadWriteProp { get; set; } public int WriteOnlyProp { set => throw new System.NotImplementedException(); } }", - Options = + CodeActionOptions = CodeActionOptions.Default with { - { ImplementTypeOptions.Metadata.PropertyGenerationBehavior, ImplementTypePropertyGenerationBehavior.PreferAutoProperties }, - }, + ImplementTypeOptions = new ImplementTypeOptions(InsertionBehavior: ImplementTypeInsertionBehavior.AtTheEnd) + } }.RunAsync(); } diff --git a/src/EditorFeatures/Core/ImplementType/ImplementTypeOptionsStorage.cs b/src/EditorFeatures/Core/ImplementType/ImplementTypeOptionsStorage.cs new file mode 100644 index 0000000000000..139acd773f8a2 --- /dev/null +++ b/src/EditorFeatures/Core/ImplementType/ImplementTypeOptionsStorage.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// 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.Options; + +namespace Microsoft.CodeAnalysis.ImplementType +{ + internal static class ImplementTypeOptionsStorage + { + public static ImplementTypeOptions GetImplementTypeOptions(this IGlobalOptionService globalOptions, string language) + => new( + InsertionBehavior: globalOptions.GetOption(InsertionBehavior, language), + PropertyGenerationBehavior: globalOptions.GetOption(PropertyGenerationBehavior, language)); + + private const string FeatureName = "ImplementTypeOptions"; + + public static readonly PerLanguageOption2 InsertionBehavior = + new(FeatureName, + "InsertionBehavior", + defaultValue: ImplementTypeOptions.Default.InsertionBehavior, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.ImplementTypeOptions.InsertionBehavior")); + + public static readonly PerLanguageOption2 PropertyGenerationBehavior = + new(FeatureName, + "PropertyGenerationBehavior", + defaultValue: ImplementTypeOptions.Default.PropertyGenerationBehavior, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.ImplementTypeOptions.PropertyGenerationBehavior")); + } +} diff --git a/src/EditorFeatures/Core/Implementation/CodeActions/CodeActionOptionsStorage.cs b/src/EditorFeatures/Core/Implementation/CodeActions/CodeActionOptionsStorage.cs index c4a5784c02f94..602b692419fdd 100644 --- a/src/EditorFeatures/Core/Implementation/CodeActions/CodeActionOptionsStorage.cs +++ b/src/EditorFeatures/Core/Implementation/CodeActions/CodeActionOptionsStorage.cs @@ -4,6 +4,7 @@ using System.Collections.Immutable; using Microsoft.CodeAnalysis.Completion; +using Microsoft.CodeAnalysis.ImplementType; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.SymbolSearch; @@ -20,6 +21,7 @@ internal static CodeActionOptions GetBlockingCodeActionOptions(this IGlobalOptio private static CodeActionOptions GetCodeActionOptions(this IGlobalOptionService globalOptions, string language, bool isBlocking) => new( SearchOptions: globalOptions.GetSymbolSearchOptions(language), + ImplementTypeOptions: globalOptions.GetImplementTypeOptions(language), HideAdvancedMembers: globalOptions.GetOption(CompletionOptionsStorage.HideAdvancedMembers, language), IsBlocking: isBlocking); diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionOrUserDiagnosticTest.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionOrUserDiagnosticTest.cs index aa218035e8803..7997a06582b08 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionOrUserDiagnosticTest.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionOrUserDiagnosticTest.cs @@ -376,6 +376,7 @@ internal Task TestInRegularAndScriptAsync( CodeActionPriority? priority = null, CompilationOptions compilationOptions = null, OptionsCollection options = null, + CodeActionOptions? codeActionOptions = null, object fixProviderData = null, ParseOptions parseOptions = null, string title = null, @@ -383,7 +384,7 @@ internal Task TestInRegularAndScriptAsync( { return TestInRegularAndScript1Async( initialMarkup, expectedMarkup, index, - new TestParameters(parseOptions, compilationOptions, options, CodeActionOptions.Default, fixProviderData, index, priority, title: title, testHost: testHost)); + new TestParameters(parseOptions, compilationOptions, options, codeActionOptions ?? CodeActionOptions.Default, fixProviderData, index, priority, title: title, testHost: testHost)); } internal Task TestInRegularAndScript1Async( diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs index b978f9a995a8a..5648605a31668 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs @@ -73,6 +73,13 @@ public Test() /// internal OptionsCollection Options => _sharedState.Options; +#if !CODE_STYLE + internal CodeActionOptions CodeActionOptions + { + get => _sharedState.CodeActionOptions; + set => _sharedState.CodeActionOptions = value; + } +#endif /// public string? EditorConfig { @@ -98,6 +105,9 @@ protected override async Task RunImplAsync(CancellationToken cancellationToken = #if !CODE_STYLE protected override AnalyzerOptions GetAnalyzerOptions(Project project) => new WorkspaceAnalyzerOptions(base.GetAnalyzerOptions(project), project); + + protected override CodeFixContext CreateCodeFixContext(Document document, TextSpan span, ImmutableArray diagnostics, Action> registerCodeFix, CancellationToken cancellationToken) + => new(document, span, diagnostics, registerCodeFix, _sharedState.CodeActionOptions, cancellationToken); #endif protected override Diagnostic? TrySelectDiagnosticToFix(ImmutableArray fixableDiagnostics) diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/SharedVerifierState.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/SharedVerifierState.cs index c8679afa8e11c..b5229719dac52 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/SharedVerifierState.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/SharedVerifierState.cs @@ -7,6 +7,7 @@ using Microsoft.CodeAnalysis.Testing.Verifiers; #if !CODE_STYLE +using Microsoft.CodeAnalysis.CodeActions; using Roslyn.Utilities; #endif @@ -45,6 +46,9 @@ public SharedVerifierState(AnalyzerTest test, string defaultFileE /// internal OptionsCollection Options { get; } +#if !CODE_STYLE + internal CodeActionOptions CodeActionOptions { get; set; } +#endif internal void Apply() { var (analyzerConfigSource, remainingOptions) = CodeFixVerifierHelper.ConvertOptionsToAnalyzerConfig(_defaultFileExt, EditorConfig, Options); diff --git a/src/EditorFeatures/VisualBasic/Utilities/CommandHandlers/AbstractImplementAbstractClassOrInterfaceCommandHandler.vb b/src/EditorFeatures/VisualBasic/Utilities/CommandHandlers/AbstractImplementAbstractClassOrInterfaceCommandHandler.vb index 3c7167f549ea6..1a179ce52af3a 100644 --- a/src/EditorFeatures/VisualBasic/Utilities/CommandHandlers/AbstractImplementAbstractClassOrInterfaceCommandHandler.vb +++ b/src/EditorFeatures/VisualBasic/Utilities/CommandHandlers/AbstractImplementAbstractClassOrInterfaceCommandHandler.vb @@ -163,7 +163,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Utilities.CommandHandlers Return False End If - Dim options = ImplementTypeOptions.From(document.Project) + Dim options = _globalOptions.GetImplementTypeOptions(document.Project.Language) Dim newDocument = TryGetNewDocument(document, options, identifier, cancellationToken) If newDocument Is Nothing Then diff --git a/src/EditorFeatures/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassTests.vb b/src/EditorFeatures/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassTests.vb index 74bd618c3f1b0..0d19bbdab8213 100644 --- a/src/EditorFeatures/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassTests.vb +++ b/src/EditorFeatures/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassTests.vb @@ -2,10 +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. +Imports Microsoft.CodeAnalysis.CodeActions Imports Microsoft.CodeAnalysis.CodeFixes Imports Microsoft.CodeAnalysis.Diagnostics Imports Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Diagnostics Imports Microsoft.CodeAnalysis.ImplementType +Imports Microsoft.CodeAnalysis.SymbolSearch Imports Microsoft.CodeAnalysis.VisualBasic.ImplementAbstractClass Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ImplementAbstractClass @@ -630,9 +632,9 @@ Class C Throw New System.NotImplementedException() End Set End Property -End Class", parameters:=New TestParameters(options:=[Option]( - ImplementTypeOptions.Metadata.PropertyGenerationBehavior, - ImplementTypePropertyGenerationBehavior.PreferAutoProperties))) +End Class", parameters:=New TestParameters(codeActionOptions:=New CodeActionOptions( + SearchOptions:=SymbolSearchOptions.Default, + ImplementTypeOptions:=New ImplementTypeOptions(PropertyGenerationBehavior:=ImplementTypePropertyGenerationBehavior.PreferAutoProperties)))) End Function End Class End Namespace diff --git a/src/EditorFeatures/VisualBasicTest/ImplementInterface/ImplementInterfaceTests.vb b/src/EditorFeatures/VisualBasicTest/ImplementInterface/ImplementInterfaceTests.vb index f915762663037..31bd6cd863b48 100644 --- a/src/EditorFeatures/VisualBasicTest/ImplementInterface/ImplementInterfaceTests.vb +++ b/src/EditorFeatures/VisualBasicTest/ImplementInterface/ImplementInterfaceTests.vb @@ -2,10 +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. +Imports Microsoft.CodeAnalysis.CodeActions Imports Microsoft.CodeAnalysis.CodeFixes Imports Microsoft.CodeAnalysis.Diagnostics Imports Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Diagnostics Imports Microsoft.CodeAnalysis.ImplementType +Imports Microsoft.CodeAnalysis.SymbolSearch Imports Microsoft.CodeAnalysis.VisualBasic.ImplementInterface Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ImplementInterface @@ -4646,9 +4648,9 @@ class Class Throw New System.NotImplementedException() End Set End Property -end class", parameters:=New TestParameters(options:=[Option]( - ImplementTypeOptions.Metadata.PropertyGenerationBehavior, - ImplementTypePropertyGenerationBehavior.PreferAutoProperties))) +end class", parameters:=New TestParameters(codeActionOptions:=New CodeActionOptions( + SearchOptions:=SymbolSearchOptions.Default, + ImplementTypeOptions:=New ImplementTypeOptions(PropertyGenerationBehavior:=ImplementTypePropertyGenerationBehavior.PreferAutoProperties)))) End Function End Class End Namespace diff --git a/src/Features/CSharp/Portable/ImplementInterface/CSharpImplementInterfaceCodeFixProvider.cs b/src/Features/CSharp/Portable/ImplementInterface/CSharpImplementInterfaceCodeFixProvider.cs index ffaa2974eb11c..34e68a1f1bd02 100644 --- a/src/Features/CSharp/Portable/ImplementInterface/CSharpImplementInterfaceCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/ImplementInterface/CSharpImplementInterfaceCodeFixProvider.cs @@ -51,11 +51,10 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) var service = document.GetRequiredLanguageService(); var model = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); - var options = ImplementTypeOptions.From(document.Project); var actions = token.Parent.GetAncestorsOrThis() .Where(_interfaceName) - .Select(n => service.GetCodeActions(document, options, model, n, cancellationToken)) + .Select(n => service.GetCodeActions(document, context.Options.ImplementTypeOptions, model, n, cancellationToken)) .FirstOrDefault(a => !a.IsEmpty); if (actions.IsDefaultOrEmpty) diff --git a/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/LanguageServices/RegularExpressionsOptions.cs b/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/LanguageServices/RegularExpressionsOptions.cs index b95e2f02834d9..6285a663b2816 100644 --- a/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/LanguageServices/RegularExpressionsOptions.cs +++ b/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/LanguageServices/RegularExpressionsOptions.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Immutable; using System.Composition; +using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Options.Providers; @@ -17,7 +18,7 @@ internal class RegularExpressionsOptions new( nameof(RegularExpressionsOptions), nameof(ReportInvalidRegexPatterns), - defaultValue: true, + IdeAnalyzerOptions.Default.ReportInvalidRegexPatterns, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ReportInvalidRegexPatterns")); public static PerLanguageOption2 HighlightRelatedRegexComponentsUnderCursor = diff --git a/src/Features/Core/Portable/Fading/FadingOptions.cs b/src/Features/Core/Portable/Fading/FadingOptions.cs index 152f0217ad468..9349c606b1bd4 100644 --- a/src/Features/Core/Portable/Fading/FadingOptions.cs +++ b/src/Features/Core/Portable/Fading/FadingOptions.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Immutable; using System.Composition; +using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Options.Providers; @@ -29,11 +30,11 @@ public Metadata() private const string FeatureName = "FadingOptions"; public static readonly PerLanguageOption2 FadeOutUnusedImports = new( - FeatureName, "FadeOutUnusedImports", defaultValue: true, + FeatureName, "FadeOutUnusedImports", IdeAnalyzerOptions.Default.FadeOutUnusedImports, storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.FadeOutUnusedImports")); public static readonly PerLanguageOption2 FadeOutUnreachableCode = new( - FeatureName, "FadeOutUnreachableCode", defaultValue: true, + FeatureName, "FadeOutUnreachableCode", IdeAnalyzerOptions.Default.FadeOutUnreachableCode, storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.FadeOutUnreachableCode")); } } diff --git a/src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs b/src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs index 6295abf449ee6..7ced21bcb6e74 100644 --- a/src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs +++ b/src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs @@ -41,9 +41,8 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) if (classNode == null) return; - var options = ImplementTypeOptions.From(document.Project); var data = await ImplementAbstractClassData.TryGetDataAsync( - document, classNode, GetClassIdentifier(classNode), options, cancellationToken).ConfigureAwait(false); + document, classNode, GetClassIdentifier(classNode), context.Options.ImplementTypeOptions, cancellationToken).ConfigureAwait(false); if (data == null) return; diff --git a/src/Features/Core/Portable/ImplementType/ImplementTypeOptions.cs b/src/Features/Core/Portable/ImplementType/ImplementTypeOptions.cs deleted file mode 100644 index 2a543b075ce87..0000000000000 --- a/src/Features/Core/Portable/ImplementType/ImplementTypeOptions.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Composition; -using System.Collections.Immutable; -using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Options.Providers; - -namespace Microsoft.CodeAnalysis.ImplementType -{ - internal readonly record struct ImplementTypeOptions( - ImplementTypeInsertionBehavior InsertionBehavior, - ImplementTypePropertyGenerationBehavior PropertyGenerationBehavior) - { - public static ImplementTypeOptions From(Project project) - => From(project.Solution.Options, project.Language); - - public static ImplementTypeOptions From(OptionSet options, string language) - => new( - InsertionBehavior: options.GetOption(Metadata.InsertionBehavior, language), - PropertyGenerationBehavior: options.GetOption(Metadata.PropertyGenerationBehavior, language)); - - [ExportSolutionOptionProvider, Shared] - internal sealed class Metadata : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public Metadata() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - InsertionBehavior, - PropertyGenerationBehavior); - - private const string FeatureName = "ImplementTypeOptions"; - - public static readonly PerLanguageOption2 InsertionBehavior = - new(FeatureName, - "InsertionBehavior", - defaultValue: ImplementTypeInsertionBehavior.WithOtherMembersOfTheSameKind, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.ImplementTypeOptions.InsertionBehavior")); - - public static readonly PerLanguageOption2 PropertyGenerationBehavior = - new(FeatureName, - "PropertyGenerationBehavior", - defaultValue: ImplementTypePropertyGenerationBehavior.PreferThrowingProperties, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.ImplementTypeOptions.PropertyGenerationBehavior")); - } - } -} diff --git a/src/Features/VisualBasic/Portable/ImplementInterface/VisualBasicImplementInterfaceCodeFixProvider.vb b/src/Features/VisualBasic/Portable/ImplementInterface/VisualBasicImplementInterfaceCodeFixProvider.vb index 4d4081405d9db..07412631d3d9c 100644 --- a/src/Features/VisualBasic/Portable/ImplementInterface/VisualBasicImplementInterfaceCodeFixProvider.vb +++ b/src/Features/VisualBasic/Portable/ImplementInterface/VisualBasicImplementInterfaceCodeFixProvider.vb @@ -58,11 +58,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ImplementInterface Return End If - Dim options = ImplementTypeOptions.From(document.Project) Dim service = document.GetLanguageService(Of IImplementInterfaceService)() Dim actions = service.GetCodeActions( document, - options, + context.Options.ImplementTypeOptions, Await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(False), typeNode, cancellationToken) diff --git a/src/Tools/ExternalAccess/OmniSharp/Analyzers/OmniSharpIdeAnalyzerOptions.cs b/src/Tools/ExternalAccess/OmniSharp/Analyzers/OmniSharpIdeAnalyzerOptions.cs deleted file mode 100644 index 98e5d2ff6b314..0000000000000 --- a/src/Tools/ExternalAccess/OmniSharp/Analyzers/OmniSharpIdeAnalyzerOptions.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// 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.ExternalAccess.OmniSharp.ImplementType; - -namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.Analyzers -{ - internal readonly record struct OmniSharpIdeAnalyzerOptions( - OmniSharpImplementTypeOptions ImplementTypeOptions); -} diff --git a/src/Tools/ExternalAccess/OmniSharp/Analyzers/OmniSharpWorkspaceAnalyzerOptionsFactory.cs b/src/Tools/ExternalAccess/OmniSharp/Analyzers/OmniSharpWorkspaceAnalyzerOptionsFactory.cs index 71de93ca95df7..bf6932ceaea87 100644 --- a/src/Tools/ExternalAccess/OmniSharp/Analyzers/OmniSharpWorkspaceAnalyzerOptionsFactory.cs +++ b/src/Tools/ExternalAccess/OmniSharp/Analyzers/OmniSharpWorkspaceAnalyzerOptionsFactory.cs @@ -8,7 +8,7 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.Analyzers { internal static class OmniSharpWorkspaceAnalyzerOptionsFactory { - public static AnalyzerOptions Create(Solution solution, AnalyzerOptions options, OmniSharpIdeAnalyzerOptions ideOptions) - => new WorkspaceAnalyzerOptions(options, solution, ideOptions); + public static AnalyzerOptions Create(Solution solution, AnalyzerOptions options) + => new WorkspaceAnalyzerOptions(options, solution, IdeAnalyzerOptions.Default); } } diff --git a/src/Tools/ExternalAccess/OmniSharp/CodeActions/OmniSharpCodeFixContextFactory.cs b/src/Tools/ExternalAccess/OmniSharp/CodeActions/OmniSharpCodeFixContextFactory.cs new file mode 100644 index 0000000000000..b4f31dd36f8ba --- /dev/null +++ b/src/Tools/ExternalAccess/OmniSharp/CodeActions/OmniSharpCodeFixContextFactory.cs @@ -0,0 +1,35 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Immutable; +using System.Threading; +using Microsoft.CodeAnalysis.CodeActions; +using Microsoft.CodeAnalysis.CodeFixes; +using Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.ImplementType; +using Microsoft.CodeAnalysis.ImplementType; +using Microsoft.CodeAnalysis.SymbolSearch; +using Microsoft.CodeAnalysis.Text; + +namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.CodeActions +{ + internal static class OmniSharpCodeFixContextFactory + { + public static CodeFixContext Create( + Document document, + TextSpan span, + ImmutableArray diagnostics, + Action> registerCodeFix, + OmniSharpImplementTypeOptions implementTypeOptions, + CancellationToken cancellationToken) + => new(document, span, diagnostics, registerCodeFix, GetCodeActionOptions(implementTypeOptions), cancellationToken); + + private static CodeActionOptions GetCodeActionOptions(OmniSharpImplementTypeOptions implementTypeOptions) + => new( + SymbolSearchOptions.Default, + new ImplementTypeOptions( + InsertionBehavior: (ImplementTypeInsertionBehavior)implementTypeOptions.InsertionBehavior, + PropertyGenerationBehavior: (ImplementTypePropertyGenerationBehavior)implementTypeOptions.PropertyGenerationBehavior)); + } +} diff --git a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs index fbc2016f006c2..d21c61cedf71f 100644 --- a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs +++ b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs @@ -117,11 +117,11 @@ public AdvancedOptionPageControl(OptionStore optionStore, IComponentModel compon BindToOption(DontPutOutOrRefOnStruct, ExtractMethodOptions.Metadata.DontPutOutOrRefOnStruct, LanguageNames.CSharp); - BindToOption(with_other_members_of_the_same_kind, ImplementTypeOptions.Metadata.InsertionBehavior, ImplementTypeInsertionBehavior.WithOtherMembersOfTheSameKind, LanguageNames.CSharp); - BindToOption(at_the_end, ImplementTypeOptions.Metadata.InsertionBehavior, ImplementTypeInsertionBehavior.AtTheEnd, LanguageNames.CSharp); + BindToOption(with_other_members_of_the_same_kind, ImplementTypeOptionsStorage.InsertionBehavior, ImplementTypeInsertionBehavior.WithOtherMembersOfTheSameKind, LanguageNames.CSharp); + BindToOption(at_the_end, ImplementTypeOptionsStorage.InsertionBehavior, ImplementTypeInsertionBehavior.AtTheEnd, LanguageNames.CSharp); - BindToOption(prefer_throwing_properties, ImplementTypeOptions.Metadata.PropertyGenerationBehavior, ImplementTypePropertyGenerationBehavior.PreferThrowingProperties, LanguageNames.CSharp); - BindToOption(prefer_auto_properties, ImplementTypeOptions.Metadata.PropertyGenerationBehavior, ImplementTypePropertyGenerationBehavior.PreferAutoProperties, LanguageNames.CSharp); + BindToOption(prefer_throwing_properties, ImplementTypeOptionsStorage.PropertyGenerationBehavior, ImplementTypePropertyGenerationBehavior.PreferThrowingProperties, LanguageNames.CSharp); + BindToOption(prefer_auto_properties, ImplementTypeOptionsStorage.PropertyGenerationBehavior, ImplementTypePropertyGenerationBehavior.PreferAutoProperties, LanguageNames.CSharp); BindToOption(Report_invalid_placeholders_in_string_dot_format_calls, ValidateFormatStringOption.ReportInvalidPlaceholdersInStringDotFormatCalls, LanguageNames.CSharp); diff --git a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb index 59c1f2df469c8..3286c99c8c72c 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb +++ b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb @@ -137,11 +137,11 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options BindToOption(DontPutOutOrRefOnStruct, ExtractMethodOptions.Metadata.DontPutOutOrRefOnStruct, LanguageNames.VisualBasic) ' Implement Interface or Abstract Class - BindToOption(with_other_members_of_the_same_kind, ImplementTypeOptions.Metadata.InsertionBehavior, ImplementTypeInsertionBehavior.WithOtherMembersOfTheSameKind, LanguageNames.VisualBasic) - BindToOption(at_the_end, ImplementTypeOptions.Metadata.InsertionBehavior, ImplementTypeInsertionBehavior.AtTheEnd, LanguageNames.VisualBasic) + BindToOption(with_other_members_of_the_same_kind, ImplementTypeOptionsStorage.InsertionBehavior, ImplementTypeInsertionBehavior.WithOtherMembersOfTheSameKind, LanguageNames.VisualBasic) + BindToOption(at_the_end, ImplementTypeOptionsStorage.InsertionBehavior, ImplementTypeInsertionBehavior.AtTheEnd, LanguageNames.VisualBasic) - BindToOption(prefer_throwing_properties, ImplementTypeOptions.Metadata.PropertyGenerationBehavior, ImplementTypePropertyGenerationBehavior.PreferThrowingProperties, LanguageNames.VisualBasic) - BindToOption(prefer_auto_properties, ImplementTypeOptions.Metadata.PropertyGenerationBehavior, ImplementTypePropertyGenerationBehavior.PreferAutoProperties, LanguageNames.VisualBasic) + BindToOption(prefer_throwing_properties, ImplementTypeOptionsStorage.PropertyGenerationBehavior, ImplementTypePropertyGenerationBehavior.PreferThrowingProperties, LanguageNames.VisualBasic) + BindToOption(prefer_auto_properties, ImplementTypeOptionsStorage.PropertyGenerationBehavior, ImplementTypePropertyGenerationBehavior.PreferAutoProperties, LanguageNames.VisualBasic) ' Inline hints BindToOption(DisplayAllHintsWhilePressingAltF1, InlineHintsViewOptions.DisplayAllHintsWhilePressingAltF1) diff --git a/src/Features/Core/Portable/ImplementType/ImplementTypeInsertionBehavior.cs b/src/Workspaces/Core/Portable/ImplementType/ImplementTypeInsertionBehavior.cs similarity index 100% rename from src/Features/Core/Portable/ImplementType/ImplementTypeInsertionBehavior.cs rename to src/Workspaces/Core/Portable/ImplementType/ImplementTypeInsertionBehavior.cs diff --git a/src/Workspaces/Core/Portable/ImplementType/ImplementTypeOptions.cs b/src/Workspaces/Core/Portable/ImplementType/ImplementTypeOptions.cs new file mode 100644 index 0000000000000..307a8ffc66f5b --- /dev/null +++ b/src/Workspaces/Core/Portable/ImplementType/ImplementTypeOptions.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// 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.Runtime.Serialization; + +namespace Microsoft.CodeAnalysis.ImplementType +{ + [DataContract] + internal readonly record struct ImplementTypeOptions( + [property: DataMember(Order = 0)] ImplementTypeInsertionBehavior InsertionBehavior = ImplementTypeInsertionBehavior.WithOtherMembersOfTheSameKind, + [property: DataMember(Order = 1)] ImplementTypePropertyGenerationBehavior PropertyGenerationBehavior = ImplementTypePropertyGenerationBehavior.PreferThrowingProperties) + { + public ImplementTypeOptions() + : this(InsertionBehavior: ImplementTypeInsertionBehavior.WithOtherMembersOfTheSameKind) + { + } + + public static readonly ImplementTypeOptions Default = new(); + } +} diff --git a/src/Features/Core/Portable/ImplementType/ImplementTypePropertyGenerationBehavior.cs b/src/Workspaces/Core/Portable/ImplementType/ImplementTypePropertyGenerationBehavior.cs similarity index 100% rename from src/Features/Core/Portable/ImplementType/ImplementTypePropertyGenerationBehavior.cs rename to src/Workspaces/Core/Portable/ImplementType/ImplementTypePropertyGenerationBehavior.cs diff --git a/src/Workspaces/Core/Portable/Microsoft.CodeAnalysis.Workspaces.csproj b/src/Workspaces/Core/Portable/Microsoft.CodeAnalysis.Workspaces.csproj index 69768a3e7c101..161653267be59 100644 --- a/src/Workspaces/Core/Portable/Microsoft.CodeAnalysis.Workspaces.csproj +++ b/src/Workspaces/Core/Portable/Microsoft.CodeAnalysis.Workspaces.csproj @@ -44,6 +44,7 @@ + @@ -80,7 +81,7 @@ - +