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/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); diff --git a/src/EditorFeatures/Test2/Expansion/AbstractExpansionTest.vb b/src/EditorFeatures/Test2/Expansion/AbstractExpansionTest.vb index cdd0c8d1cb616..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 = 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/TestUtilities/Formatting/AbstractNewDocumentFormattingServiceTests.cs b/src/EditorFeatures/TestUtilities/Formatting/AbstractNewDocumentFormattingServiceTests.cs index 441ac828ce5b6..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) ?? - CodeCleanupOptions.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/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..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( - CodeGenerationOptions.GetDefault(document.Project.Services), - CodeCleanupOptions.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) 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); } 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/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/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/CodeCleanupTests.cs b/src/Workspaces/CoreTest/CodeCleanup/CodeCleanupTests.cs index baf2a8c27fce4..86cb826d12a01 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,117 +155,113 @@ 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() { - 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); } }; - VerifyRange("{|b:class C {}|}", transformer, ref expectedResult); + await VerifyRange("{|b:class C {}|}", transformer); } [Fact] - public void EntireRangeWithTransformation_AddMember() + 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); } }; - VerifyRange("{|b:class C {}|}", transformer, ref expectedResult); + await VerifyRange("{|b:class C {}|}", transformer); } [Fact] - public void RangeWithTransformation_AddMember() + 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); } }; - VerifyRange("namespace N { {|b:class C {}|} }", transformer, ref expectedResult); + await VerifyRange("namespace N { {|b:class C {}|} }", transformer); } [Fact] - public void RangeWithTransformation_RemoveMember() + 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); } }; - VerifyRange("namespace N { {|b:class C { void Method() { } }|} }", transformer, ref expectedResult); + await VerifyRange("namespace N { {|b:class C { void Method() { } }|} }", transformer); } [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 +277,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 +314,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,16 +335,15 @@ 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() { - 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,54 +353,57 @@ public void 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); } }; - VerifyRange("namespace N { class C { {|b:void Method() { }|} } }", transformer, ref expectedResult); + await VerifyRange("namespace N { class C { {|b:void Method() { }|} } }", transformer); } 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); + var transformer = new MockCodeCleanupProvider { ExpectedResult = expectedResult }; + + await VerifyRange(codeWithoutMarker, [], namedSpans["b"], transformer, language); } - private static void VerifyRange(string codeWithMarker, ICodeCleanupProvider transformer, ref 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); - VerifyRange(codeWithoutMarker, [transformer], namedSpans["b"], ref expectedResult, language); + await VerifyRange(codeWithoutMarker, [transformer], namedSpans["b"], transformer, 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, 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, CodeCleanupOptions.GetDefault(document.Project.Services), 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/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/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)); 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: 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/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; 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 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..243677ebb6796 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs @@ -2,19 +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.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; using Microsoft.CodeAnalysis.OrganizeImports; -#endif namespace Microsoft.CodeAnalysis.CodeCleanup; @@ -26,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() { @@ -41,5 +25,4 @@ public OrganizeImportsOptions GetOrganizeImportsOptions() PlaceSystemNamespaceFirst = AddImportOptions.PlaceSystemNamespaceFirst, NewLine = FormattingOptions.LineFormatting.NewLine, }; -#endif } 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/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs index b0738940b39aa..0061f26bf1b40 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs @@ -3,18 +3,10 @@ // 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.Diagnostics.Analyzers.NamingStyles; using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.CodeCleanup; - -#if !CODE_STYLE -using Microsoft.CodeAnalysis.Host; -#endif namespace Microsoft.CodeAnalysis.CodeGeneration; @@ -38,28 +30,4 @@ 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] -internal readonly record struct CodeAndImportGenerationOptions -{ - [DataMember] - public required CodeGenerationOptions GenerationOptions { get; init; } - - [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/Compiler/Core/CompilerExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems index 824a4a4616610..3c9d6c4f2a066 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems @@ -190,8 +190,8 @@ InternalUtilities\UnicodeCharacterUtilities.cs + - @@ -281,6 +281,7 @@ + @@ -641,6 +642,7 @@ + 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/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/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; /// 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/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 { /// 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; diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs index 396b813e9f95c..babba8c1cefbc 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.Shared.Extensions; using Microsoft.CodeAnalysis.Simplification; namespace Microsoft.CodeAnalysis.CodeCleanup; @@ -23,12 +24,17 @@ public static CodeCleanupOptions GetCodeCleanupOptions(this IOptionsReader optio DocumentFormattingOptions = options.GetDocumentFormattingOptions(), }; -#if !CODE_STYLE public static async ValueTask GetCodeCleanupOptionsAsync(this Document document, CancellationToken cancellationToken) { var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); - return configOptions.GetCodeCleanupOptions(document.Project.Services, document.AllowImportsInHiddenRegions()); + return configOptions.GetCodeCleanupOptions(document.Project.GetExtendedLanguageServices().LanguageServices, document.AllowImportsInHiddenRegions()); } -#endif + + public static CodeCleanupOptions GetDefault(LanguageServices languageServices) + => new() + { + FormattingOptions = SyntaxFormattingOptionsProviders.GetDefault(languageServices), + SimplifierOptions = SimplifierOptionsProviders.GetDefault(languageServices) + }; } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CleanCodeGenerationOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CleanCodeGenerationOptions.cs similarity index 83% rename from src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CleanCodeGenerationOptions.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CleanCodeGenerationOptions.cs index 1acef75129fa3..eba41e6db113d 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/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,26 +19,23 @@ internal readonly record struct CleanCodeGenerationOptions [DataMember] public required CodeCleanupOptions CleanupOptions { get; init; } -#if !CODE_STYLE - public static CleanCodeGenerationOptions GetDefault(LanguageServices languageServices) - => new() - { - GenerationOptions = CodeGenerationOptions.GetDefault(languageServices), - CleanupOptions = CodeCleanupOptions.GetDefault(languageServices) - }; - public CodeAndImportGenerationOptions CodeAndImportGenerationOptions => new() { GenerationOptions = GenerationOptions, AddImportOptions = CleanupOptions.AddImportOptions }; -#endif } -#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() { @@ -50,4 +43,3 @@ public static async ValueTask GetCleanCodeGeneration CleanupOptions = await document.GetCodeCleanupOptionsAsync(cancellationToken).ConfigureAwait(false) }; } -#endif 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 93% rename from src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProvider.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProviders.cs index 602a383f4e600..c305e949c7a4e 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProvider.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProviders.cs @@ -46,4 +46,7 @@ public static async ValueTask GetCodeGenerationInfoAs var service = document.GetRequiredLanguageService(); return service.GetInfo(context, options, document.Project.ParseOptions); } + + public static CodeGenerationOptions GetDefault(LanguageServices languageServices) + => languageServices.GetRequiredService().DefaultOptions; } 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. diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ProjectExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ProjectExtensions.cs index 2c00001dec6de..13a9669003389 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ProjectExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ProjectExtensions.cs @@ -39,6 +39,7 @@ public static HostLanguageServices GetExtendedLanguageServices(this Project proj #else => project.Solution.Services.GetExtendedLanguageServices(project.Language); #endif + #pragma warning restore RS0030 // Do not used banned APIs public static string? TryGetAnalyzerConfigPathForProjectConfiguration(this Project project) 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/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..32a4686da39e5 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems @@ -10,7 +10,9 @@ - + + + @@ -19,7 +21,9 @@ + +