From b26088a91a4d102bc4daa31fde290fe661ca2b03 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 11:29:07 -0700 Subject: [PATCH 01/26] in progress --- .../AbstractGenerateConstructorService.State.cs | 8 +------- .../AbstractGenerateEnumMemberService.CodeAction.cs | 4 ---- ...ctGenerateParameterizedMemberService.SignatureInfo.cs | 4 ---- .../AbstractGenerateParameterizedMemberService.State.cs | 4 ---- .../AbstractGenerateParameterizedMemberService.cs | 4 ---- .../Compiler/Core/AddImport/AddImportPlacementOptions.cs | 9 --------- .../Compiler/Core/CodeCleanup/CodeCleanupOptions.cs | 4 ---- .../Core/CodeGeneration/CodeGenerationOptions.cs | 5 +++-- 8 files changed, 4 insertions(+), 38 deletions(-) diff --git a/src/Analyzers/Core/CodeFixes/GenerateConstructor/AbstractGenerateConstructorService.State.cs b/src/Analyzers/Core/CodeFixes/GenerateConstructor/AbstractGenerateConstructorService.State.cs index b592f43102233..2464b17f06d9e 100644 --- a/src/Analyzers/Core/CodeFixes/GenerateConstructor/AbstractGenerateConstructorService.State.cs +++ b/src/Analyzers/Core/CodeFixes/GenerateConstructor/AbstractGenerateConstructorService.State.cs @@ -238,13 +238,7 @@ private bool TryInitializeDelegatedConstructor(CancellationToken cancellationTok } private TLanguageService GetRequiredLanguageService(string language) where TLanguageService : ILanguageService - { -#if CODE_STYLE - return _document.Project.Solution.Workspace.Services.GetExtendedLanguageServices(language).GetRequiredService(); -#else - return _document.Project.Solution.Services.GetRequiredLanguageService(language); -#endif - } + => _document.Project.Solution.Workspace.Services.GetExtendedLanguageServices(language).GetRequiredService(); private bool ClashesWithExistingConstructor() { diff --git a/src/Analyzers/Core/CodeFixes/GenerateEnumMember/AbstractGenerateEnumMemberService.CodeAction.cs b/src/Analyzers/Core/CodeFixes/GenerateEnumMember/AbstractGenerateEnumMemberService.CodeAction.cs index a406679dcb829..06f1f851076b8 100644 --- a/src/Analyzers/Core/CodeFixes/GenerateEnumMember/AbstractGenerateEnumMemberService.CodeAction.cs +++ b/src/Analyzers/Core/CodeFixes/GenerateEnumMember/AbstractGenerateEnumMemberService.CodeAction.cs @@ -23,11 +23,7 @@ private partial class GenerateEnumMemberCodeAction(Document document, State stat protected override async Task GetChangedDocumentAsync(CancellationToken cancellationToken) { -#if CODE_STYLE var languageServices = _document.Project.Solution.Workspace.Services.GetExtendedLanguageServices(_state.TypeToGenerateIn.Language); -#else - var languageServices = _document.Project.Solution.Services.GetLanguageServices(_state.TypeToGenerateIn.Language); -#endif var codeGenerator = languageServices.GetService(); var semanticFacts = languageServices.GetService(); diff --git a/src/Analyzers/Core/CodeFixes/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.SignatureInfo.cs b/src/Analyzers/Core/CodeFixes/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.SignatureInfo.cs index a985fefa216b0..73576ea358ae1 100644 --- a/src/Analyzers/Core/CodeFixes/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.SignatureInfo.cs +++ b/src/Analyzers/Core/CodeFixes/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.SignatureInfo.cs @@ -125,11 +125,7 @@ public async ValueTask GenerateMethodAsync( methodKind: State.MethodKind); // Ensure no conflicts between type parameter names and parameter names. -#if CODE_STYLE var languageServiceProvider = Document.Project.Solution.Workspace.Services.GetExtendedLanguageServices(State.TypeToGenerateIn.Language); -#else - var languageServiceProvider = Document.Project.Solution.Services.GetLanguageServices(State.TypeToGenerateIn.Language); -#endif var syntaxFacts = languageServiceProvider.GetService(); diff --git a/src/Analyzers/Core/CodeFixes/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.State.cs b/src/Analyzers/Core/CodeFixes/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.State.cs index 9e0238d40b596..3356e6913fb69 100644 --- a/src/Analyzers/Core/CodeFixes/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.State.cs +++ b/src/Analyzers/Core/CodeFixes/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.State.cs @@ -82,11 +82,7 @@ protected async Task TryFinishInitializingStateAsync(TService service, Sem .GetMembers(IdentifierToken.ValueText) .OfType(); -#if CODE_STYLE var destinationProvider = document.Project.Solution.Workspace.Services.GetExtendedLanguageServices(TypeToGenerateIn.Language); -#else - var destinationProvider = document.Project.Solution.Services.GetLanguageServices(TypeToGenerateIn.Language); -#endif var syntaxFacts = destinationProvider.GetService(); var syntaxFactory = destinationProvider.GetService(); diff --git a/src/Analyzers/Core/CodeFixes/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.cs b/src/Analyzers/Core/CodeFixes/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.cs index bc8ba4ff7c24e..f194be1ce987e 100644 --- a/src/Analyzers/Core/CodeFixes/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.cs +++ b/src/Analyzers/Core/CodeFixes/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.cs @@ -54,11 +54,7 @@ protected async ValueTask> GetActionsAsync(Document d if (canGenerateAbstractly) result.Add(new GenerateParameterizedMemberCodeAction((TService)this, document, state, isAbstract: true, generateProperty: false)); -#if CODE_STYLE var semanticFacts = document.Project.Solution.Workspace.Services.GetExtendedLanguageServices(state.TypeToGenerateIn.Language).GetService(); -#else - var semanticFacts = document.Project.Solution.Services.GetLanguageServices(state.TypeToGenerateIn.Language).GetService(); -#endif if (semanticFacts.SupportsParameterizedProperties && state.InvocationExpressionOpt != null) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/AddImport/AddImportPlacementOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/AddImport/AddImportPlacementOptions.cs index ce7d53e0b3f64..e9497203663d9 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/AddImport/AddImportPlacementOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/AddImport/AddImportPlacementOptions.cs @@ -3,16 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.Serialization; -using System.Threading; -using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeStyle; -using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.CodeAnalysis.Options; - -#if !CODE_STYLE -using Microsoft.CodeAnalysis.Host; -#endif namespace Microsoft.CodeAnalysis.AddImport; diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs index 9edd5a1e66e0c..2e2eff4245b46 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs @@ -2,14 +2,10 @@ // 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 System.Runtime.Serialization; using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Simplification; using Microsoft.CodeAnalysis.AddImport; -using Microsoft.CodeAnalysis.Options; -using Roslyn.Utilities; #if !CODE_STYLE using Microsoft.CodeAnalysis.Host; diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs index b0738940b39aa..7cf860d1ad7f2 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs @@ -12,9 +12,10 @@ using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.CodeCleanup; -#if !CODE_STYLE using Microsoft.CodeAnalysis.Host; -#endif +//#if !CODE_STYLE +//using Microsoft.CodeAnalysis.Host; +//#endif namespace Microsoft.CodeAnalysis.CodeGeneration; From 1f21f90f5068314dadef852243195f3bf144e5ab Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 11:42:16 -0700 Subject: [PATCH 02/26] in progress --- ....cs => OrganizeImportsOptionsProviders.cs} | 16 ------------- .../CodeCleanupOptions.cs | 13 ----------- .../Core/CompilerExtensions.projitems | 6 ++--- .../Formatting/SyntaxFormattingOptions.cs | 5 ---- .../Core/Indentation/IndentationOptions.cs | 9 -------- .../OrganizeImports/OrganizeImportsOptions.cs | 23 +++++++++++++++++++ .../Core/Simplification/SimplifierOptions.cs | 5 ---- .../CodeCleanupOptionsProviders.cs | 16 +++++++++++++ .../CleanCodeGenerationOptions.cs | 6 ++--- .../CodeGeneration/CodeGenerationOptions.cs | 13 ++--------- .../CodeGenerationOptionsProvider.cs | 9 ++++++++ .../SyntaxFormattingOptionsProviders.cs | 3 +++ .../IndentationOptionsProviders.cs | 14 +++++++++++ .../SimplifierOptionsProviders.cs | 3 +++ .../Core/WorkspaceExtensions.projitems | 3 +++ 15 files changed, 78 insertions(+), 66 deletions(-) rename src/Workspaces/Core/Portable/OrganizeImports/{OrganizeImportsOptions.cs => OrganizeImportsOptionsProviders.cs} (67%) rename src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/{CodeCleanup => CodeGeneration}/CodeCleanupOptions.cs (77%) create mode 100644 src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/OrganizeImports/OrganizeImportsOptions.cs rename src/Workspaces/SharedUtilitiesAndExtensions/{Compiler => Workspace}/Core/CodeGeneration/CleanCodeGenerationOptions.cs (97%) rename src/Workspaces/SharedUtilitiesAndExtensions/{Compiler => Workspace}/Core/CodeGeneration/CodeGenerationOptions.cs (92%) create mode 100644 src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Indentation/IndentationOptionsProviders.cs diff --git a/src/Workspaces/Core/Portable/OrganizeImports/OrganizeImportsOptions.cs b/src/Workspaces/Core/Portable/OrganizeImports/OrganizeImportsOptionsProviders.cs similarity index 67% rename from src/Workspaces/Core/Portable/OrganizeImports/OrganizeImportsOptions.cs rename to src/Workspaces/Core/Portable/OrganizeImports/OrganizeImportsOptionsProviders.cs index 5a1e43b672b93..1d929d73dc61d 100644 --- a/src/Workspaces/Core/Portable/OrganizeImports/OrganizeImportsOptions.cs +++ b/src/Workspaces/Core/Portable/OrganizeImports/OrganizeImportsOptionsProviders.cs @@ -2,30 +2,14 @@ // 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; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.AddImport; using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Options; namespace Microsoft.CodeAnalysis.OrganizeImports; -[DataContract] -internal readonly record struct OrganizeImportsOptions -{ - [DataMember] public bool PlaceSystemNamespaceFirst { get; init; } = AddImportPlacementOptions.Default.PlaceSystemNamespaceFirst; - [DataMember] public bool SeparateImportDirectiveGroups { get; init; } = SyntaxFormattingOptions.CommonDefaults.SeparateImportDirectiveGroups; - [DataMember] public string NewLine { get; init; } = LineFormattingOptions.Default.NewLine; - - public OrganizeImportsOptions() - { - } - - public static readonly OrganizeImportsOptions Default = new(); -} - internal static class OrganizeImportsOptionsProviders { public static OrganizeImportsOptions GetOrganizeImportsOptions(this IOptionsReader options, string language) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeCleanupOptions.cs similarity index 77% rename from src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeCleanupOptions.cs index 2e2eff4245b46..243677ebb6796 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeCleanupOptions.cs @@ -6,11 +6,7 @@ using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Simplification; using Microsoft.CodeAnalysis.AddImport; - -#if !CODE_STYLE -using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.OrganizeImports; -#endif namespace Microsoft.CodeAnalysis.CodeCleanup; @@ -22,14 +18,6 @@ internal sealed record class CodeCleanupOptions [DataMember] public AddImportPlacementOptions AddImportOptions { get; init; } = AddImportPlacementOptions.Default; [DataMember] public DocumentFormattingOptions DocumentFormattingOptions { get; init; } = DocumentFormattingOptions.Default; -#if !CODE_STYLE - public static CodeCleanupOptions GetDefault(LanguageServices languageServices) - => new() - { - FormattingOptions = SyntaxFormattingOptions.GetDefault(languageServices), - SimplifierOptions = SimplifierOptions.GetDefault(languageServices) - }; - public OrganizeImportsOptions GetOrganizeImportsOptions() => new() { @@ -37,5 +25,4 @@ public OrganizeImportsOptions GetOrganizeImportsOptions() PlaceSystemNamespaceFirst = AddImportOptions.PlaceSystemNamespaceFirst, NewLine = FormattingOptions.LineFormatting.NewLine, }; -#endif } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems index 824a4a4616610..6b21f14ea161c 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems @@ -190,9 +190,7 @@ InternalUtilities\UnicodeCharacterUtilities.cs - - - + @@ -281,6 +279,7 @@ + @@ -641,6 +640,7 @@ + diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/SyntaxFormattingOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/SyntaxFormattingOptions.cs index 2163bb66630ea..390e8ea2e7509 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/SyntaxFormattingOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/SyntaxFormattingOptions.cs @@ -39,9 +39,4 @@ private protected SyntaxFormattingOptions(IOptionsReader options, string languag public int TabSize => LineFormatting.TabSize; public int IndentationSize => LineFormatting.IndentationSize; public string NewLine => LineFormatting.NewLine; - -#if !CODE_STYLE - public static SyntaxFormattingOptions GetDefault(Host.LanguageServices languageServices) - => languageServices.GetRequiredService().DefaultOptions; -#endif } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Indentation/IndentationOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Indentation/IndentationOptions.cs index 368be8c83f237..44979917caeef 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Indentation/IndentationOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Indentation/IndentationOptions.cs @@ -5,10 +5,6 @@ using System.Runtime.Serialization; using Microsoft.CodeAnalysis.Formatting; -#if !CODE_STYLE -using Microsoft.CodeAnalysis.Host; -#endif - namespace Microsoft.CodeAnalysis.Indentation; [DataContract] @@ -19,9 +15,4 @@ internal readonly record struct IndentationOptions( [DataMember(Order = 2)] public FormattingOptions2.IndentStyle IndentStyle { get; init; } = DefaultIndentStyle; public const FormattingOptions2.IndentStyle DefaultIndentStyle = FormattingOptions2.IndentStyle.Smart; - -#if !CODE_STYLE - public static IndentationOptions GetDefault(LanguageServices languageServices) - => new(SyntaxFormattingOptions.GetDefault(languageServices)); -#endif } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/OrganizeImports/OrganizeImportsOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/OrganizeImports/OrganizeImportsOptions.cs new file mode 100644 index 0000000000000..88527f96513e3 --- /dev/null +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/OrganizeImports/OrganizeImportsOptions.cs @@ -0,0 +1,23 @@ +// 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; +using Microsoft.CodeAnalysis.AddImport; +using Microsoft.CodeAnalysis.Formatting; + +namespace Microsoft.CodeAnalysis.OrganizeImports; + +[DataContract] +internal readonly record struct OrganizeImportsOptions +{ + [DataMember] public bool PlaceSystemNamespaceFirst { get; init; } = AddImportPlacementOptions.Default.PlaceSystemNamespaceFirst; + [DataMember] public bool SeparateImportDirectiveGroups { get; init; } = SyntaxFormattingOptions.CommonDefaults.SeparateImportDirectiveGroups; + [DataMember] public string NewLine { get; init; } = LineFormattingOptions.Default.NewLine; + + public OrganizeImportsOptions() + { + } + + public static readonly OrganizeImportsOptions Default = new(); +} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Simplification/SimplifierOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Simplification/SimplifierOptions.cs index 6d5818eb6d6d3..42ba4b36ca865 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Simplification/SimplifierOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Simplification/SimplifierOptions.cs @@ -52,9 +52,4 @@ public bool TryGetQualifyMemberAccessOption(SymbolKind symbolKind, [NotNullWhen( return option != null; } - -#if !CODE_STYLE - public static SimplifierOptions GetDefault(Host.LanguageServices languageServices) - => languageServices.GetRequiredService().DefaultOptions; -#endif } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs index 396b813e9f95c..10db6110ab297 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs @@ -8,6 +8,7 @@ using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.OrganizeImports; using Microsoft.CodeAnalysis.Simplification; namespace Microsoft.CodeAnalysis.CodeCleanup; @@ -30,5 +31,20 @@ public static async ValueTask GetCodeCleanupOptionsAsync(thi return configOptions.GetCodeCleanupOptions(document.Project.Services, document.AllowImportsInHiddenRegions()); } #endif + + public static CodeCleanupOptions GetDefault(LanguageServices languageServices) + => new() + { + FormattingOptions = SyntaxFormattingOptionsProviders.GetDefault(languageServices), + SimplifierOptions = SimplifierOptionsProviders.GetDefault(languageServices) + }; + + public OrganizeImportsOptions GetOrganizeImportsOptions() + => new() + { + SeparateImportDirectiveGroups = FormattingOptions.SeparateImportDirectiveGroups, + PlaceSystemNamespaceFirst = AddImportOptions.PlaceSystemNamespaceFirst, + NewLine = FormattingOptions.LineFormatting.NewLine, + }; } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CleanCodeGenerationOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CleanCodeGenerationOptions.cs similarity index 97% rename from src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CleanCodeGenerationOptions.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CleanCodeGenerationOptions.cs index 1acef75129fa3..f22999013d334 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CleanCodeGenerationOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CleanCodeGenerationOptions.cs @@ -8,9 +8,9 @@ using Microsoft.CodeAnalysis.CodeCleanup; using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles; -#if !CODE_STYLE +//#if !CODE_STYLE using Microsoft.CodeAnalysis.Host; -#endif +//#endif namespace Microsoft.CodeAnalysis.CodeGeneration; @@ -23,7 +23,6 @@ internal readonly record struct CleanCodeGenerationOptions [DataMember] public required CodeCleanupOptions CleanupOptions { get; init; } -#if !CODE_STYLE public static CleanCodeGenerationOptions GetDefault(LanguageServices languageServices) => new() { @@ -37,7 +36,6 @@ public CodeAndImportGenerationOptions CodeAndImportGenerationOptions GenerationOptions = GenerationOptions, AddImportOptions = CleanupOptions.AddImportOptions }; -#endif } #if !CODE_STYLE diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptions.cs similarity index 92% rename from src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptions.cs index 7cf860d1ad7f2..f231778de1a39 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptions.cs @@ -3,16 +3,11 @@ // See the LICENSE file in the project root for more information. using System.Runtime.Serialization; -using System.Threading; -using System.Threading.Tasks; using Microsoft.CodeAnalysis.AddImport; -using Roslyn.Utilities; -using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles; using Microsoft.CodeAnalysis.CodeStyle; -using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.CodeCleanup; - +using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles; using Microsoft.CodeAnalysis.Host; +using Microsoft.CodeAnalysis.Options; //#if !CODE_STYLE //using Microsoft.CodeAnalysis.Host; //#endif @@ -40,10 +35,8 @@ private protected CodeGenerationOptions(IOptionsReader options, string language) NamingStyle = options.GetOption(NamingStyleOptions.NamingPreferences, language); } -#if !CODE_STYLE public static CodeGenerationOptions GetDefault(LanguageServices languageServices) => languageServices.GetRequiredService().DefaultOptions; -#endif } [DataContract] @@ -55,12 +48,10 @@ internal readonly record struct CodeAndImportGenerationOptions [DataMember] public required AddImportPlacementOptions AddImportOptions { get; init; } -#if !CODE_STYLE internal static CodeAndImportGenerationOptions GetDefault(LanguageServices languageServices) => new() { GenerationOptions = CodeGenerationOptions.GetDefault(languageServices), AddImportOptions = AddImportPlacementOptions.Default }; -#endif } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProvider.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProvider.cs index 602a383f4e600..95e5502d5cb2f 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProvider.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProvider.cs @@ -6,9 +6,11 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.AddImport; using Microsoft.CodeAnalysis.CodeCleanup; +using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; +using Microsoft.CodeAnalysis.Simplification; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CodeGeneration; @@ -46,4 +48,11 @@ public static async ValueTask GetCodeGenerationInfoAs var service = document.GetRequiredLanguageService(); return service.GetInfo(context, options, document.Project.ParseOptions); } + + public static CodeCleanupOptions GetDefault(LanguageServices languageServices) + => new() + { + FormattingOptions = SyntaxFormattingOptions.GetDefault(languageServices), + SimplifierOptions = SimplifierOptions.GetDefault(languageServices) + }; } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Formatting/SyntaxFormattingOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Formatting/SyntaxFormattingOptionsProviders.cs index be9cf562bac4e..8e5e5c41e1530 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Formatting/SyntaxFormattingOptionsProviders.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Formatting/SyntaxFormattingOptionsProviders.cs @@ -22,4 +22,7 @@ public static async ValueTask GetSyntaxFormattingOption var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); return formatting.GetFormattingOptions(configOptions); } + + public static SyntaxFormattingOptions GetDefault(Host.LanguageServices languageServices) + => languageServices.GetRequiredService().DefaultOptions; } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Indentation/IndentationOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Indentation/IndentationOptionsProviders.cs new file mode 100644 index 0000000000000..099000384fa1e --- /dev/null +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Indentation/IndentationOptionsProviders.cs @@ -0,0 +1,14 @@ +// 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.Formatting; +using Microsoft.CodeAnalysis.Host; + +namespace Microsoft.CodeAnalysis.Indentation; + +internal static class IndentationOptionsProviders +{ + public static IndentationOptions GetDefault(LanguageServices languageServices) + => new(SyntaxFormattingOptionsProviders.GetDefault(languageServices)); +} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/SimplifierOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/SimplifierOptionsProviders.cs index 9bb772509f3d5..2ed19877fdcc3 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/SimplifierOptionsProviders.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/SimplifierOptionsProviders.cs @@ -22,5 +22,8 @@ public static async ValueTask GetSimplifierOptionsAsync(this var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); return simplification.GetSimplifierOptions(configOptions); } + + public static SimplifierOptions GetDefault(Host.LanguageServices languageServices) + => languageServices.GetRequiredService().DefaultOptions; } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems index 3aa2b46b92d4e..fdc6023558781 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems @@ -10,6 +10,8 @@ + + @@ -20,6 +22,7 @@ + From ca4f838edf9ef4ef4a524056805ca6975369526e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 11:44:20 -0700 Subject: [PATCH 03/26] fix --- .../Core/CodeCleanup/CodeCleanupOptionsProviders.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs index 10db6110ab297..aaf1bb96c927a 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs @@ -38,13 +38,5 @@ public static CodeCleanupOptions GetDefault(LanguageServices languageServices) FormattingOptions = SyntaxFormattingOptionsProviders.GetDefault(languageServices), SimplifierOptions = SimplifierOptionsProviders.GetDefault(languageServices) }; - - public OrganizeImportsOptions GetOrganizeImportsOptions() - => new() - { - SeparateImportDirectiveGroups = FormattingOptions.SeparateImportDirectiveGroups, - PlaceSystemNamespaceFirst = AddImportOptions.PlaceSystemNamespaceFirst, - NewLine = FormattingOptions.LineFormatting.NewLine, - }; } From f126e9157c1bbaa5529262ba6fd8afbe22869aba Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 11:48:34 -0700 Subject: [PATCH 04/26] Move more --- .../CSharpCodeGenerationOptions.cs | 9 ------- .../CodeCleanupOptions.cs | 0 .../CodeAndImportGenerationOptions.cs | 18 ++++++++++++++ .../CodeGeneration/CodeGenerationOptions.cs | 24 ------------------- .../Core/CompilerExtensions.projitems | 4 +++- ...CodeAndImportGenerationOptionsProviders.cs | 18 ++++++++++++++ ...r.cs => CodeGenerationOptionsProviders.cs} | 10 ++------ .../Core/WorkspaceExtensions.projitems | 4 ++-- 8 files changed, 43 insertions(+), 44 deletions(-) rename src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/{CodeGeneration => CodeCleanup}/CodeCleanupOptions.cs (100%) create mode 100644 src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeAndImportGenerationOptions.cs rename src/Workspaces/SharedUtilitiesAndExtensions/{Workspace => Compiler}/Core/CodeGeneration/CodeGenerationOptions.cs (57%) create mode 100644 src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeAndImportGenerationOptionsProviders.cs rename src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/{CodeGenerationOptionsProvider.cs => CodeGenerationOptionsProviders.cs} (87%) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/CodeGeneration/CSharpCodeGenerationOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/CodeGeneration/CSharpCodeGenerationOptions.cs index a428cc68f2dde..55bef9fbf4b22 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/CodeGeneration/CSharpCodeGenerationOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/CodeGeneration/CSharpCodeGenerationOptions.cs @@ -2,20 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.AddImport; using Microsoft.CodeAnalysis.CodeGeneration; using Microsoft.CodeAnalysis.CodeStyle; using Microsoft.CodeAnalysis.CSharp.CodeStyle; -using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles; -using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Options; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.CodeGeneration; diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeCleanupOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs similarity index 100% rename from src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeCleanupOptions.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeAndImportGenerationOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeAndImportGenerationOptions.cs new file mode 100644 index 0000000000000..36c8a758344f6 --- /dev/null +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeAndImportGenerationOptions.cs @@ -0,0 +1,18 @@ +// 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; +using Microsoft.CodeAnalysis.AddImport; + +namespace Microsoft.CodeAnalysis.CodeGeneration; + +[DataContract] +internal readonly record struct CodeAndImportGenerationOptions +{ + [DataMember] + public required CodeGenerationOptions GenerationOptions { get; init; } + + [DataMember] + public required AddImportPlacementOptions AddImportOptions { get; init; } +} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs similarity index 57% rename from src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptions.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs index f231778de1a39..0061f26bf1b40 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs @@ -6,11 +6,7 @@ using Microsoft.CodeAnalysis.AddImport; using Microsoft.CodeAnalysis.CodeStyle; using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles; -using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Options; -//#if !CODE_STYLE -//using Microsoft.CodeAnalysis.Host; -//#endif namespace Microsoft.CodeAnalysis.CodeGeneration; @@ -34,24 +30,4 @@ private protected CodeGenerationOptions(IOptionsReader options, string language) { NamingStyle = options.GetOption(NamingStyleOptions.NamingPreferences, language); } - - public static CodeGenerationOptions GetDefault(LanguageServices languageServices) - => languageServices.GetRequiredService().DefaultOptions; -} - -[DataContract] -internal readonly record struct CodeAndImportGenerationOptions -{ - [DataMember] - public required CodeGenerationOptions GenerationOptions { get; init; } - - [DataMember] - public required AddImportPlacementOptions AddImportOptions { get; init; } - - internal static CodeAndImportGenerationOptions GetDefault(LanguageServices languageServices) - => new() - { - GenerationOptions = CodeGenerationOptions.GetDefault(languageServices), - AddImportOptions = AddImportPlacementOptions.Default - }; } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems index 6b21f14ea161c..3c9d6c4f2a066 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems @@ -190,7 +190,9 @@ InternalUtilities\UnicodeCharacterUtilities.cs - + + + diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeAndImportGenerationOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeAndImportGenerationOptionsProviders.cs new file mode 100644 index 0000000000000..6123361bdd32c --- /dev/null +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeAndImportGenerationOptionsProviders.cs @@ -0,0 +1,18 @@ +// 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.AddImport; +using Microsoft.CodeAnalysis.Host; + +namespace Microsoft.CodeAnalysis.CodeGeneration; + +internal static class CodeAndImportGenerationOptionsProviders +{ + internal static CodeAndImportGenerationOptions GetDefault(LanguageServices languageServices) + => new() + { + GenerationOptions = CodeGenerationOptionsProviders.GetDefault(languageServices), + AddImportOptions = AddImportPlacementOptions.Default + }; +} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProvider.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProviders.cs similarity index 87% rename from src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProvider.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProviders.cs index 95e5502d5cb2f..c305e949c7a4e 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProvider.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProviders.cs @@ -6,11 +6,9 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.AddImport; using Microsoft.CodeAnalysis.CodeCleanup; -using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.CodeAnalysis.Simplification; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CodeGeneration; @@ -49,10 +47,6 @@ public static async ValueTask GetCodeGenerationInfoAs return service.GetInfo(context, options, document.Project.ParseOptions); } - public static CodeCleanupOptions GetDefault(LanguageServices languageServices) - => new() - { - FormattingOptions = SyntaxFormattingOptions.GetDefault(languageServices), - SimplifierOptions = SimplifierOptions.GetDefault(languageServices) - }; + public static CodeGenerationOptions GetDefault(LanguageServices languageServices) + => languageServices.GetRequiredService().DefaultOptions; } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems index fdc6023558781..575b74a52ecc6 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems @@ -11,8 +11,8 @@ - - + + From e21071ffd38ae250a1c1ce3a227e96389b935704 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 11:51:57 -0700 Subject: [PATCH 05/26] in progress --- .../ExtractMethod/ExtractMethodOptions.cs | 4 ++-- .../CodeCleanupOptionsProviders.cs | 10 +++++++--- .../CleanCodeGenerationOptions.cs | 20 +++++++------------ 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/Workspaces/Core/Portable/ExtractMethod/ExtractMethodOptions.cs b/src/Workspaces/Core/Portable/ExtractMethod/ExtractMethodOptions.cs index 1eab0a3867d8f..00ed83a7d1461 100644 --- a/src/Workspaces/Core/Portable/ExtractMethod/ExtractMethodOptions.cs +++ b/src/Workspaces/Core/Portable/ExtractMethod/ExtractMethodOptions.cs @@ -26,8 +26,8 @@ internal readonly record struct ExtractMethodGenerationOptions public static ExtractMethodGenerationOptions GetDefault(LanguageServices languageServices) => new() { - CodeGenerationOptions = CodeGenerationOptions.GetDefault(languageServices), - CodeCleanupOptions = CodeCleanupOptions.GetDefault(languageServices), + CodeGenerationOptions = CodeGenerationOptionsProviders.GetDefault(languageServices), + CodeCleanupOptions = CodeCleanupOptionsProviders.GetDefault(languageServices), }; public ExtractMethodGenerationOptions() diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs index aaf1bb96c927a..66a8d1c5aa85e 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs @@ -8,7 +8,7 @@ using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.OrganizeImports; +using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Simplification; namespace Microsoft.CodeAnalysis.CodeCleanup; @@ -24,13 +24,17 @@ public static CodeCleanupOptions GetCodeCleanupOptions(this IOptionsReader optio DocumentFormattingOptions = options.GetDocumentFormattingOptions(), }; -#if !CODE_STYLE +#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public static async ValueTask GetCodeCleanupOptionsAsync(this Document document, CancellationToken cancellationToken) +#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { +#if CODE_STYLE + return GetDefault(document.Project.GetExtendedLanguageServices().LanguageServices); +#else var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); return configOptions.GetCodeCleanupOptions(document.Project.Services, document.AllowImportsInHiddenRegions()); - } #endif + } public static CodeCleanupOptions GetDefault(LanguageServices languageServices) => new() diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CleanCodeGenerationOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CleanCodeGenerationOptions.cs index f22999013d334..eba41e6db113d 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CleanCodeGenerationOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CleanCodeGenerationOptions.cs @@ -6,11 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeCleanup; -using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles; - -//#if !CODE_STYLE using Microsoft.CodeAnalysis.Host; -//#endif namespace Microsoft.CodeAnalysis.CodeGeneration; @@ -23,13 +19,6 @@ internal readonly record struct CleanCodeGenerationOptions [DataMember] public required CodeCleanupOptions CleanupOptions { get; init; } - public static CleanCodeGenerationOptions GetDefault(LanguageServices languageServices) - => new() - { - GenerationOptions = CodeGenerationOptions.GetDefault(languageServices), - CleanupOptions = CodeCleanupOptions.GetDefault(languageServices) - }; - public CodeAndImportGenerationOptions CodeAndImportGenerationOptions => new() { @@ -38,9 +27,15 @@ public CodeAndImportGenerationOptions CodeAndImportGenerationOptions }; } -#if !CODE_STYLE internal static class CleanCodeGenerationOptionsProviders { + public static CleanCodeGenerationOptions GetDefault(LanguageServices languageServices) + => new() + { + GenerationOptions = CodeGenerationOptionsProviders.GetDefault(languageServices), + CleanupOptions = CodeCleanupOptionsProviders.GetDefault(languageServices) + }; + public static async ValueTask GetCleanCodeGenerationOptionsAsync(this Document document, CancellationToken cancellationToken) => new() { @@ -48,4 +43,3 @@ public static async ValueTask GetCleanCodeGeneration CleanupOptions = await document.GetCodeCleanupOptionsAsync(cancellationToken).ConfigureAwait(false) }; } -#endif From 80882c152817e426a90d5ac26202dbed79545e01 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 11:53:18 -0700 Subject: [PATCH 06/26] Fix layering --- .../Core/Portable/FullyQualify/AbstractFullyQualifyService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Features/Core/Portable/FullyQualify/AbstractFullyQualifyService.cs b/src/Features/Core/Portable/FullyQualify/AbstractFullyQualifyService.cs index 226d4274bac46..aad6340b3f3a5 100644 --- a/src/Features/Core/Portable/FullyQualify/AbstractFullyQualifyService.cs +++ b/src/Features/Core/Portable/FullyQualify/AbstractFullyQualifyService.cs @@ -222,7 +222,7 @@ private async Task> ProcessNodeAsync(Document document, var newRoot = await ReplaceNodeAsync(simpleName, containerName, originalSymbol.IsType, cancellationToken).ConfigureAwait(false); var newDocument = document.WithSyntaxRoot(newRoot); var cleanedDocument = await CodeAction.CleanupDocumentAsync( - newDocument, CodeCleanupOptions.GetDefault(document.Project.Services), cancellationToken).ConfigureAwait(false); + newDocument, await document.GetCodeCleanupOptionsAsync(cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); return await cleanedDocument.GetTextChangesAsync(document, cancellationToken).ConfigureAwait(false); } From 0ee9423622f0c34ba1eccc59794eb007db0900fd Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 11:54:07 -0700 Subject: [PATCH 07/26] Fixes --- .../Formatting/AbstractNewDocumentFormattingServiceTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EditorFeatures/TestUtilities/Formatting/AbstractNewDocumentFormattingServiceTests.cs b/src/EditorFeatures/TestUtilities/Formatting/AbstractNewDocumentFormattingServiceTests.cs index 441ac828ce5b6..5a601ff6936bd 100644 --- a/src/EditorFeatures/TestUtilities/Formatting/AbstractNewDocumentFormattingServiceTests.cs +++ b/src/EditorFeatures/TestUtilities/Formatting/AbstractNewDocumentFormattingServiceTests.cs @@ -32,7 +32,7 @@ internal async Task TestAsync(string testCode, string expected, OptionsCollectio var cleanupOptions = options?.GetCodeCleanupOptions(languageServices, allowImportsInHiddenRegions: false) ?? - CodeCleanupOptions.GetDefault(languageServices); + CodeCleanupOptionsProviders.GetDefault(languageServices); var formattingService = document.GetRequiredLanguageService(); var formattedDocument = await formattingService.FormatNewDocumentAsync(document, hintDocument: null, cleanupOptions, CancellationToken.None); From de44b14cc5bf850ef140d0a148bee888ab2850a1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 11:58:19 -0700 Subject: [PATCH 08/26] Tests --- ...stractNewDocumentFormattingServiceTests.cs | 2 +- .../CoreTest/CodeCleanup/CodeCleanupTests.cs | 74 +++++++++---------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/EditorFeatures/TestUtilities/Formatting/AbstractNewDocumentFormattingServiceTests.cs b/src/EditorFeatures/TestUtilities/Formatting/AbstractNewDocumentFormattingServiceTests.cs index 5a601ff6936bd..206227baa5c13 100644 --- a/src/EditorFeatures/TestUtilities/Formatting/AbstractNewDocumentFormattingServiceTests.cs +++ b/src/EditorFeatures/TestUtilities/Formatting/AbstractNewDocumentFormattingServiceTests.cs @@ -32,7 +32,7 @@ internal async Task TestAsync(string testCode, string expected, OptionsCollectio var cleanupOptions = options?.GetCodeCleanupOptions(languageServices, allowImportsInHiddenRegions: false) ?? - CodeCleanupOptionsProviders.GetDefault(languageServices); + await document.GetCodeCleanupOptionsAsync(CancellationToken.None); var formattingService = document.GetRequiredLanguageService(); var formattedDocument = await formattingService.FormatNewDocumentAsync(document, hintDocument: null, cleanupOptions, CancellationToken.None); diff --git a/src/Workspaces/CoreTest/CodeCleanup/CodeCleanupTests.cs b/src/Workspaces/CoreTest/CodeCleanup/CodeCleanupTests.cs index baf2a8c27fce4..bd2ddbcd1a73b 100644 --- a/src/Workspaces/CoreTest/CodeCleanup/CodeCleanupTests.cs +++ b/src/Workspaces/CoreTest/CodeCleanup/CodeCleanupTests.cs @@ -38,7 +38,7 @@ public void DefaultCSharpCodeCleanups() public async Task CodeCleanersCSharp_NoSpans() { var document = CreateDocument("class C { }", LanguageNames.CSharp); - var cleanDocument = await CodeCleaner.CleanupAsync(document, [], CodeCleanupOptions.GetDefault(document.Project.Services)); + var cleanDocument = await CodeCleaner.CleanupAsync(document, [], await document.GetCodeCleanupOptionsAsync(CancellationToken.None)); Assert.Equal(document, cleanDocument); } @@ -47,7 +47,7 @@ public async Task CodeCleanersCSharp_NoSpans() public async Task CodeCleanersCSharp_Document() { var document = CreateDocument("class C { }", LanguageNames.CSharp); - var cleanDocument = await CodeCleaner.CleanupAsync(document, CodeCleanupOptions.GetDefault(document.Project.Services)); + var cleanDocument = await CodeCleaner.CleanupAsync(document, await document.GetCodeCleanupOptionsAsync(CancellationToken.None)); Assert.Equal(document, cleanDocument); } @@ -57,7 +57,7 @@ public async Task CodeCleanersCSharp_Span() { var document = CreateDocument("class C { }", LanguageNames.CSharp); var root = await document.GetSyntaxRootAsync(); - var cleanDocument = await CodeCleaner.CleanupAsync(document, root.FullSpan, CodeCleanupOptions.GetDefault(document.Project.Services)); + var cleanDocument = await CodeCleaner.CleanupAsync(document, root.FullSpan, await document.GetCodeCleanupOptionsAsync(CancellationToken.None)); Assert.Equal(document, cleanDocument); } @@ -67,7 +67,7 @@ public async Task CodeCleanersCSharp_Spans() { var document = CreateDocument("class C { }", LanguageNames.CSharp); var root = await document.GetSyntaxRootAsync(); - var cleanDocument = await CodeCleaner.CleanupAsync(document, [root.FullSpan], CodeCleanupOptions.GetDefault(document.Project.Services)); + var cleanDocument = await CodeCleaner.CleanupAsync(document, [root.FullSpan], await document.GetCodeCleanupOptionsAsync(CancellationToken.None)); Assert.Equal(document, cleanDocument); } @@ -90,7 +90,7 @@ public async Task CodeCleanersVisualBasic_NoSpans() { var document = CreateDocument(@"Class C End Class", LanguageNames.VisualBasic); - var cleanDocument = await CodeCleaner.CleanupAsync(document, [], CodeCleanupOptions.GetDefault(document.Project.Services)); + var cleanDocument = await CodeCleaner.CleanupAsync(document, [], await document.GetCodeCleanupOptionsAsync(CancellationToken.None)); Assert.Equal(document, cleanDocument); } @@ -100,7 +100,7 @@ public async Task CodeCleanersVisualBasic_Document() { var document = CreateDocument(@"Class C End Class", LanguageNames.VisualBasic); - var cleanDocument = await CodeCleaner.CleanupAsync(document, CodeCleanupOptions.GetDefault(document.Project.Services)); + var cleanDocument = await CodeCleaner.CleanupAsync(document, await document.GetCodeCleanupOptionsAsync(CancellationToken.None)); Assert.Equal(document, cleanDocument); } @@ -111,7 +111,7 @@ public async Task CodeCleanersVisualBasic_Span() var document = CreateDocument(@"Class C End Class", LanguageNames.VisualBasic); var root = await document.GetSyntaxRootAsync(); - var cleanDocument = await CodeCleaner.CleanupAsync(document, root.FullSpan, CodeCleanupOptions.GetDefault(document.Project.Services)); + var cleanDocument = await CodeCleaner.CleanupAsync(document, root.FullSpan, await document.GetCodeCleanupOptionsAsync(CancellationToken.None)); Assert.Equal(document, cleanDocument); } @@ -122,7 +122,7 @@ public async Task CodeCleanersVisualBasic_Spans() var document = CreateDocument(@"Class C End Class", LanguageNames.VisualBasic); var root = await document.GetSyntaxRootAsync(); - var cleanDocument = await CodeCleaner.CleanupAsync(document, [root.FullSpan], CodeCleanupOptions.GetDefault(document.Project.Services)); + var cleanDocument = await CodeCleaner.CleanupAsync(document, [root.FullSpan], await document.GetCodeCleanupOptionsAsync(CancellationToken.None)); Assert.Equal(document, cleanDocument); } @@ -134,7 +134,7 @@ public async Task CodeCleanersCSharp_Annotation() var annotation = new SyntaxAnnotation(); document = document.WithSyntaxRoot((await document.GetSyntaxRootAsync()).WithAdditionalAnnotations(annotation)); - var cleanDocument = await CodeCleaner.CleanupAsync(document, annotation, CodeCleanupOptions.GetDefault(document.Project.Services)); + var cleanDocument = await CodeCleaner.CleanupAsync(document, annotation, await document.GetCodeCleanupOptionsAsync(CancellationToken.None)); Assert.Equal(document, cleanDocument); } @@ -147,7 +147,7 @@ public async Task CodeCleanersVisualBasic_Annotation() var annotation = new SyntaxAnnotation(); document = document.WithSyntaxRoot((await document.GetSyntaxRootAsync()).WithAdditionalAnnotations(annotation)); - var cleanDocument = await CodeCleaner.CleanupAsync(document, annotation, CodeCleanupOptions.GetDefault(document.Project.Services)); + var cleanDocument = await CodeCleaner.CleanupAsync(document, annotation, await document.GetCodeCleanupOptionsAsync(CancellationToken.None)); Assert.Equal(document, cleanDocument); } @@ -155,19 +155,19 @@ public async Task CodeCleanersVisualBasic_Annotation() #endregion [Fact] - public void EntireRange() + public Task EntireRange() => VerifyRange("{|b:{|r:class C {}|}|}"); [Fact] - public void EntireRange_Merge() + public Task EntireRange_Merge() => VerifyRange("{|r:class {|b:C { }|} class {|b: B { } |}|}"); [Fact] - public void EntireRange_EndOfFile() + public Task EntireRange_EndOfFile() => VerifyRange("{|r:class {|b:C { }|} class {|b: B { } |} |}"); [Fact] - public void EntireRangeWithTransformation_RemoveClass() + public async Task EntireRangeWithTransformation_RemoveClass() { var expectedResult = (IEnumerable)null; var transformer = new MockCodeCleanupProvider() @@ -183,11 +183,11 @@ public void EntireRangeWithTransformation_RemoveClass() } }; - VerifyRange("{|b:class C {}|}", transformer, ref expectedResult); + await VerifyRange("{|b:class C {}|}", transformer, expectedResult); } [Fact] - public void EntireRangeWithTransformation_AddMember() + public async Task EntireRangeWithTransformation_AddMember() { var expectedResult = (IEnumerable)null; var transformer = new MockCodeCleanupProvider() @@ -205,11 +205,11 @@ public void EntireRangeWithTransformation_AddMember() } }; - VerifyRange("{|b:class C {}|}", transformer, ref expectedResult); + await VerifyRange("{|b:class C {}|}", transformer, expectedResult); } [Fact] - public void RangeWithTransformation_AddMember() + public async Task RangeWithTransformation_AddMember() { var expectedResult = (IEnumerable)null; var transformer = new MockCodeCleanupProvider() @@ -227,11 +227,11 @@ public void RangeWithTransformation_AddMember() } }; - VerifyRange("namespace N { {|b:class C {}|} }", transformer, ref expectedResult); + await VerifyRange("namespace N { {|b:class C {}|} }", transformer, expectedResult); } [Fact] - public void RangeWithTransformation_RemoveMember() + public async Task RangeWithTransformation_RemoveMember() { var expectedResult = (IEnumerable)null; var transformer = new MockCodeCleanupProvider() @@ -249,23 +249,23 @@ public void RangeWithTransformation_RemoveMember() } }; - VerifyRange("namespace N { {|b:class C { void Method() { } }|} }", transformer, ref expectedResult); + await VerifyRange("namespace N { {|b:class C { void Method() { } }|} }", transformer, expectedResult); } [Fact] - public void MultipleRange_Overlapped() + public Task MultipleRange_Overlapped() => VerifyRange("namespace N {|r:{ {|b:class C { {|b:void Method() { }|} }|} }|}"); [Fact] - public void MultipleRange_Adjacent() + public Task MultipleRange_Adjacent() => VerifyRange("namespace N {|r:{ {|b:class C { |}{|b:void Method() { } }|} }|}"); [Fact] - public void MultipleRanges() + public Task MultipleRanges() => VerifyRange("namespace N { class C {|r:{ {|b:void Method() { }|} }|} class C2 {|r:{ {|b:void Method() { }|} }|} }"); [Fact, WorkItem(12848, "DevDiv_Projects/Roslyn")] - public void DoNotCrash_VB() + public async Task DoNotCrash_VB() { var code = @"#If DEBUG OrElse TRACE Then Imports System.Diagnostics @@ -281,7 +281,7 @@ Imports System.Diagnostics #End Region #End Region"; - VerifyRange(code, LanguageNames.VisualBasic); + await VerifyRange(code, LanguageNames.VisualBasic); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/774295")] @@ -318,12 +318,12 @@ End Class Assert.NotNull(newSemanticModel); Assert.True(newSemanticModel.IsSpeculativeSemanticModel); - var cleanDocument = await CodeCleaner.CleanupAsync(document, CodeCleanupOptions.GetDefault(document.Project.Services)); + var cleanDocument = await CodeCleaner.CleanupAsync(document, await document.GetCodeCleanupOptionsAsync(CancellationToken.None)); Assert.Equal(document, cleanDocument); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/547075")] - public void TestCodeCleanupWithinNonStructuredTrivia() + public async Task TestCodeCleanupWithinNonStructuredTrivia() { var code = @" #Const ccConst = 0 @@ -339,11 +339,11 @@ Sub Main(args As String()) End Sub End Module"; - VerifyRange(code, LanguageNames.VisualBasic); + await VerifyRange(code, LanguageNames.VisualBasic); } [Fact] - public void RangeWithTransformation_OutsideOfRange() + public async Task RangeWithTransformation_OutsideOfRange() { var expectedResult = (IEnumerable)null; var transformer = new MockCodeCleanupProvider() @@ -364,31 +364,31 @@ public void RangeWithTransformation_OutsideOfRange() } }; - VerifyRange("namespace N { class C { {|b:void Method() { }|} } }", transformer, ref expectedResult); + await VerifyRange("namespace N { class C { {|b:void Method() { }|} } }", transformer, expectedResult); } public static CSharp.Syntax.MethodDeclarationSyntax CreateCSharpMethod(string returnType = "void", string methodName = "Method") => CSharp.SyntaxFactory.MethodDeclaration(CSharp.SyntaxFactory.ParseTypeName(returnType), CSharp.SyntaxFactory.Identifier(methodName)); - private static void VerifyRange(string codeWithMarker, string language = LanguageNames.CSharp) + private static async Task VerifyRange(string codeWithMarker, string language = LanguageNames.CSharp) { MarkupTestFile.GetSpans(codeWithMarker, out var codeWithoutMarker, out IDictionary> namedSpans); var expectedResult = namedSpans.TryGetValue("r", out var spans) ? spans : SpecializedCollections.EmptyEnumerable(); - VerifyRange(codeWithoutMarker, [], namedSpans["b"], ref expectedResult, language); + await VerifyRange(codeWithoutMarker, [], namedSpans["b"], expectedResult, language); } - private static void VerifyRange(string codeWithMarker, ICodeCleanupProvider transformer, ref IEnumerable expectedResult, string language = LanguageNames.CSharp) + private static async Task VerifyRange(string codeWithMarker, ICodeCleanupProvider transformer, IEnumerable expectedResult, string language = LanguageNames.CSharp) { MarkupTestFile.GetSpans(codeWithMarker, out var codeWithoutMarker, out IDictionary> namedSpans); - VerifyRange(codeWithoutMarker, [transformer], namedSpans["b"], ref expectedResult, language); + await VerifyRange(codeWithoutMarker, [transformer], namedSpans["b"], expectedResult, language); } - private static void VerifyRange(string code, ImmutableArray codeCleanups, ImmutableArray spans, ref IEnumerable expectedResult, string language) + private static async Task VerifyRange(string code, ImmutableArray codeCleanups, ImmutableArray spans, IEnumerable expectedResult, string language) { var result = (IEnumerable)null; var spanCodeCleanup = new MockCodeCleanupProvider() @@ -402,7 +402,7 @@ private static void VerifyRange(string code, ImmutableArray Date: Fri, 30 Aug 2024 11:59:58 -0700 Subject: [PATCH 09/26] Tests --- .../CoreTest/CodeCleanup/AddMissingTokensTests.cs | 3 ++- .../CoreTest/CodeCleanup/FixIncorrectTokenTests.cs | 3 ++- .../CodeCleanup/NormalizeModifiersOrOperatorsTests.cs | 3 ++- .../CoreTest/CodeCleanup/ReduceTokenTests.cs | 2 +- .../RemoveUnnecessaryLineContinuationTests.cs | 2 +- .../CoreTest/Remote/ServiceDescriptorTests.cs | 10 +++++----- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Workspaces/CoreTest/CodeCleanup/AddMissingTokensTests.cs b/src/Workspaces/CoreTest/CodeCleanup/AddMissingTokensTests.cs index 97ab62f43dd9d..be8c06f9a4dc0 100644 --- a/src/Workspaces/CoreTest/CodeCleanup/AddMissingTokensTests.cs +++ b/src/Workspaces/CoreTest/CodeCleanup/AddMissingTokensTests.cs @@ -4,6 +4,7 @@ #nullable disable +using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeCleanup; using Microsoft.CodeAnalysis.CodeCleanup.Providers; @@ -2717,7 +2718,7 @@ private static async Task VerifyAsync(string codeWithMarker, string expectedResu var document = CreateDocument(codeWithoutMarker, LanguageNames.VisualBasic); var codeCleanups = CodeCleaner.GetDefaultProviders(document).WhereAsArray(p => p.Name is PredefinedCodeCleanupProviderNames.AddMissingTokens or PredefinedCodeCleanupProviderNames.Format or PredefinedCodeCleanupProviderNames.Simplification); - var cleanDocument = await CodeCleaner.CleanupAsync(document, textSpans[0], CodeCleanupOptions.GetDefault(document.Project.Services), codeCleanups); + var cleanDocument = await CodeCleaner.CleanupAsync(document, textSpans[0], await document.GetCodeCleanupOptionsAsync(CancellationToken.None), codeCleanups); Assert.Equal(expectedResult, (await cleanDocument.GetSyntaxRootAsync()).ToFullString()); } diff --git a/src/Workspaces/CoreTest/CodeCleanup/FixIncorrectTokenTests.cs b/src/Workspaces/CoreTest/CodeCleanup/FixIncorrectTokenTests.cs index 7cfa9ee728a40..130ace2e44034 100644 --- a/src/Workspaces/CoreTest/CodeCleanup/FixIncorrectTokenTests.cs +++ b/src/Workspaces/CoreTest/CodeCleanup/FixIncorrectTokenTests.cs @@ -4,6 +4,7 @@ #nullable disable +using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeCleanup; using Microsoft.CodeAnalysis.CodeCleanup.Providers; @@ -742,7 +743,7 @@ private static async Task VerifyAsync(string codeWithMarker, string expectedResu var document = CreateDocument(codeWithoutMarker, LanguageNames.VisualBasic); var codeCleanups = CodeCleaner.GetDefaultProviders(document).WhereAsArray(p => p.Name is PredefinedCodeCleanupProviderNames.FixIncorrectTokens or PredefinedCodeCleanupProviderNames.Format); - var cleanDocument = await CodeCleaner.CleanupAsync(document, textSpans[0], CodeCleanupOptions.GetDefault(document.Project.Services), codeCleanups); + var cleanDocument = await CodeCleaner.CleanupAsync(document, textSpans[0], await document.GetCodeCleanupOptionsAsync(CancellationToken.None), codeCleanups); Assert.Equal(expectedResult, (await cleanDocument.GetSyntaxRootAsync()).ToFullString()); } diff --git a/src/Workspaces/CoreTest/CodeCleanup/NormalizeModifiersOrOperatorsTests.cs b/src/Workspaces/CoreTest/CodeCleanup/NormalizeModifiersOrOperatorsTests.cs index 5327e19d4a3b2..3a173727b342e 100644 --- a/src/Workspaces/CoreTest/CodeCleanup/NormalizeModifiersOrOperatorsTests.cs +++ b/src/Workspaces/CoreTest/CodeCleanup/NormalizeModifiersOrOperatorsTests.cs @@ -4,6 +4,7 @@ #nullable disable +using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeCleanup; using Microsoft.CodeAnalysis.CodeCleanup.Providers; @@ -1018,7 +1019,7 @@ private static async Task VerifyAsync(string codeWithMarker, string expectedResu var document = CreateDocument(codeWithoutMarker, LanguageNames.VisualBasic); var codeCleanups = CodeCleaner.GetDefaultProviders(document).WhereAsArray(p => p.Name is PredefinedCodeCleanupProviderNames.NormalizeModifiersOrOperators or PredefinedCodeCleanupProviderNames.Format); - var cleanDocument = await CodeCleaner.CleanupAsync(document, textSpans[0], CodeCleanupOptions.GetDefault(document.Project.Services), codeCleanups); + var cleanDocument = await CodeCleaner.CleanupAsync(document, textSpans[0], await document.GetCodeCleanupOptionsAsync(CancellationToken.None), codeCleanups); Assert.Equal(expectedResult, (await cleanDocument.GetSyntaxRootAsync()).ToFullString()); } diff --git a/src/Workspaces/CoreTest/CodeCleanup/ReduceTokenTests.cs b/src/Workspaces/CoreTest/CodeCleanup/ReduceTokenTests.cs index e04395d1e8188..e7b0192c68c5e 100644 --- a/src/Workspaces/CoreTest/CodeCleanup/ReduceTokenTests.cs +++ b/src/Workspaces/CoreTest/CodeCleanup/ReduceTokenTests.cs @@ -2006,7 +2006,7 @@ private static async Task VerifyAsync(string codeWithMarker, string expectedResu var document = CreateDocument(codeWithoutMarker, LanguageNames.VisualBasic); var codeCleanups = CodeCleaner.GetDefaultProviders(document).WhereAsArray(p => p.Name is PredefinedCodeCleanupProviderNames.ReduceTokens or PredefinedCodeCleanupProviderNames.CaseCorrection or PredefinedCodeCleanupProviderNames.Format); - var cleanDocument = await CodeCleaner.CleanupAsync(document, textSpans[0], CodeCleanupOptions.GetDefault(document.Project.Services), codeCleanups); + var cleanDocument = await CodeCleaner.CleanupAsync(document, textSpans[0], await document.GetCodeCleanupOptionsAsync(CancellationToken.None), codeCleanups); AssertEx.EqualOrDiff(expectedResult, (await cleanDocument.GetSyntaxRootAsync()).ToFullString()); } diff --git a/src/Workspaces/CoreTest/CodeCleanup/RemoveUnnecessaryLineContinuationTests.cs b/src/Workspaces/CoreTest/CodeCleanup/RemoveUnnecessaryLineContinuationTests.cs index 4b5a2c31e6c13..2ba8121d55bfd 100644 --- a/src/Workspaces/CoreTest/CodeCleanup/RemoveUnnecessaryLineContinuationTests.cs +++ b/src/Workspaces/CoreTest/CodeCleanup/RemoveUnnecessaryLineContinuationTests.cs @@ -1441,7 +1441,7 @@ private static async Task VerifyAsync(string codeWithMarker, string expectedResu var document = CreateDocument(codeWithoutMarker, LanguageNames.VisualBasic, langVersion); var codeCleanups = CodeCleaner.GetDefaultProviders(document).WhereAsArray(p => p.Name is PredefinedCodeCleanupProviderNames.RemoveUnnecessaryLineContinuation or PredefinedCodeCleanupProviderNames.Format); - var cleanDocument = await CodeCleaner.CleanupAsync(document, textSpans[0], CodeCleanupOptions.GetDefault(document.Project.Services), codeCleanups); + var cleanDocument = await CodeCleaner.CleanupAsync(document, textSpans[0], await document.GetCodeCleanupOptionsAsync(CancellationToken.None), codeCleanups); var actualResult = (await cleanDocument.GetRequiredSyntaxRootAsync(CancellationToken.None)).ToFullString(); AssertEx.EqualOrDiff(expectedResult, actualResult); diff --git a/src/Workspaces/CoreTest/Remote/ServiceDescriptorTests.cs b/src/Workspaces/CoreTest/Remote/ServiceDescriptorTests.cs index f67ab44a54236..0e9c68fc1b5bb 100644 --- a/src/Workspaces/CoreTest/Remote/ServiceDescriptorTests.cs +++ b/src/Workspaces/CoreTest/Remote/ServiceDescriptorTests.cs @@ -231,11 +231,11 @@ public void OptionsAreMessagePackSerializable(string language) var options = new object[] { - SimplifierOptions.GetDefault(languageServices), - SyntaxFormattingOptions.GetDefault(languageServices), - CodeCleanupOptions.GetDefault(languageServices), - CodeGenerationOptions.GetDefault(languageServices), - IndentationOptions.GetDefault(languageServices), + SimplifierOptionsProviders.GetDefault(languageServices), + SyntaxFormattingOptionsProviders.GetDefault(languageServices), + CodeCleanupOptionsProviders.GetDefault(languageServices), + CodeGenerationOptionsProviders.GetDefault(languageServices), + IndentationOptionsProviders.GetDefault(languageServices), ExtractMethodGenerationOptions.GetDefault(languageServices), // some non-default values: From 3de525a7cf2de7b1ace8efcc471fc5bfcfe57640 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 12:01:40 -0700 Subject: [PATCH 10/26] More tests --- src/EditorFeatures/Test2/Expansion/AbstractExpansionTest.vb | 2 +- .../CaseCorrecting/CaseCorrectionServiceTests.vb | 2 +- .../VisualBasicTest/ExtractMethod/ExtractMethodTests.vb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/EditorFeatures/Test2/Expansion/AbstractExpansionTest.vb b/src/EditorFeatures/Test2/Expansion/AbstractExpansionTest.vb index cdd0c8d1cb616..06d5470266b8f 100644 --- a/src/EditorFeatures/Test2/Expansion/AbstractExpansionTest.vb +++ b/src/EditorFeatures/Test2/Expansion/AbstractExpansionTest.vb @@ -30,7 +30,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Expansion Dim root = Await document.GetSyntaxRootAsync() - Dim cleanupOptions = CodeCleanupOptions.GetDefault(document.Project.Services) + Dim cleanupOptions = Await document.getcodecleanupoptionsasync(CancellationToken.None) Dim spans As ImmutableArray(Of TextSpan) = Nothing If hostDocument.AnnotatedSpans.TryGetValue("Expand", spans) Then diff --git a/src/EditorFeatures/VisualBasicTest/CaseCorrecting/CaseCorrectionServiceTests.vb b/src/EditorFeatures/VisualBasicTest/CaseCorrecting/CaseCorrectionServiceTests.vb index da3fe27a072e4..eaca1431049d9 100644 --- a/src/EditorFeatures/VisualBasicTest/CaseCorrecting/CaseCorrectionServiceTests.vb +++ b/src/EditorFeatures/VisualBasicTest/CaseCorrecting/CaseCorrectionServiceTests.vb @@ -34,7 +34,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.CaseCorrecting Dim document = workspace.CurrentSolution.GetDocument(hostDocument.Id) Dim span = (Await document.GetSyntaxRootAsync()).FullSpan - Dim options = CodeCleanupOptions.GetDefault(document.Project.Services) + Dim options = Await document.GetCodeCleanupOptionsAsync(CancellationToken.None) Dim service = document.GetLanguageService(Of ICodeCleanerService) Dim newDocument = Await service.CleanupAsync( diff --git a/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.vb b/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.vb index ef0e156145c7a..42c362459f93d 100644 --- a/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.vb +++ b/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.vb @@ -106,8 +106,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ExtractMethod ' extract method Dim extractGenerationOptions = VBOptionsFactory.CreateExtractMethodGenerationOptions( - CodeGenerationOptions.GetDefault(document.Project.Services), - CodeCleanupOptions.GetDefault(document.Project.Services)) + CodeGenerationOptionsProviders.GetDefault(document.Project.Services), + CodeCleanupOptionsProviders.GetDefault(document.Project.Services)) Dim extractor = New VisualBasicMethodExtractor(selectedCode, extractGenerationOptions) Dim result = extractor.ExtractMethod(status, CancellationToken.None) From 5549b10ce822df740445aa6cb030f7a595234cf8 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 12:02:25 -0700 Subject: [PATCH 11/26] More tests --- .../CSharpTest/ExtractMethod/ExtractMethodBase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs b/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs index c370c7cf0e1e5..01ff3aaa94105 100644 --- a/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs +++ b/src/EditorFeatures/CSharpTest/ExtractMethod/ExtractMethodBase.cs @@ -120,8 +120,8 @@ protected static async Task ExtractMethodAsync( var options = new ExtractMethodGenerationOptions() { - CodeGenerationOptions = CodeGenerationOptions.GetDefault(document.Project.Services), - CodeCleanupOptions = CodeCleanupOptions.GetDefault(document.Project.Services), + CodeGenerationOptions = CodeGenerationOptionsProviders.GetDefault(document.Project.Services), + CodeCleanupOptions = await document.GetCodeCleanupOptionsAsync(CancellationToken.None), }; var semanticDocument = await SemanticDocument.CreateAsync(document, CancellationToken.None); From d385a5ff8880ffc01d3ec27e623eb360637d1565 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 12:11:28 -0700 Subject: [PATCH 12/26] More tests --- src/EditorFeatures/Test2/Expansion/AbstractExpansionTest.vb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/EditorFeatures/Test2/Expansion/AbstractExpansionTest.vb b/src/EditorFeatures/Test2/Expansion/AbstractExpansionTest.vb index 06d5470266b8f..dbd1782c5984a 100644 --- a/src/EditorFeatures/Test2/Expansion/AbstractExpansionTest.vb +++ b/src/EditorFeatures/Test2/Expansion/AbstractExpansionTest.vb @@ -5,10 +5,8 @@ Imports System.Collections.Immutable Imports System.Threading Imports Microsoft.CodeAnalysis -Imports Microsoft.CodeAnalysis.CodeActions Imports Microsoft.CodeAnalysis.CodeCleanup Imports Microsoft.CodeAnalysis.Editor.UnitTests.Extensions -Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces Imports Microsoft.CodeAnalysis.Formatting Imports Microsoft.CodeAnalysis.Simplification Imports Microsoft.CodeAnalysis.Text @@ -30,7 +28,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Expansion Dim root = Await document.GetSyntaxRootAsync() - Dim cleanupOptions = Await document.getcodecleanupoptionsasync(CancellationToken.None) + Dim cleanupOptions = Await document.GetCodeCleanupOptionsAsync(CancellationToken.None) Dim spans As ImmutableArray(Of TextSpan) = Nothing If hostDocument.AnnotatedSpans.TryGetValue("Expand", spans) Then From 7a4dacbb138466c0dba79f8e3971f84fefa6da1c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 12:13:26 -0700 Subject: [PATCH 13/26] More tests --- .../VisualBasicTest/ExtractMethod/ExtractMethodTests.vb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.vb b/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.vb index 42c362459f93d..99ff3e546669a 100644 --- a/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.vb +++ b/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.vb @@ -106,8 +106,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ExtractMethod ' extract method Dim extractGenerationOptions = VBOptionsFactory.CreateExtractMethodGenerationOptions( - CodeGenerationOptionsProviders.GetDefault(document.Project.Services), - CodeCleanupOptionsProviders.GetDefault(document.Project.Services)) + Await document.GetCodeGenerationOptionsAsync(CancellationToken.None), + Await document.GetCodeCleanupOptionsAsync(CancellationToken.None)) Dim extractor = New VisualBasicMethodExtractor(selectedCode, extractGenerationOptions) Dim result = extractor.ExtractMethod(status, CancellationToken.None) From e9a4f91950b8b3875ed5cb34bd9fc2f1597c6ec4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 12:23:59 -0700 Subject: [PATCH 14/26] Fix tests --- .../CoreTest/CodeCleanup/CodeCleanupTests.cs | 58 +++++++++---------- .../CodeCleanup/MockCodeCleanupProvider.cs | 12 ++-- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/Workspaces/CoreTest/CodeCleanup/CodeCleanupTests.cs b/src/Workspaces/CoreTest/CodeCleanup/CodeCleanupTests.cs index bd2ddbcd1a73b..86cb826d12a01 100644 --- a/src/Workspaces/CoreTest/CodeCleanup/CodeCleanupTests.cs +++ b/src/Workspaces/CoreTest/CodeCleanup/CodeCleanupTests.cs @@ -169,87 +169,83 @@ public Task EntireRange_EndOfFile() [Fact] public async Task EntireRangeWithTransformation_RemoveClass() { - var expectedResult = (IEnumerable)null; var transformer = new MockCodeCleanupProvider() { - CleanupDocumentAsyncImpl = async (document, spans, options, cancellationToken) => + CleanupDocumentAsyncImpl = async (provider, document, spans, options, cancellationToken) => { var root = await document.GetSyntaxRootAsync(cancellationToken); root = root.RemoveCSharpMember(0); - expectedResult = [root.FullSpan]; + provider.ExpectedResult = [root.FullSpan]; return document.WithSyntaxRoot(root); } }; - await VerifyRange("{|b:class C {}|}", transformer, expectedResult); + await VerifyRange("{|b:class C {}|}", transformer); } [Fact] public async Task EntireRangeWithTransformation_AddMember() { - var expectedResult = (IEnumerable)null; var transformer = new MockCodeCleanupProvider() { - CleanupDocumentAsyncImpl = async (document, spans, options, cancellationToken) => + CleanupDocumentAsyncImpl = async (provider, document, spans, options, cancellationToken) => { var root = await document.GetSyntaxRootAsync(cancellationToken); var @class = root.GetMember(0); var classWithMember = @class.AddCSharpMember(CreateCSharpMethod(), 0); root = root.ReplaceNode(@class, classWithMember); - expectedResult = [root.FullSpan]; + provider.ExpectedResult = [root.FullSpan]; return document.WithSyntaxRoot(root); } }; - await VerifyRange("{|b:class C {}|}", transformer, expectedResult); + await VerifyRange("{|b:class C {}|}", transformer); } [Fact] public async Task RangeWithTransformation_AddMember() { - var expectedResult = (IEnumerable)null; var transformer = new MockCodeCleanupProvider() { - CleanupDocumentAsyncImpl = async (document, spans, options, cancellationToken) => + CleanupDocumentAsyncImpl = async (provider, document, spans, options, cancellationToken) => { var root = await document.GetSyntaxRootAsync(cancellationToken); var @class = root.GetMember(0).GetMember(0); var classWithMember = @class.AddCSharpMember(CreateCSharpMethod(), 0); root = root.ReplaceNode(@class, classWithMember); - expectedResult = [root.GetMember(0).GetMember(0).GetCodeCleanupSpan()]; + provider.ExpectedResult = [root.GetMember(0).GetMember(0).GetCodeCleanupSpan()]; return document.WithSyntaxRoot(root); } }; - await VerifyRange("namespace N { {|b:class C {}|} }", transformer, expectedResult); + await VerifyRange("namespace N { {|b:class C {}|} }", transformer); } [Fact] public async Task RangeWithTransformation_RemoveMember() { - var expectedResult = (IEnumerable)null; var transformer = new MockCodeCleanupProvider() { - CleanupDocumentAsyncImpl = async (document, spans, options, cancellationToken) => + CleanupDocumentAsyncImpl = async (provider, document, spans, options, cancellationToken) => { var root = await document.GetSyntaxRootAsync(cancellationToken); var @class = root.GetMember(0).GetMember(0); var classWithMember = @class.RemoveCSharpMember(0); root = root.ReplaceNode(@class, classWithMember); - expectedResult = [root.GetMember(0).GetMember(0).GetCodeCleanupSpan()]; + provider.ExpectedResult = [root.GetMember(0).GetMember(0).GetCodeCleanupSpan()]; return document.WithSyntaxRoot(root); } }; - await VerifyRange("namespace N { {|b:class C { void Method() { } }|} }", transformer, expectedResult); + await VerifyRange("namespace N { {|b:class C { void Method() { } }|} }", transformer); } [Fact] @@ -345,10 +341,9 @@ End Sub [Fact] public async Task RangeWithTransformation_OutsideOfRange() { - var expectedResult = (IEnumerable)null; var transformer = new MockCodeCleanupProvider() { - CleanupDocumentAsyncImpl = async (document, spans, options, cancellationToken) => + CleanupDocumentAsyncImpl = async (provider, document, spans, options, cancellationToken) => { var root = await document.GetSyntaxRootAsync(cancellationToken); var member = root.GetMember(0).GetMember(0).GetMember(0); @@ -358,13 +353,13 @@ public async Task RangeWithTransformation_OutsideOfRange() root = root.ReplaceToken(previousToken, CSharp.SyntaxFactory.Identifier(previousToken.LeadingTrivia, previousToken.ValueText, previousToken.TrailingTrivia)); root = root.ReplaceToken(nextToken, CSharp.SyntaxFactory.Token(nextToken.LeadingTrivia, CSharp.CSharpExtensions.Kind(nextToken), nextToken.TrailingTrivia)); - expectedResult = []; + provider.ExpectedResult = []; return document.WithSyntaxRoot(root); } }; - await VerifyRange("namespace N { class C { {|b:void Method() { }|} } }", transformer, expectedResult); + await VerifyRange("namespace N { class C { {|b:void Method() { }|} } }", transformer); } public static CSharp.Syntax.MethodDeclarationSyntax CreateCSharpMethod(string returnType = "void", string methodName = "Method") @@ -377,35 +372,38 @@ private static async Task VerifyRange(string codeWithMarker, string language = L var expectedResult = namedSpans.TryGetValue("r", out var spans) ? spans : SpecializedCollections.EmptyEnumerable(); - await VerifyRange(codeWithoutMarker, [], namedSpans["b"], expectedResult, language); + var transformer = new MockCodeCleanupProvider { ExpectedResult = expectedResult }; + + await VerifyRange(codeWithoutMarker, [], namedSpans["b"], transformer, language); } - private static async Task VerifyRange(string codeWithMarker, ICodeCleanupProvider transformer, IEnumerable expectedResult, string language = LanguageNames.CSharp) + private static async Task VerifyRange(string codeWithMarker, MockCodeCleanupProvider transformer, string language = LanguageNames.CSharp) { MarkupTestFile.GetSpans(codeWithMarker, out var codeWithoutMarker, out IDictionary> namedSpans); - await VerifyRange(codeWithoutMarker, [transformer], namedSpans["b"], expectedResult, language); + await VerifyRange(codeWithoutMarker, [transformer], namedSpans["b"], transformer, language); } - private static async Task VerifyRange(string code, ImmutableArray codeCleanups, ImmutableArray spans, IEnumerable expectedResult, string language) + private static async Task VerifyRange(string code, ImmutableArray codeCleanups, ImmutableArray spans, MockCodeCleanupProvider transformer, string language) { - var result = (IEnumerable)null; var spanCodeCleanup = new MockCodeCleanupProvider() { - CleanupDocumentAsyncImpl = (document, spans, options, cancellationToken) => + CleanupDocumentAsyncImpl = (provider, document, spans, options, cancellationToken) => { - result = spans; + provider.ExpectedResult = spans; return Task.FromResult(document); } }; var document = CreateDocument(code, language); - CodeCleaner.CleanupAsync(document, spans, await document.GetCodeCleanupOptionsAsync(CancellationToken.None), codeCleanups.Concat(spanCodeCleanup)).Wait(); + await CodeCleaner.CleanupAsync(document, spans, + await document.GetCodeCleanupOptionsAsync(CancellationToken.None), + codeCleanups.Concat(spanCodeCleanup)); - var sortedSpans = result.ToList(); - var expectedSpans = expectedResult.ToList(); + var sortedSpans = spanCodeCleanup.ExpectedResult.ToList(); + var expectedSpans = transformer.ExpectedResult.ToList(); sortedSpans.Sort(); expectedSpans.Sort(); diff --git a/src/Workspaces/CoreTest/CodeCleanup/MockCodeCleanupProvider.cs b/src/Workspaces/CoreTest/CodeCleanup/MockCodeCleanupProvider.cs index 7c4357021d287..4984445d61f22 100644 --- a/src/Workspaces/CoreTest/CodeCleanup/MockCodeCleanupProvider.cs +++ b/src/Workspaces/CoreTest/CodeCleanup/MockCodeCleanupProvider.cs @@ -3,6 +3,8 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections; +using System.Collections.Generic; using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; @@ -16,17 +18,15 @@ namespace Microsoft.CodeAnalysis.UnitTests.CodeCleanup { internal sealed class MockCodeCleanupProvider : ICodeCleanupProvider { - public Func, SyntaxFormattingOptions, CancellationToken, Task>? CleanupDocumentAsyncImpl { get; set; } - public Func, SyntaxFormattingOptions, SolutionServices, SyntaxNode>? CleanupNodeImpl { get; set; } + public IEnumerable ExpectedResult = null!; - public MockCodeCleanupProvider() - { - } + public Func, SyntaxFormattingOptions, CancellationToken, Task>? CleanupDocumentAsyncImpl { get; set; } + public Func, SyntaxFormattingOptions, SolutionServices, SyntaxNode>? CleanupNodeImpl { get; set; } public string Name => nameof(MockCodeCleanupProvider); public Task CleanupAsync(Document document, ImmutableArray spans, CodeCleanupOptions options, CancellationToken cancellationToken) - => (CleanupDocumentAsyncImpl ?? throw new NotImplementedException()).Invoke(document, spans, options.FormattingOptions, cancellationToken); + => (CleanupDocumentAsyncImpl ?? throw new NotImplementedException()).Invoke(this, document, spans, options.FormattingOptions, cancellationToken); public Task CleanupAsync(SyntaxNode root, ImmutableArray spans, SyntaxFormattingOptions options, SolutionServices services, CancellationToken cancellationToken) => Task.FromResult((CleanupNodeImpl ?? throw new NotImplementedException()).Invoke(root, spans, options, services)); From c5d6d27da0fbedd9383dab90eb4464080631b59a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 12:40:59 -0700 Subject: [PATCH 15/26] building --- .../Formatting/DocumentFormattingOptions.cs | 18 ------------- .../DocumentFormattingOptionsProviders.cs | 27 +++++++++++++++++++ .../Core/WorkspaceExtensions.projitems | 1 + 3 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Formatting/DocumentFormattingOptionsProviders.cs diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/DocumentFormattingOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/DocumentFormattingOptions.cs index 6495f54bcdacb..8480f2cd540d2 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/DocumentFormattingOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/DocumentFormattingOptions.cs @@ -18,21 +18,3 @@ internal sealed record class DocumentFormattingOptions [DataMember] public string FileHeaderTemplate { get; init; } = ""; [DataMember] public bool InsertFinalNewLine { get; init; } = false; } - -internal static class DocumentFormattingOptionsProviders -{ - public static DocumentFormattingOptions GetDocumentFormattingOptions(this IOptionsReader options) - => new() - { - FileHeaderTemplate = options.GetOption(CodeStyleOptions2.FileHeaderTemplate), - InsertFinalNewLine = options.GetOption(FormattingOptions2.InsertFinalNewLine) - }; - -#if !CODE_STYLE - public static async ValueTask GetDocumentFormattingOptionsAsync(this Document document, CancellationToken cancellationToken) - { - var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); - return configOptions.GetDocumentFormattingOptions(); - } -#endif -} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Formatting/DocumentFormattingOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Formatting/DocumentFormattingOptionsProviders.cs new file mode 100644 index 0000000000000..b3c9b701e2228 --- /dev/null +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Formatting/DocumentFormattingOptionsProviders.cs @@ -0,0 +1,27 @@ +// 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.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.CodeStyle; +using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.Shared.Extensions; + +namespace Microsoft.CodeAnalysis.Formatting; + +internal static class DocumentFormattingOptionsProviders +{ + public static DocumentFormattingOptions GetDocumentFormattingOptions(this IOptionsReader options) + => new() + { + FileHeaderTemplate = options.GetOption(CodeStyleOptions2.FileHeaderTemplate), + InsertFinalNewLine = options.GetOption(FormattingOptions2.InsertFinalNewLine) + }; + + public static async ValueTask GetDocumentFormattingOptionsAsync(this Document document, CancellationToken cancellationToken) + { + var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); + return configOptions.GetDocumentFormattingOptions(); + } +} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems index 575b74a52ecc6..17723094b7ccb 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems @@ -21,6 +21,7 @@ + From efe946f599a5c31fe9730c6cc6d21d69fb9b3942 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 12:42:09 -0700 Subject: [PATCH 16/26] share code --- .../Core/CodeCleanup/CodeCleanupOptionsProviders.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs index 66a8d1c5aa85e..babba8c1cefbc 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs @@ -24,16 +24,10 @@ public static CodeCleanupOptions GetCodeCleanupOptions(this IOptionsReader optio DocumentFormattingOptions = options.GetDocumentFormattingOptions(), }; -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public static async ValueTask GetCodeCleanupOptionsAsync(this Document document, CancellationToken cancellationToken) -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { -#if CODE_STYLE - return GetDefault(document.Project.GetExtendedLanguageServices().LanguageServices); -#else var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); - return configOptions.GetCodeCleanupOptions(document.Project.Services, document.AllowImportsInHiddenRegions()); -#endif + return configOptions.GetCodeCleanupOptions(document.Project.GetExtendedLanguageServices().LanguageServices, document.AllowImportsInHiddenRegions()); } public static CodeCleanupOptions GetDefault(LanguageServices languageServices) From 02b9a11f3460f3ee147d2d76dd2874e515460f53 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 12:43:37 -0700 Subject: [PATCH 17/26] Remoive --- .../Compiler/Core/Services/SyntaxFacts/ISyntaxFacts.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SyntaxFacts/ISyntaxFacts.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SyntaxFacts/ISyntaxFacts.cs index 074aa4e482618..6bd812470edbe 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SyntaxFacts/ISyntaxFacts.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SyntaxFacts/ISyntaxFacts.cs @@ -8,12 +8,6 @@ using System.Threading; using Microsoft.CodeAnalysis.Text; -#if CODE_STYLE -using Microsoft.CodeAnalysis.Internal.Editing; -#else -using Microsoft.CodeAnalysis.Editing; -#endif - namespace Microsoft.CodeAnalysis.LanguageService; /// From 8f1bbea60f46f07ca7fb24307df21626d5af4d4e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 12:44:15 -0700 Subject: [PATCH 18/26] Remoive --- .../Compiler/Core/Utilities/IReferenceCountedDisposable.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/IReferenceCountedDisposable.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/IReferenceCountedDisposable.cs index f751e0c8898e1..e8805de937baa 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/IReferenceCountedDisposable.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/IReferenceCountedDisposable.cs @@ -12,10 +12,7 @@ namespace Roslyn.Utilities; /// disposing directly. /// /// -internal interface IReferenceCountedDisposable : IDisposable -#if !CODE_STYLE - , IAsyncDisposable -#endif +internal interface IReferenceCountedDisposable : IDisposable, IAsyncDisposable where T : class { /// From 743d0ce7e5f3f4efbabee7fada281e7bda32fcc2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 12:44:31 -0700 Subject: [PATCH 19/26] Remoive --- .../Compiler/Core/Utilities/ReferenceCountedDisposable.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/ReferenceCountedDisposable.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/ReferenceCountedDisposable.cs index 6d636c7529e52..11eaafe676ce9 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/ReferenceCountedDisposable.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/ReferenceCountedDisposable.cs @@ -186,10 +186,8 @@ public ValueTask DisposeAsync() if (instanceToDispose == null) return ValueTaskFactory.CompletedTask; -#if !CODE_STYLE if (instanceToDispose is IAsyncDisposable asyncDisposable) return asyncDisposable.DisposeAsync(); -#endif instanceToDispose.Dispose(); return ValueTaskFactory.CompletedTask; From 20e8927b3b06438faaba069589b6a142d0b5d854 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 12:44:50 -0700 Subject: [PATCH 20/26] Remoive --- .../Compiler/CSharp/Formatting/CSharpFormattingOptions2.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/CSharpFormattingOptions2.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/CSharpFormattingOptions2.cs index 66e973d451995..62669e9750b21 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/CSharpFormattingOptions2.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/CSharpFormattingOptions2.cs @@ -3,14 +3,12 @@ // See the LICENSE file in the project root for more information. using System.Collections.Immutable; -using System.Diagnostics; using Roslyn.Utilities; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Formatting; #if CODE_STYLE using CSharpWorkspaceResources = Microsoft.CodeAnalysis.CSharp.CSharpCodeStyleResources; -using WorkspacesResources = Microsoft.CodeAnalysis.CodeStyleResources; #endif namespace Microsoft.CodeAnalysis.CSharp.Formatting; From 2dee1815c48e377c08e354a9cbf9a1527ee27daa Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 12:45:37 -0700 Subject: [PATCH 21/26] Remoive --- .../CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs index 081625a453edf..cebd1153d3b37 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs @@ -19,12 +19,6 @@ using Roslyn.Utilities; using Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery; -#if CODE_STYLE -using Microsoft.CodeAnalysis.Internal.Editing; -#else -using Microsoft.CodeAnalysis.Editing; -#endif - namespace Microsoft.CodeAnalysis.CSharp.LanguageService; internal class CSharpSyntaxFacts : ISyntaxFacts From 8f32abb0c82085c08dd5195461b406d9cfcac666 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 12:46:57 -0700 Subject: [PATCH 22/26] Remoive --- .../Workspace/Core/CodeGeneration/CodeGenerator.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerator.cs index ff18482a5f37d..312998cb290d1 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerator.cs @@ -21,11 +21,7 @@ internal static class CodeGenerator public static readonly SyntaxAnnotation Annotation = new(nameof(CodeGenerator)); private static ICodeGenerationService GetCodeGenerationService(HostWorkspaceServices services, string language) -#if CODE_STYLE => services.GetExtendedLanguageServices(language).GetRequiredService(); -#else - => services.GetLanguageServices(language).GetRequiredService(); -#endif /// /// Create a new solution where the declaration of the destination symbol has an additional event of the same signature as the specified event symbol. From 080e2173a47c61765256490f82e3556518934a8b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 12:50:36 -0700 Subject: [PATCH 23/26] Remoive --- .../Workspace/Core/Extensions/ProjectExtensions.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ProjectExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ProjectExtensions.cs index 2c00001dec6de..b2521e3b2eaba 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ProjectExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ProjectExtensions.cs @@ -34,11 +34,8 @@ public static TLanguageService GetRequiredLanguageService(this /// Gets extended host language services, which includes language services from . /// public static HostLanguageServices GetExtendedLanguageServices(this Project project) -#if CODE_STYLE => project.Solution.Workspace.Services.GetExtendedLanguageServices(project.Language); -#else - => project.Solution.Services.GetExtendedLanguageServices(project.Language); -#endif + #pragma warning restore RS0030 // Do not used banned APIs public static string? TryGetAnalyzerConfigPathForProjectConfiguration(this Project project) From cd81fe77e23cdb47849059152bb869c559ac96a1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 13:03:09 -0700 Subject: [PATCH 24/26] Update src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems --- .../Workspace/Core/WorkspaceExtensions.projitems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems index 17723094b7ccb..32a4686da39e5 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems @@ -23,7 +23,7 @@ - + From 6e25f3898d54aeb87676b7b5e0105cb9125df35f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 15:09:42 -0700 Subject: [PATCH 25/26] ublblock --- .../Core/CodeCleanup/CodeCleanupOptionsProviders.cs | 6 +++++- .../Core/CodeGeneration/CodeGenerationOptionsProviders.cs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs index babba8c1cefbc..618e5f8e44866 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs @@ -27,7 +27,11 @@ public static CodeCleanupOptions GetCodeCleanupOptions(this IOptionsReader optio public static async ValueTask GetCodeCleanupOptionsAsync(this Document document, CancellationToken cancellationToken) { var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); - return configOptions.GetCodeCleanupOptions(document.Project.GetExtendedLanguageServices().LanguageServices, document.AllowImportsInHiddenRegions()); +#pragma warning disable CS0618 // Type or member is obsolete +#pragma warning disable RS0030 // Do not use banned APIs + return configOptions.GetCodeCleanupOptions(document.Project.LanguageServices.LanguageServices, document.AllowImportsInHiddenRegions()); +#pragma warning restore RS0030 // Do not use banned APIs +#pragma warning restore CS0618 // Type or member is obsolete } public static CodeCleanupOptions GetDefault(LanguageServices languageServices) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProviders.cs index c305e949c7a4e..9d029ddbffaf5 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProviders.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProviders.cs @@ -35,7 +35,11 @@ public static CleanCodeGenerationOptions GetCleanCodeGenerationOptions(this IOpt public static async ValueTask GetCodeGenerationOptionsAsync(this Document document, CancellationToken cancellationToken) { var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); - return configOptions.GetCodeGenerationOptions(document.Project.GetExtendedLanguageServices().LanguageServices); +#pragma warning disable CS0618 // Type or member is obsolete +#pragma warning disable RS0030 // Do not use banned APIs + return configOptions.GetCodeGenerationOptions(document.Project.LanguageServices.LanguageServices); +#pragma warning restore RS0030 // Do not use banned APIs +#pragma warning restore CS0618 // Type or member is obsolete } public static async ValueTask GetCodeGenerationInfoAsync(this Document document, CodeGenerationContext context, CancellationToken cancellationToken) From 8e763eb901034171281c46f40e5b4804b2aeaadb Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 30 Aug 2024 20:15:33 -0700 Subject: [PATCH 26/26] Fix --- .../Core/CodeCleanup/CodeCleanupOptionsProviders.cs | 6 +----- .../Core/CodeGeneration/CodeGenerationOptionsProviders.cs | 6 +----- .../Workspace/Core/Extensions/ProjectExtensions.cs | 4 ++++ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs index 618e5f8e44866..babba8c1cefbc 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs @@ -27,11 +27,7 @@ public static CodeCleanupOptions GetCodeCleanupOptions(this IOptionsReader optio public static async ValueTask GetCodeCleanupOptionsAsync(this Document document, CancellationToken cancellationToken) { var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); -#pragma warning disable CS0618 // Type or member is obsolete -#pragma warning disable RS0030 // Do not use banned APIs - return configOptions.GetCodeCleanupOptions(document.Project.LanguageServices.LanguageServices, document.AllowImportsInHiddenRegions()); -#pragma warning restore RS0030 // Do not use banned APIs -#pragma warning restore CS0618 // Type or member is obsolete + return configOptions.GetCodeCleanupOptions(document.Project.GetExtendedLanguageServices().LanguageServices, document.AllowImportsInHiddenRegions()); } public static CodeCleanupOptions GetDefault(LanguageServices languageServices) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProviders.cs index 9d029ddbffaf5..c305e949c7a4e 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProviders.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProviders.cs @@ -35,11 +35,7 @@ public static CleanCodeGenerationOptions GetCleanCodeGenerationOptions(this IOpt public static async ValueTask GetCodeGenerationOptionsAsync(this Document document, CancellationToken cancellationToken) { var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); -#pragma warning disable CS0618 // Type or member is obsolete -#pragma warning disable RS0030 // Do not use banned APIs - return configOptions.GetCodeGenerationOptions(document.Project.LanguageServices.LanguageServices); -#pragma warning restore RS0030 // Do not use banned APIs -#pragma warning restore CS0618 // Type or member is obsolete + return configOptions.GetCodeGenerationOptions(document.Project.GetExtendedLanguageServices().LanguageServices); } public static async ValueTask GetCodeGenerationInfoAsync(this Document document, CodeGenerationContext context, CancellationToken cancellationToken) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ProjectExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ProjectExtensions.cs index b2521e3b2eaba..13a9669003389 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ProjectExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ProjectExtensions.cs @@ -34,7 +34,11 @@ public static TLanguageService GetRequiredLanguageService(this /// Gets extended host language services, which includes language services from . /// public static HostLanguageServices GetExtendedLanguageServices(this Project project) +#if CODE_STYLE => project.Solution.Workspace.Services.GetExtendedLanguageServices(project.Language); +#else + => project.Solution.Services.GetExtendedLanguageServices(project.Language); +#endif #pragma warning restore RS0030 // Do not used banned APIs