diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs index 5c7de40348a80..8c4a9d8eb06fd 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs @@ -35,8 +35,8 @@ public CSharpRemoveUnusedValuesCodeFixProvider() } #if CODE_STYLE - protected override ISyntaxFormattingService GetSyntaxFormattingService() - => CSharpSyntaxFormattingService.Instance; + protected override ISyntaxFormatting GetSyntaxFormatting() + => CSharpSyntaxFormatting.Instance; #endif protected override BlockSyntax WrapWithBlockIfNecessary(IEnumerable statements) diff --git a/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForAssignmentCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForAssignmentCodeFixProvider.cs index 0c478bdb97205..c1b7f821b23f8 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForAssignmentCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForAssignmentCodeFixProvider.cs @@ -66,8 +66,8 @@ protected override ExpressionSyntax ConvertToExpression(IThrowOperation throwOpe => CSharpUseConditionalExpressionHelpers.ConvertToExpression(throwOperation); #if CODE_STYLE - protected override ISyntaxFormattingService GetSyntaxFormattingService() - => CSharpSyntaxFormattingService.Instance; + protected override ISyntaxFormatting GetSyntaxFormatting() + => CSharpSyntaxFormatting.Instance; #endif } } diff --git a/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForReturnCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForReturnCodeFixProvider.cs index 68069c4736e75..ccc2af8af9862 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForReturnCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForReturnCodeFixProvider.cs @@ -52,8 +52,8 @@ protected override ExpressionSyntax ConvertToExpression(IThrowOperation throwOpe => CSharpUseConditionalExpressionHelpers.ConvertToExpression(throwOperation); #if CODE_STYLE - protected override ISyntaxFormattingService GetSyntaxFormattingService() - => CSharpSyntaxFormattingService.Instance; + protected override ISyntaxFormatting GetSyntaxFormatting() + => CSharpSyntaxFormatting.Instance; #endif } } diff --git a/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs index adf04d8fc912a..5fb59a2c445c0 100644 --- a/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs @@ -67,7 +67,7 @@ public sealed override ImmutableArray FixableDiagnosticIds internal sealed override CodeFixCategory CodeFixCategory => CodeFixCategory.CodeQuality; #if CODE_STYLE - protected abstract ISyntaxFormattingService GetSyntaxFormattingService(); + protected abstract ISyntaxFormatting GetSyntaxFormatting(); #endif /// /// Method to update the identifier token for the local/parameter declaration or reference @@ -269,7 +269,7 @@ private static async Task PreprocessDocumentAsync(Document document, I protected sealed override async Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) { #if CODE_STYLE - var provider = GetSyntaxFormattingService(); + var provider = GetSyntaxFormatting(); var options = provider.GetFormattingOptions(document.Project.AnalyzerOptions.GetAnalyzerOptionSet(editor.OriginalRoot.SyntaxTree, cancellationToken)); #else var provider = document.Project.Solution.Workspace.Services; @@ -832,7 +832,7 @@ private async Task AdjustLocalDeclarationsAsync( // Run formatter prior to invoking IMoveDeclarationNearReferenceService. #if CODE_STYLE - var provider = GetSyntaxFormattingService(); + var provider = GetSyntaxFormatting(); rootWithTrackedNodes = FormatterHelper.Format(rootWithTrackedNodes, originalDeclStatementsToMoveOrRemove.Select(s => s.Span), provider, options, rules: null, cancellationToken); #else var provider = document.Project.Solution.Workspace.Services; diff --git a/src/Analyzers/Core/CodeFixes/UseConditionalExpression/AbstractUseConditionalExpressionCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseConditionalExpression/AbstractUseConditionalExpressionCodeFixProvider.cs index 30018fd0c3f3d..f986ec870e774 100644 --- a/src/Analyzers/Core/CodeFixes/UseConditionalExpression/AbstractUseConditionalExpressionCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseConditionalExpression/AbstractUseConditionalExpressionCodeFixProvider.cs @@ -41,7 +41,7 @@ internal abstract class AbstractUseConditionalExpressionCodeFixProvider< protected abstract AbstractFormattingRule GetMultiLineFormattingRule(); #if CODE_STYLE - protected abstract ISyntaxFormattingService GetSyntaxFormattingService(); + protected abstract ISyntaxFormatting GetSyntaxFormatting(); #endif protected abstract TExpressionSyntax ConvertToExpression(IThrowOperation throwOperation); @@ -77,7 +77,7 @@ await FixOneAsync( var rules = new List { GetMultiLineFormattingRule() }; #if CODE_STYLE - var provider = GetSyntaxFormattingService(); + var provider = GetSyntaxFormatting(); var options = provider.GetFormattingOptions(document.Project.AnalyzerOptions.GetAnalyzerOptionSet(root.SyntaxTree, cancellationToken)); #else var provider = document.Project.Solution.Workspace.Services; diff --git a/src/Analyzers/VisualBasic/CodeFixes/RemoveUnusedParametersAndValues/VisualBasicRemoveUnusedValuesCodeFixProvider.vb b/src/Analyzers/VisualBasic/CodeFixes/RemoveUnusedParametersAndValues/VisualBasicRemoveUnusedValuesCodeFixProvider.vb index a751f08efa9a1..e184ec00eb87b 100644 --- a/src/Analyzers/VisualBasic/CodeFixes/RemoveUnusedParametersAndValues/VisualBasicRemoveUnusedValuesCodeFixProvider.vb +++ b/src/Analyzers/VisualBasic/CodeFixes/RemoveUnusedParametersAndValues/VisualBasicRemoveUnusedValuesCodeFixProvider.vb @@ -26,8 +26,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnusedParametersAndValues End Sub #If CODE_STYLE Then - Protected Overrides Function GetSyntaxFormattingService() As ISyntaxFormattingService - Return VisualBasicSyntaxFormattingService.Instance + Protected Overrides Function GetSyntaxFormatting() As ISyntaxFormatting + Return VisualBasicSyntaxFormatting.Instance End Function #End If diff --git a/src/Analyzers/VisualBasic/CodeFixes/UseConditionalExpression/VisualBasicUseConditionalExpressionForAssignmentCodeFixProvider.vb b/src/Analyzers/VisualBasic/CodeFixes/UseConditionalExpression/VisualBasicUseConditionalExpressionForAssignmentCodeFixProvider.vb index 978af318745ca..5a92840da3542 100644 --- a/src/Analyzers/VisualBasic/CodeFixes/UseConditionalExpression/VisualBasicUseConditionalExpressionForAssignmentCodeFixProvider.vb +++ b/src/Analyzers/VisualBasic/CodeFixes/UseConditionalExpression/VisualBasicUseConditionalExpressionForAssignmentCodeFixProvider.vb @@ -60,8 +60,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UseConditionalExpression End Function #If CODE_STYLE Then - Protected Overrides Function GetSyntaxFormattingService() As ISyntaxFormattingService - Return VisualBasicSyntaxFormattingService.Instance + Protected Overrides Function GetSyntaxFormatting() As ISyntaxFormatting + Return VisualBasicSyntaxFormatting.Instance End Function #End If End Class diff --git a/src/Analyzers/VisualBasic/CodeFixes/UseConditionalExpression/VisualBasicUseConditionalExpressionForReturnCodeFixProvider.vb b/src/Analyzers/VisualBasic/CodeFixes/UseConditionalExpression/VisualBasicUseConditionalExpressionForReturnCodeFixProvider.vb index ead0c5dff0848..a546148b18c7f 100644 --- a/src/Analyzers/VisualBasic/CodeFixes/UseConditionalExpression/VisualBasicUseConditionalExpressionForReturnCodeFixProvider.vb +++ b/src/Analyzers/VisualBasic/CodeFixes/UseConditionalExpression/VisualBasicUseConditionalExpressionForReturnCodeFixProvider.vb @@ -44,8 +44,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UseConditionalExpression End Function #If CODE_STYLE Then - Protected Overrides Function GetSyntaxFormattingService() As ISyntaxFormattingService - Return VisualBasicSyntaxFormattingService.Instance + Protected Overrides Function GetSyntaxFormatting() As ISyntaxFormatting + Return VisualBasicSyntaxFormatting.Instance End Function #End If End Class diff --git a/src/CodeStyle/CSharp/Analyzers/CSharpFormattingAnalyzer.cs b/src/CodeStyle/CSharp/Analyzers/CSharpFormattingAnalyzer.cs index 4951f7e8f2335..3f31dd0f3a08f 100644 --- a/src/CodeStyle/CSharp/Analyzers/CSharpFormattingAnalyzer.cs +++ b/src/CodeStyle/CSharp/Analyzers/CSharpFormattingAnalyzer.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using Microsoft.CodeAnalysis.CSharp.Formatting; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Formatting; @@ -13,7 +11,7 @@ namespace Microsoft.CodeAnalysis.CodeStyle [DiagnosticAnalyzer(LanguageNames.CSharp)] internal class CSharpFormattingAnalyzer : AbstractFormattingAnalyzer { - protected override ISyntaxFormattingService SyntaxFormattingService - => CSharpSyntaxFormattingService.Instance; + protected override ISyntaxFormatting SyntaxFormatting + => CSharpSyntaxFormatting.Instance; } } diff --git a/src/CodeStyle/CSharp/CodeFixes/CSharpFormattingCodeFixProvider.cs b/src/CodeStyle/CSharp/CodeFixes/CSharpFormattingCodeFixProvider.cs index 482aa5cba637a..9476008efaaa6 100644 --- a/src/CodeStyle/CSharp/CodeFixes/CSharpFormattingCodeFixProvider.cs +++ b/src/CodeStyle/CSharp/CodeFixes/CSharpFormattingCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Composition; using Microsoft.CodeAnalysis.CodeFixes; @@ -13,8 +11,7 @@ namespace Microsoft.CodeAnalysis.CodeStyle { - [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.FixFormatting)] - [Shared] + [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.FixFormatting), Shared] internal class CSharpFormattingCodeFixProvider : AbstractFormattingCodeFixProvider { [ImportingConstructor] @@ -23,6 +20,6 @@ public CSharpFormattingCodeFixProvider() { } - protected override ISyntaxFormattingService SyntaxFormattingService => CSharpSyntaxFormattingService.Instance; + protected override ISyntaxFormatting SyntaxFormatting => CSharpSyntaxFormatting.Instance; } } diff --git a/src/CodeStyle/Core/Analyzers/AbstractFormattingAnalyzer.cs b/src/CodeStyle/Core/Analyzers/AbstractFormattingAnalyzer.cs index dbeaf6f74148b..a39030841d90e 100644 --- a/src/CodeStyle/Core/Analyzers/AbstractFormattingAnalyzer.cs +++ b/src/CodeStyle/Core/Analyzers/AbstractFormattingAnalyzer.cs @@ -27,15 +27,15 @@ public sealed override ImmutableArray SupportedDiagnostics public sealed override DiagnosticAnalyzerCategory GetAnalyzerCategory() => DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis; - protected abstract ISyntaxFormattingService SyntaxFormattingService { get; } + protected abstract ISyntaxFormatting SyntaxFormatting { get; } protected sealed override void InitializeWorker(AnalysisContext context) => context.RegisterSyntaxTreeAction(AnalyzeSyntaxTree); private void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context) { - var options = SyntaxFormattingService.GetFormattingOptions(context.Options.AnalyzerConfigOptionsProvider.GetOptions(context.Tree)); - FormattingAnalyzerHelper.AnalyzeSyntaxTree(context, SyntaxFormattingService, Descriptor, options); + var options = SyntaxFormatting.GetFormattingOptions(context.Options.AnalyzerConfigOptionsProvider.GetOptions(context.Tree)); + FormattingAnalyzerHelper.AnalyzeSyntaxTree(context, SyntaxFormatting, Descriptor, options); } } } diff --git a/src/CodeStyle/Core/Analyzers/Formatting/FormatterHelper.cs b/src/CodeStyle/Core/Analyzers/Formatting/FormatterHelper.cs index 54db1c6918b95..eb90f80e93436 100644 --- a/src/CodeStyle/Core/Analyzers/Formatting/FormatterHelper.cs +++ b/src/CodeStyle/Core/Analyzers/Formatting/FormatterHelper.cs @@ -19,7 +19,7 @@ internal static class FormatterHelper /// /// Gets the formatting rules that would be applied if left unspecified. /// - internal static IEnumerable GetDefaultFormattingRules(ISyntaxFormattingService syntaxFormattingService) + internal static IEnumerable GetDefaultFormattingRules(ISyntaxFormatting syntaxFormattingService) => syntaxFormattingService.GetDefaultFormattingRules(); /// @@ -29,10 +29,10 @@ internal static IEnumerable GetDefaultFormattingRules(IS /// An optional set of formatting options. If these options are not supplied the current set of options from the workspace will be used. /// An optional cancellation token. /// The formatted tree's root node. - public static SyntaxNode Format(SyntaxNode node, ISyntaxFormattingService syntaxFormattingService, SyntaxFormattingOptions options, CancellationToken cancellationToken) + public static SyntaxNode Format(SyntaxNode node, ISyntaxFormatting syntaxFormattingService, SyntaxFormattingOptions options, CancellationToken cancellationToken) => Format(node, SpecializedCollections.SingletonEnumerable(node.FullSpan), syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken); - public static SyntaxNode Format(SyntaxNode node, TextSpan spanToFormat, ISyntaxFormattingService syntaxFormattingService, SyntaxFormattingOptions options, CancellationToken cancellationToken) + public static SyntaxNode Format(SyntaxNode node, TextSpan spanToFormat, ISyntaxFormatting syntaxFormattingService, SyntaxFormattingOptions options, CancellationToken cancellationToken) => Format(node, SpecializedCollections.SingletonEnumerable(spanToFormat), syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken); /// @@ -43,16 +43,16 @@ public static SyntaxNode Format(SyntaxNode node, TextSpan spanToFormat, ISyntaxF /// An optional set of formatting options. If these options are not supplied the current set of options from the workspace will be used. /// An optional cancellation token. /// The formatted tree's root node. - public static SyntaxNode Format(SyntaxNode node, SyntaxAnnotation annotation, ISyntaxFormattingService syntaxFormattingService, SyntaxFormattingOptions options, IEnumerable? rules, CancellationToken cancellationToken) + public static SyntaxNode Format(SyntaxNode node, SyntaxAnnotation annotation, ISyntaxFormatting syntaxFormattingService, SyntaxFormattingOptions options, IEnumerable? rules, CancellationToken cancellationToken) => Format(node, GetAnnotatedSpans(node, annotation), syntaxFormattingService, options, rules, cancellationToken: cancellationToken); - internal static SyntaxNode Format(SyntaxNode node, IEnumerable spans, ISyntaxFormattingService syntaxFormattingService, SyntaxFormattingOptions options, IEnumerable? rules, CancellationToken cancellationToken) + internal static SyntaxNode Format(SyntaxNode node, IEnumerable spans, ISyntaxFormatting syntaxFormattingService, SyntaxFormattingOptions options, IEnumerable? rules, CancellationToken cancellationToken) => GetFormattingResult(node, spans, syntaxFormattingService, options, rules, cancellationToken).GetFormattedRoot(cancellationToken); - internal static IList GetFormattedTextChanges(SyntaxNode node, IEnumerable spans, ISyntaxFormattingService syntaxFormattingService, SyntaxFormattingOptions options, IEnumerable? rules, CancellationToken cancellationToken) + internal static IList GetFormattedTextChanges(SyntaxNode node, IEnumerable spans, ISyntaxFormatting syntaxFormattingService, SyntaxFormattingOptions options, IEnumerable? rules, CancellationToken cancellationToken) => GetFormattingResult(node, spans, syntaxFormattingService, options, rules, cancellationToken).GetTextChanges(cancellationToken); - internal static IFormattingResult GetFormattingResult(SyntaxNode node, IEnumerable spans, ISyntaxFormattingService syntaxFormattingService, SyntaxFormattingOptions options, IEnumerable? rules, CancellationToken cancellationToken) + internal static IFormattingResult GetFormattingResult(SyntaxNode node, IEnumerable spans, ISyntaxFormatting syntaxFormattingService, SyntaxFormattingOptions options, IEnumerable? rules, CancellationToken cancellationToken) => syntaxFormattingService.GetFormattingResult(node, spans, options, rules, cancellationToken); /// @@ -62,7 +62,7 @@ internal static IFormattingResult GetFormattingResult(SyntaxNode node, IEnumerab /// An optional set of formatting options. If these options are not supplied the current set of options from the workspace will be used. /// An optional cancellation token. /// The changes necessary to format the tree. - public static IList GetFormattedTextChanges(SyntaxNode node, ISyntaxFormattingService syntaxFormattingService, SyntaxFormattingOptions options, CancellationToken cancellationToken) + public static IList GetFormattedTextChanges(SyntaxNode node, ISyntaxFormatting syntaxFormattingService, SyntaxFormattingOptions options, CancellationToken cancellationToken) => GetFormattedTextChanges(node, SpecializedCollections.SingletonEnumerable(node.FullSpan), syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken); } } diff --git a/src/CodeStyle/Core/Analyzers/FormattingAnalyzerHelper.cs b/src/CodeStyle/Core/Analyzers/FormattingAnalyzerHelper.cs index e6a0dd174a082..59dc6e4062dcb 100644 --- a/src/CodeStyle/Core/Analyzers/FormattingAnalyzerHelper.cs +++ b/src/CodeStyle/Core/Analyzers/FormattingAnalyzerHelper.cs @@ -10,7 +10,7 @@ #if CODE_STYLE using Formatter = Microsoft.CodeAnalysis.Formatting.FormatterHelper; -using FormattingProvider = Microsoft.CodeAnalysis.Formatting.ISyntaxFormattingService; +using FormattingProvider = Microsoft.CodeAnalysis.Formatting.ISyntaxFormatting; #else using FormattingProvider = Microsoft.CodeAnalysis.Host.HostWorkspaceServices; #endif diff --git a/src/CodeStyle/Core/CodeFixes/FormattingCodeFixHelper.cs b/src/CodeStyle/Core/CodeFixes/FormattingCodeFixHelper.cs index c6f074a545a51..1b9522d6e249b 100644 --- a/src/CodeStyle/Core/CodeFixes/FormattingCodeFixHelper.cs +++ b/src/CodeStyle/Core/CodeFixes/FormattingCodeFixHelper.cs @@ -9,7 +9,7 @@ #if CODE_STYLE using Formatter = Microsoft.CodeAnalysis.Formatting.FormatterHelper; -using FormattingProvider = Microsoft.CodeAnalysis.Formatting.ISyntaxFormattingService; +using FormattingProvider = Microsoft.CodeAnalysis.Formatting.ISyntaxFormatting; #else using Microsoft.CodeAnalysis.Options; using FormattingProvider = Microsoft.CodeAnalysis.Host.HostWorkspaceServices; diff --git a/src/CodeStyle/Core/CodeFixes/FormattingCodeFixProvider.cs b/src/CodeStyle/Core/CodeFixes/FormattingCodeFixProvider.cs index e7550a1dde299..225866e0482b4 100644 --- a/src/CodeStyle/Core/CodeFixes/FormattingCodeFixProvider.cs +++ b/src/CodeStyle/Core/CodeFixes/FormattingCodeFixProvider.cs @@ -22,7 +22,7 @@ internal abstract class AbstractFormattingCodeFixProvider : CodeFixProvider public sealed override ImmutableArray FixableDiagnosticIds => ImmutableArray.Create(IDEDiagnosticIds.FormattingDiagnosticId); - protected abstract ISyntaxFormattingService SyntaxFormattingService { get; } + protected abstract ISyntaxFormatting SyntaxFormatting { get; } public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) { @@ -43,7 +43,7 @@ private async Task FixOneAsync(CodeFixContext context, Diagnostic diag { var options = await GetOptionsAsync(context.Document, cancellationToken).ConfigureAwait(false); var tree = await context.Document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); - var updatedTree = await FormattingCodeFixHelper.FixOneAsync(tree, SyntaxFormattingService, options, diagnostic, cancellationToken).ConfigureAwait(false); + var updatedTree = await FormattingCodeFixHelper.FixOneAsync(tree, this.SyntaxFormatting, options, diagnostic, cancellationToken).ConfigureAwait(false); return context.Document.WithText(await updatedTree.GetTextAsync(cancellationToken).ConfigureAwait(false)); } @@ -51,7 +51,7 @@ private async Task GetOptionsAsync(Document document, C { var tree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var analyzerConfigOptions = document.Project.AnalyzerOptions.AnalyzerConfigOptionsProvider.GetOptions(tree); - return SyntaxFormattingService.GetFormattingOptions(analyzerConfigOptions); + return this.SyntaxFormatting.GetFormattingOptions(analyzerConfigOptions); } public sealed override FixAllProvider GetFixAllProvider() @@ -60,7 +60,7 @@ public sealed override FixAllProvider GetFixAllProvider() var cancellationToken = context.CancellationToken; var options = await GetOptionsAsync(document, cancellationToken).ConfigureAwait(false); var syntaxRoot = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); - var updatedSyntaxRoot = Formatter.Format(syntaxRoot, this.SyntaxFormattingService, options, cancellationToken); + var updatedSyntaxRoot = Formatter.Format(syntaxRoot, this.SyntaxFormatting, options, cancellationToken); return document.WithSyntaxRoot(updatedSyntaxRoot); }); } diff --git a/src/CodeStyle/VisualBasic/Analyzers/VisualBasicFormattingAnalyzer.vb b/src/CodeStyle/VisualBasic/Analyzers/VisualBasicFormattingAnalyzer.vb index 6d4e5c6883742..fdd627c81a7f8 100644 --- a/src/CodeStyle/VisualBasic/Analyzers/VisualBasicFormattingAnalyzer.vb +++ b/src/CodeStyle/VisualBasic/Analyzers/VisualBasicFormattingAnalyzer.vb @@ -11,9 +11,9 @@ Namespace Microsoft.CodeAnalysis.CodeStyle Friend Class VisualBasicFormattingAnalyzer Inherits AbstractFormattingAnalyzer - Protected Overrides ReadOnly Property SyntaxFormattingService As ISyntaxFormattingService + Protected Overrides ReadOnly Property SyntaxFormatting As ISyntaxFormatting Get - Return VisualBasicSyntaxFormattingService.Instance + Return VisualBasicSyntaxFormatting.Instance End Get End Property End Class diff --git a/src/CodeStyle/VisualBasic/CodeFixes/VisualBasicFormattingCodeFixProvider.vb b/src/CodeStyle/VisualBasic/CodeFixes/VisualBasicFormattingCodeFixProvider.vb index f46110e6b3c62..f8887597a692c 100644 --- a/src/CodeStyle/VisualBasic/CodeFixes/VisualBasicFormattingCodeFixProvider.vb +++ b/src/CodeStyle/VisualBasic/CodeFixes/VisualBasicFormattingCodeFixProvider.vb @@ -19,9 +19,9 @@ Namespace Microsoft.CodeAnalysis.CodeStyle Public Sub New() End Sub - Protected Overrides ReadOnly Property SyntaxFormattingService As ISyntaxFormattingService + Protected Overrides ReadOnly Property SyntaxFormatting As ISyntaxFormatting Get - Return VisualBasicSyntaxFormattingService.Instance + Return VisualBasicSyntaxFormatting.Instance End Get End Property End Class diff --git a/src/EditorFeatures/CSharpTest/Formatting/Indentation/CSharpFormatterTestsBase.cs b/src/EditorFeatures/CSharpTest/Formatting/Indentation/CSharpFormatterTestsBase.cs index ab19697d14108..8b026400d67c8 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/Indentation/CSharpFormatterTestsBase.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/Indentation/CSharpFormatterTestsBase.cs @@ -84,7 +84,7 @@ private static async Task TokenFormatWorkerAsync(TestWorkspace workspace, ITextB var options = await IndentationOptions.FromDocumentAsync(document, CancellationToken.None); var formatter = new CSharpSmartTokenFormatter(options, rules, root); - var changes = await formatter.FormatTokenAsync(workspace.Services, token, CancellationToken.None); + var changes = await formatter.FormatTokenAsync(token, CancellationToken.None); ApplyChanges(buffer, changes); } diff --git a/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartTokenFormatterFormatRangeTests.cs b/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartTokenFormatterFormatRangeTests.cs index 3f5ef74ec4eaf..7381ad106a6b1 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartTokenFormatterFormatRangeTests.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartTokenFormatterFormatRangeTests.cs @@ -3604,7 +3604,7 @@ private static async Task AutoFormatOnMarkerAsync(string initialMarkup, string e return; } - var changes = formatter.FormatRange(workspace.Services, tokenRange.Value.Item1, tokenRange.Value.Item2, CancellationToken.None); + var changes = formatter.FormatRange(tokenRange.Value.Item1, tokenRange.Value.Item2, CancellationToken.None); var actual = GetFormattedText(buffer, changes); Assert.Equal(expected, actual); } diff --git a/src/EditorFeatures/VisualBasicTest/Formatting/Indentation/SmartTokenFormatter_FormatTokenTests.vb b/src/EditorFeatures/VisualBasicTest/Formatting/Indentation/SmartTokenFormatter_FormatTokenTests.vb index 82ed93b5b91c6..963b42b588913 100644 --- a/src/EditorFeatures/VisualBasicTest/Formatting/Indentation/SmartTokenFormatter_FormatTokenTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Formatting/Indentation/SmartTokenFormatter_FormatTokenTests.vb @@ -153,7 +153,7 @@ $$) End Class .Value.Replace(vbLf, vbCrLf) - Await ExpectException_TestAsync(code, 4, FormattingOptions.IndentStyle.Block) + Await ExpectException_TestAsync(code, 4, FormattingOptions2.IndentStyle.Block) End Function @@ -166,14 +166,14 @@ $$) End Class .Value.Replace(vbLf, vbCrLf) - Await ExpectException_TestAsync(code, indentation:=0, indentStyle:=FormattingOptions.IndentStyle.None) + Await ExpectException_TestAsync(code, indentation:=0, indentStyle:=FormattingOptions2.IndentStyle.None) End Function - Private Shared Async Function ExpectException_TestAsync(codeWithMarkup As String, indentation As Integer, Optional indentStyle As FormattingOptions.IndentStyle = FormattingOptions.IndentStyle.Smart) As Task + Private Shared Async Function ExpectException_TestAsync(codeWithMarkup As String, indentation As Integer, Optional indentStyle As FormattingOptions2.IndentStyle = FormattingOptions2.IndentStyle.Smart) As Task Assert.NotNull(Await Record.ExceptionAsync(Function() TestAsync(codeWithMarkup, indentation, indentStyle:=indentStyle))) End Function - Private Shared Async Function TestAsync(codeWithMarkup As String, indentation As Integer, Optional indentStyle As FormattingOptions.IndentStyle = FormattingOptions.IndentStyle.Smart) As Threading.Tasks.Task + Private Shared Async Function TestAsync(codeWithMarkup As String, indentation As Integer, Optional indentStyle As FormattingOptions2.IndentStyle = FormattingOptions2.IndentStyle.Smart) As Threading.Tasks.Task Dim code As String = Nothing Dim position As Integer = 0 MarkupTestFile.GetPosition(codeWithMarkup, code, position) @@ -202,7 +202,7 @@ End Class Dim formatOptions = Await SyntaxFormattingOptions.FromDocumentAsync(document, CancellationToken.None) Dim smartFormatter = New VisualBasicSmartTokenFormatter(formatOptions, formattingRules, root) - Dim changes = Await smartFormatter.FormatTokenAsync(workspace.Services, token, Nothing) + Dim changes = Await smartFormatter.FormatTokenAsync(token, Nothing) Using edit = buffer.CreateEdit() For Each change In changes diff --git a/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs b/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs index 59f1d7906edb5..3ab21a9a8f0a1 100644 --- a/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs +++ b/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs @@ -219,7 +219,7 @@ static ImmutableArray GetMergedChanges(TextChange newLineEdit, Immut var startPoint = openingPoint; var endPoint = AdjustFormattingEndPoint(text, root, startPoint, closingPoint); - if (options.AutoFormattingOptions.IndentStyle == FormattingOptions.IndentStyle.Smart) + if (options.AutoFormattingOptions.IndentStyle == FormattingOptions2.IndentStyle.Smart) { // Set the formatting start point to be the beginning of the first word to the left // of the opening brace location. diff --git a/src/Features/CSharp/Portable/BraceCompletion/CurlyBraceCompletionService.cs b/src/Features/CSharp/Portable/BraceCompletion/CurlyBraceCompletionService.cs index 41f463b88acc9..0d8891e785bc6 100644 --- a/src/Features/CSharp/Portable/BraceCompletion/CurlyBraceCompletionService.cs +++ b/src/Features/CSharp/Portable/BraceCompletion/CurlyBraceCompletionService.cs @@ -92,25 +92,25 @@ private sealed class BraceCompletionFormattingRule : BaseFormattingRule private static readonly Predicate s_predicate = o => o == null || o.Option.IsOn(SuppressOption.NoWrapping); private static readonly ImmutableArray s_instances = ImmutableArray.Create( - new BraceCompletionFormattingRule(FormattingOptions.IndentStyle.None), - new BraceCompletionFormattingRule(FormattingOptions.IndentStyle.Block), - new BraceCompletionFormattingRule(FormattingOptions.IndentStyle.Smart)); + new BraceCompletionFormattingRule(FormattingOptions2.IndentStyle.None), + new BraceCompletionFormattingRule(FormattingOptions2.IndentStyle.Block), + new BraceCompletionFormattingRule(FormattingOptions2.IndentStyle.Smart)); - private readonly FormattingOptions.IndentStyle _indentStyle; + private readonly FormattingOptions2.IndentStyle _indentStyle; private readonly CSharpSyntaxFormattingOptions _options; - public BraceCompletionFormattingRule(FormattingOptions.IndentStyle indentStyle) + public BraceCompletionFormattingRule(FormattingOptions2.IndentStyle indentStyle) : this(indentStyle, CSharpSyntaxFormattingOptions.Default) { } - private BraceCompletionFormattingRule(FormattingOptions.IndentStyle indentStyle, CSharpSyntaxFormattingOptions options) + private BraceCompletionFormattingRule(FormattingOptions2.IndentStyle indentStyle, CSharpSyntaxFormattingOptions options) { _indentStyle = indentStyle; _options = options; } - public static AbstractFormattingRule ForIndentStyle(FormattingOptions.IndentStyle indentStyle) + public static AbstractFormattingRule ForIndentStyle(FormattingOptions2.IndentStyle indentStyle) { Debug.Assert(s_instances[(int)indentStyle]._indentStyle == indentStyle); return s_instances[(int)indentStyle]; @@ -250,7 +250,7 @@ private static bool IsControlBlock(SyntaxNode? node) public override void AddAlignTokensOperations(List list, SyntaxNode node, in NextAlignTokensOperationAction nextOperation) { base.AddAlignTokensOperations(list, node, in nextOperation); - if (_indentStyle == FormattingOptions.IndentStyle.Block) + if (_indentStyle == FormattingOptions2.IndentStyle.Block) { var bracePair = node.GetBracePair(); if (bracePair.IsValidBracketOrBracePair()) diff --git a/src/Features/CSharp/Portable/Formatting/CSharpFormattingInteractionService.cs b/src/Features/CSharp/Portable/Formatting/CSharpFormattingInteractionService.cs index 5f292e5ad6d07..aff8e89724aea 100644 --- a/src/Features/CSharp/Portable/Formatting/CSharpFormattingInteractionService.cs +++ b/src/Features/CSharp/Portable/Formatting/CSharpFormattingInteractionService.cs @@ -46,7 +46,7 @@ public CSharpFormattingInteractionService() public bool SupportsFormattingOnTypedCharacter(Document document, AutoFormattingOptions options, char ch) { - var smartIndentOn = options.IndentStyle == FormattingOptions.IndentStyle.Smart; + var smartIndentOn = options.IndentStyle == FormattingOptions2.IndentStyle.Smart; // We consider the proper placement of a close curly or open curly when it is typed at // the start of the line to be a smart-indentation operation. As such, even if "format @@ -298,7 +298,7 @@ private static async Task> FormatTokenAsync(Document document, { var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var formatter = CreateSmartTokenFormatter(options, formattingRules, root); - var changes = await formatter.FormatTokenAsync(document.Project.Solution.Workspace.Services, token, cancellationToken).ConfigureAwait(false); + var changes = await formatter.FormatTokenAsync(token, cancellationToken).ConfigureAwait(false); return changes; } @@ -332,7 +332,7 @@ private static async Task> FormatRangeAsync( var formatter = new CSharpSmartTokenFormatter(options, formattingRules, (CompilationUnitSyntax)root); - var changes = formatter.FormatRange(document.Project.Solution.Workspace.Services, tokenRange.Value.Item1, tokenRange.Value.Item2, cancellationToken); + var changes = formatter.FormatRange(tokenRange.Value.Item1, tokenRange.Value.Item2, cancellationToken); return changes.ToImmutableArray(); } diff --git a/src/Tools/ExternalAccess/FSharp/Editor/AutoFormattingOptionsWrapper.cs b/src/Tools/ExternalAccess/FSharp/Editor/AutoFormattingOptionsWrapper.cs index 9e403a11b9eb1..c3f6af042cfbd 100644 --- a/src/Tools/ExternalAccess/FSharp/Editor/AutoFormattingOptionsWrapper.cs +++ b/src/Tools/ExternalAccess/FSharp/Editor/AutoFormattingOptionsWrapper.cs @@ -14,6 +14,6 @@ public AutoFormattingOptionsWrapper(AutoFormattingOptions underlyingObject) => UnderlyingObject = underlyingObject; public FormattingOptions.IndentStyle IndentStyle - => UnderlyingObject.IndentStyle; + => (FormattingOptions.IndentStyle)UnderlyingObject.IndentStyle; } } diff --git a/src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.Indenter.cs b/src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.Indenter.cs index 34921a5b63d7f..7368413ac9f4e 100644 --- a/src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.Indenter.cs +++ b/src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.Indenter.cs @@ -13,6 +13,7 @@ using Microsoft.CodeAnalysis.Formatting.Rules; using Microsoft.CodeAnalysis.Indentation; using Microsoft.CodeAnalysis.Shared.Extensions; +using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.Indentation @@ -23,12 +24,12 @@ protected override bool ShouldUseTokenIndenter(Indenter indenter, out SyntaxToke => ShouldUseSmartTokenFormatterInsteadOfIndenter( indenter.Rules, indenter.Root, indenter.LineToBeIndented, indenter.Options, out syntaxToken); - protected override ISmartTokenFormatter CreateSmartTokenFormatter(Indenter indenter) + protected override ISmartTokenFormatter CreateSmartTokenFormatter(Document document, CompilationUnitSyntax root, TextLine lineToBeIndented, IndentationOptions options) { - var services = indenter.Document.Project.Solution.Workspace.Services; + var services = document.Project.Solution.Workspace.Services; var formattingRuleFactory = services.GetRequiredService(); - var rules = formattingRuleFactory.CreateRule(indenter.Document.Document, indenter.LineToBeIndented.Start).Concat(Formatter.GetDefaultFormattingRules(indenter.Document.Document)); - return new CSharpSmartTokenFormatter(indenter.Options, rules, indenter.Root); + var rules = formattingRuleFactory.CreateRule(document, lineToBeIndented.Start).Concat(CSharpSyntaxFormatting.Instance.GetDefaultFormattingRules()); + return new CSharpSmartTokenFormatter(options, rules, root); } protected override IndentationResult? GetDesiredIndentationWorker(Indenter indenter, SyntaxToken? tokenOpt, SyntaxTrivia? triviaOpt) diff --git a/src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.cs b/src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.cs index 0352f8b050d7c..b7aaf99b66337 100644 --- a/src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.cs +++ b/src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.cs @@ -32,7 +32,7 @@ public CSharpIndentationService() { } - protected override AbstractFormattingRule GetSpecializedIndentationFormattingRule(FormattingOptions.IndentStyle indentStyle) + protected override AbstractFormattingRule GetSpecializedIndentationFormattingRule(FormattingOptions2.IndentStyle indentStyle) => s_instance; public static bool ShouldUseSmartTokenFormatterInsteadOfIndenter( @@ -51,7 +51,7 @@ public static bool ShouldUseSmartTokenFormatterInsteadOfIndenter( return false; } - if (options.AutoFormattingOptions.IndentStyle != FormattingOptions.IndentStyle.Smart) + if (options.AutoFormattingOptions.IndentStyle != FormattingOptions2.IndentStyle.Smart) { return false; } diff --git a/src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.Indenter.cs b/src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.Indenter.cs index 2930aad0f7637..bcb536d364d15 100644 --- a/src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.Indenter.cs +++ b/src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.Indenter.cs @@ -36,12 +36,15 @@ protected struct Indenter public readonly SyntaxTree Tree => Document.SyntaxTree; public readonly SourceText Text => Document.Text; + public readonly ISmartTokenFormatter SmartTokenFormatter; + public Indenter( AbstractIndentationService service, SyntacticDocument document, IEnumerable rules, IndentationOptions options, TextLine lineToBeIndented, + ISmartTokenFormatter smartTokenFormatter, CancellationToken cancellationToken) { Document = document; @@ -52,6 +55,7 @@ public Indenter( Root = (TSyntaxRoot)document.Root; LineToBeIndented = lineToBeIndented; _tabSize = options.FormattingOptions.TabSize; + SmartTokenFormatter = smartTokenFormatter; CancellationToken = cancellationToken; Rules = rules; @@ -166,9 +170,9 @@ public bool TryGetSmartTokenIndentation(out IndentationResult indentationResult) // var root = document.GetSyntaxRootSynchronously(cancellationToken); var sourceText = Tree.GetText(CancellationToken); - var formatter = _service.CreateSmartTokenFormatter(this); - var changes = formatter.FormatTokenAsync(Document.Project.Solution.Workspace.Services, token, CancellationToken) - .WaitAndGetResult_CanCallOnBackground(CancellationToken); + var changes = this.SmartTokenFormatter + .FormatTokenAsync(token, CancellationToken) + .WaitAndGetResult_CanCallOnBackground(CancellationToken); var updatedSourceText = sourceText.WithChanges(changes); if (LineToBeIndented.LineNumber < updatedSourceText.Lines.Count) diff --git a/src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.cs b/src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.cs index 3c6655866c34f..3dbf3361508b3 100644 --- a/src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.cs +++ b/src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.cs @@ -5,11 +5,9 @@ using System.Collections.Generic; using System.Linq; using System.Threading; -using System.Threading.Tasks; using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Formatting.Rules; -using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Indentation @@ -17,9 +15,10 @@ namespace Microsoft.CodeAnalysis.Indentation internal abstract partial class AbstractIndentationService : IIndentationService where TSyntaxRoot : SyntaxNode, ICompilationUnitSyntax { - protected abstract AbstractFormattingRule GetSpecializedIndentationFormattingRule(FormattingOptions.IndentStyle indentStyle); + protected abstract AbstractFormattingRule GetSpecializedIndentationFormattingRule(FormattingOptions2.IndentStyle indentStyle); + protected abstract ISmartTokenFormatter CreateSmartTokenFormatter(Document document, TSyntaxRoot root, TextLine lineToBeIndented, IndentationOptions options); - private IEnumerable GetFormattingRules(Document document, int position, FormattingOptions.IndentStyle indentStyle) + private IEnumerable GetFormattingRules(Document document, int position, FormattingOptions2.IndentStyle indentStyle) { var workspace = document.Project.Solution.Workspace; var formattingRuleFactory = workspace.Services.GetRequiredService(); @@ -33,7 +32,7 @@ public IndentationResult GetIndentation( Document document, int lineNumber, FormattingOptions.IndentStyle indentStyle, CancellationToken cancellationToken) { - var indenter = GetIndenter(document, lineNumber, indentStyle, cancellationToken); + var indenter = GetIndenter(document, lineNumber, (FormattingOptions2.IndentStyle)indentStyle, cancellationToken); if (indentStyle == FormattingOptions.IndentStyle.None) { @@ -51,7 +50,7 @@ public IndentationResult GetIndentation( return indenter.GetDesiredIndentation(indentStyle) ?? default; } - private Indenter GetIndenter(Document document, int lineNumber, FormattingOptions.IndentStyle indentStyle, CancellationToken cancellationToken) + private Indenter GetIndenter(Document document, int lineNumber, FormattingOptions2.IndentStyle indentStyle, CancellationToken cancellationToken) { var options = IndentationOptions.FromDocumentAsync(document, cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); var syntacticDoc = SyntacticDocument.CreateAsync(document, cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); @@ -61,7 +60,10 @@ private Indenter GetIndenter(Document document, int lineNumber, FormattingOption var formattingRules = GetFormattingRules(document, lineToBeIndented.Start, indentStyle); - return new Indenter(this, syntacticDoc, formattingRules, options, lineToBeIndented, cancellationToken); + var smartTokenFormatter = CreateSmartTokenFormatter( + document, (TSyntaxRoot)syntacticDoc.Root, lineToBeIndented, options); + + return new Indenter(this, syntacticDoc, formattingRules, options, lineToBeIndented, smartTokenFormatter, cancellationToken); } /// @@ -71,7 +73,6 @@ private Indenter GetIndenter(Document document, int lineNumber, FormattingOption /// provided by this method. /// protected abstract bool ShouldUseTokenIndenter(Indenter indenter, out SyntaxToken token); - protected abstract ISmartTokenFormatter CreateSmartTokenFormatter(Indenter indenter); protected abstract IndentationResult? GetDesiredIndentationWorker( Indenter indenter, SyntaxToken? token, SyntaxTrivia? trivia); diff --git a/src/Workspaces/Core/Portable/Formatting/FormattingOptions.IndentStyle.cs b/src/Workspaces/Core/Portable/Indentation/FormattingOptions.IndentStyle.cs similarity index 83% rename from src/Workspaces/Core/Portable/Formatting/FormattingOptions.IndentStyle.cs rename to src/Workspaces/Core/Portable/Indentation/FormattingOptions.IndentStyle.cs index 110cf8f24dcf8..868176e161dd6 100644 --- a/src/Workspaces/Core/Portable/Formatting/FormattingOptions.IndentStyle.cs +++ b/src/Workspaces/Core/Portable/Indentation/FormattingOptions.IndentStyle.cs @@ -6,6 +6,7 @@ namespace Microsoft.CodeAnalysis.Formatting { public static partial class FormattingOptions { + // Publicly exposed. Keep in sync with IndentStyle2 in the CodeStyle layer. public enum IndentStyle { None = 0, diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/CSharpCompilerExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/CSharpCompilerExtensions.projitems index 9dc3b28f94a90..9425a921eb212 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/CSharpCompilerExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/CSharpCompilerExtensions.projitems @@ -87,6 +87,7 @@ + diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/CSharpSyntaxFormattingService.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/CSharpSyntaxFormattingService.cs index c077466ebb0fc..afb077968485e 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/CSharpSyntaxFormattingService.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/CSharpSyntaxFormattingService.cs @@ -19,37 +19,24 @@ namespace Microsoft.CodeAnalysis.CSharp.Formatting { -#if !CODE_STYLE - [ExportLanguageService(typeof(ISyntaxFormattingService), LanguageNames.CSharp), Shared] -#endif - internal class CSharpSyntaxFormattingService : AbstractSyntaxFormattingService + internal class CSharpSyntaxFormatting : AbstractSyntaxFormatting { - private readonly ImmutableList _rules; + public static readonly CSharpSyntaxFormatting Instance = new(); -#if CODE_STYLE - public static readonly CSharpSyntaxFormattingService Instance = new(); - -#else - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] -#endif - public CSharpSyntaxFormattingService() - { - _rules = ImmutableList.Create( - new WrappingFormattingRule(), - new SpacingFormattingRule(), - new NewLineUserSettingFormattingRule(), - new IndentUserSettingsFormattingRule(), - new ElasticTriviaFormattingRule(), - new EndOfFileTokenFormattingRule(), - new StructuredTriviaFormattingRule(), - new IndentBlockFormattingRule(), - new SuppressFormattingRule(), - new AnchorIndentationFormattingRule(), - new QueryExpressionFormattingRule(), - new TokenBasedFormattingRule(), - DefaultOperationProvider.Instance); - } + private readonly ImmutableList _rules = ImmutableList.Create( + new WrappingFormattingRule(), + new SpacingFormattingRule(), + new NewLineUserSettingFormattingRule(), + new IndentUserSettingsFormattingRule(), + new ElasticTriviaFormattingRule(), + new EndOfFileTokenFormattingRule(), + new StructuredTriviaFormattingRule(), + new IndentBlockFormattingRule(), + new SuppressFormattingRule(), + new AnchorIndentationFormattingRule(), + new QueryExpressionFormattingRule(), + new TokenBasedFormattingRule(), + DefaultOperationProvider.Instance); public override IEnumerable GetDefaultFormattingRules() => _rules; @@ -63,4 +50,16 @@ protected override IFormattingResult CreateAggregatedFormattingResult(SyntaxNode protected override AbstractFormattingResult Format(SyntaxNode node, SyntaxFormattingOptions options, IEnumerable formattingRules, SyntaxToken startToken, SyntaxToken endToken, CancellationToken cancellationToken) => new CSharpFormatEngine(node, options, formattingRules, startToken, endToken).Format(cancellationToken); } + +#if !CODE_STYLE + [ExportLanguageService(typeof(ISyntaxFormattingService), LanguageNames.CSharp), Shared] + internal class CSharpSyntaxFormattingService : CSharpSyntaxFormatting, ISyntaxFormattingService + { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public CSharpSyntaxFormattingService() + { + } + } +#endif } diff --git a/src/Workspaces/CSharp/Portable/Indentation/CSharpSmartTokenFormatter.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Indentation/CSharpSmartTokenFormatter.cs similarity index 89% rename from src/Workspaces/CSharp/Portable/Indentation/CSharpSmartTokenFormatter.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Indentation/CSharpSmartTokenFormatter.cs index d5c16d911287a..d17774e9850aa 100644 --- a/src/Workspaces/CSharp/Portable/Indentation/CSharpSmartTokenFormatter.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Indentation/CSharpSmartTokenFormatter.cs @@ -11,9 +11,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Formatting.Rules; -using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Indentation; -using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; @@ -42,7 +40,7 @@ public CSharpSmartTokenFormatter( } public IList FormatRange( - HostWorkspaceServices services, SyntaxToken startToken, SyntaxToken endToken, CancellationToken cancellationToken) + SyntaxToken startToken, SyntaxToken endToken, CancellationToken cancellationToken) { Contract.ThrowIfTrue(startToken.Kind() is SyntaxKind.None or SyntaxKind.EndOfFileToken); Contract.ThrowIfTrue(endToken.Kind() is SyntaxKind.None or SyntaxKind.EndOfFileToken); @@ -60,7 +58,10 @@ public IList FormatRange( smartTokenformattingRules = (new NoLineChangeFormattingRule()).Concat(_formattingRules); } - return Formatter.GetFormattedTextChanges(_root, new[] { TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End) }, services, _options.FormattingOptions, smartTokenformattingRules, cancellationToken); + var formatter = CSharpSyntaxFormatting.Instance; + var result = formatter.GetFormattingResult( + _root, new[] { TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End) }, _options.FormattingOptions, smartTokenformattingRules, cancellationToken); + return result.GetTextChanges(cancellationToken); } private static bool CloseBraceOfTryOrDoBlock(SyntaxToken endToken) @@ -71,7 +72,7 @@ private static bool CloseBraceOfTryOrDoBlock(SyntaxToken endToken) } public async Task> FormatTokenAsync( - HostWorkspaceServices services, SyntaxToken token, CancellationToken cancellationToken) + SyntaxToken token, CancellationToken cancellationToken) { Contract.ThrowIfTrue(token.Kind() is SyntaxKind.None or SyntaxKind.EndOfFileToken); @@ -103,7 +104,7 @@ public async Task> FormatTokenAsync( var smartTokenformattingRules = new SmartTokenFormattingRule().Concat(_formattingRules); var adjustedStartPosition = previousToken.SpanStart; if (token.IsKind(SyntaxKind.OpenBraceToken) && - _options.AutoFormattingOptions.IndentStyle != FormattingOptions.IndentStyle.Smart) + _options.AutoFormattingOptions.IndentStyle != FormattingOptions2.IndentStyle.Smart) { RoslynDebug.AssertNotNull(token.SyntaxTree); var text = await token.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false); @@ -113,7 +114,10 @@ public async Task> FormatTokenAsync( } } - return Formatter.GetFormattedTextChanges(_root, new[] { TextSpan.FromBounds(adjustedStartPosition, adjustedEndPosition) }, services, _options.FormattingOptions, smartTokenformattingRules, cancellationToken); + var formatter = CSharpSyntaxFormatting.Instance; + var result = formatter.GetFormattingResult( + _root, new[] { TextSpan.FromBounds(adjustedStartPosition, adjustedEndPosition) }, _options.FormattingOptions, smartTokenformattingRules, cancellationToken); + return result.GetTextChanges(cancellationToken); } private class NoLineChangeFormattingRule : AbstractFormattingRule diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems index 6fb74a6ed131d..13c6daa12d50a 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems @@ -229,6 +229,10 @@ + + + + diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/AbstractSyntaxFormattingService.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/AbstractSyntaxFormattingService.cs index 58d86aa33cacf..62451754a6573 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/AbstractSyntaxFormattingService.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/AbstractSyntaxFormattingService.cs @@ -16,11 +16,11 @@ namespace Microsoft.CodeAnalysis.Formatting { - internal abstract class AbstractSyntaxFormattingService : ISyntaxFormattingService + internal abstract class AbstractSyntaxFormatting : ISyntaxFormatting { private static readonly Func s_notEmpty = s => !s.IsEmpty; - protected AbstractSyntaxFormattingService() + protected AbstractSyntaxFormatting() { } diff --git a/src/Workspaces/Core/Portable/Formatting/AutoFormattingOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/AutoFormattingOptions.cs similarity index 94% rename from src/Workspaces/Core/Portable/Formatting/AutoFormattingOptions.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/AutoFormattingOptions.cs index edc1df9610d0e..03680232391b4 100644 --- a/src/Workspaces/Core/Portable/Formatting/AutoFormattingOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/AutoFormattingOptions.cs @@ -4,10 +4,13 @@ using System; using System.Collections.Immutable; +using Microsoft.CodeAnalysis.Options; + +#if !CODE_STYLE using System.Composition; using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Options.Providers; +#endif namespace Microsoft.CodeAnalysis.Formatting { @@ -15,18 +18,19 @@ namespace Microsoft.CodeAnalysis.Formatting /// Solution-wide formatting options. /// internal readonly record struct AutoFormattingOptions( - FormattingOptions.IndentStyle IndentStyle, + FormattingOptions2.IndentStyle IndentStyle, bool FormatOnReturn, bool FormatOnTyping, bool FormatOnSemicolon, bool FormatOnCloseBrace) { +#if !CODE_STYLE public static AutoFormattingOptions From(Project project) => From(project.Solution.Options, project.Language); public static AutoFormattingOptions From(OptionSet options, string language) => new( - IndentStyle: options.GetOption(Metadata.SmartIndent, language), + IndentStyle: (FormattingOptions2.IndentStyle)options.GetOption(Metadata.SmartIndent, language), FormatOnReturn: options.GetOption(Metadata.AutoFormattingOnReturn, language), FormatOnTyping: options.GetOption(Metadata.AutoFormattingOnTyping, language), FormatOnSemicolon: options.GetOption(Metadata.AutoFormattingOnSemicolon, language), @@ -70,5 +74,6 @@ public Metadata() "BraceCompletionOptions", nameof(AutoFormattingOnCloseBrace), defaultValue: true, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.Auto Formatting On Close Brace")); } +#endif } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingOptions2.IndentStyle.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingOptions2.IndentStyle.cs new file mode 100644 index 0000000000000..510a60679a166 --- /dev/null +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingOptions2.IndentStyle.cs @@ -0,0 +1,19 @@ +// 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. + +namespace Microsoft.CodeAnalysis.Formatting +{ + internal partial class FormattingOptions2 + { + /// + /// For use in the shared CodeStyle layer. Keep in syntax with IndentStyle. + /// + internal enum IndentStyle + { + None = 0, + Block = 1, + Smart = 2 + } + } +} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingOptions2.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingOptions2.cs index 13282f2a3e29b..a2e854a0268f7 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingOptions2.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingOptions2.cs @@ -19,7 +19,7 @@ namespace Microsoft.CodeAnalysis.Formatting /// /// Formatting options stored in editorconfig. /// - internal sealed class FormattingOptions2 + internal sealed partial class FormattingOptions2 { #if !CODE_STYLE [ExportSolutionOptionProvider, Shared] diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/ISyntaxFormattingService.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/ISyntaxFormattingService.cs index c83b980861bbe..b74cfa0fe85ee 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/ISyntaxFormattingService.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/ISyntaxFormattingService.cs @@ -17,16 +17,19 @@ namespace Microsoft.CodeAnalysis.Formatting { - internal interface ISyntaxFormattingService -#if !CODE_STYLE - : ILanguageService -#endif + internal interface ISyntaxFormatting { SyntaxFormattingOptions GetFormattingOptions(AnalyzerConfigOptions options); IEnumerable GetDefaultFormattingRules(); IFormattingResult GetFormattingResult(SyntaxNode node, IEnumerable? spans, SyntaxFormattingOptions options, IEnumerable? rules, CancellationToken cancellationToken); } +#if !CODE_STYLE + internal interface ISyntaxFormattingService : ISyntaxFormatting, ILanguageService + { + } +#endif + internal abstract class SyntaxFormattingOptions { public readonly bool UseTabs; diff --git a/src/Workspaces/Core/Portable/Indentation/ISmartTokenFormatter.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Indentation/ISmartTokenFormatter.cs similarity index 71% rename from src/Workspaces/Core/Portable/Indentation/ISmartTokenFormatter.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Indentation/ISmartTokenFormatter.cs index 2cab6570ce4c6..7b5e1dc398d5c 100644 --- a/src/Workspaces/Core/Portable/Indentation/ISmartTokenFormatter.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Indentation/ISmartTokenFormatter.cs @@ -5,13 +5,12 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Text; namespace Microsoft.CodeAnalysis.Indentation { internal interface ISmartTokenFormatter { - Task> FormatTokenAsync(HostWorkspaceServices services, SyntaxToken token, CancellationToken cancellationToken); + Task> FormatTokenAsync(SyntaxToken token, CancellationToken cancellationToken); } } diff --git a/src/Workspaces/Core/Portable/Indentation/IndentationOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Indentation/IndentationOptions.cs similarity index 98% rename from src/Workspaces/Core/Portable/Indentation/IndentationOptions.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Indentation/IndentationOptions.cs index b60fa4f7bc537..a911ac3350747 100644 --- a/src/Workspaces/Core/Portable/Indentation/IndentationOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Indentation/IndentationOptions.cs @@ -14,6 +14,7 @@ internal readonly record struct IndentationOptions( SyntaxFormattingOptions FormattingOptions, AutoFormattingOptions AutoFormattingOptions) { +#if !CODE_STYLE public static async Task FromDocumentAsync(Document document, CancellationToken cancellationToken) { var documentOptions = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); @@ -24,5 +25,6 @@ public static IndentationOptions From(OptionSet options, HostWorkspaceServices s => new( SyntaxFormattingOptions.Create(options, services, language), AutoFormattingOptions.From(options, language)); +#endif } } diff --git a/src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicSmartTokenFormatter.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/Indentation/VisualBasicSmartTokenFormatter.vb similarity index 77% rename from src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicSmartTokenFormatter.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/Indentation/VisualBasicSmartTokenFormatter.vb index c6df0a006973d..7d4c35cd7666e 100644 --- a/src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicSmartTokenFormatter.vb +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/Indentation/VisualBasicSmartTokenFormatter.vb @@ -10,6 +10,7 @@ Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Host Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Syntax +Imports Microsoft.CodeAnalysis.VisualBasic.Formatting Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation Friend Class VisualBasicSmartTokenFormatter @@ -32,14 +33,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation Me._root = root End Sub - Public Function FormatTokenAsync(services As HostWorkspaceServices, token As SyntaxToken, cancellationToken As CancellationToken) As Tasks.Task(Of IList(Of TextChange)) Implements ISmartTokenFormatter.FormatTokenAsync + Public Function FormatTokenAsync(token As SyntaxToken, cancellationToken As CancellationToken) As Tasks.Task(Of IList(Of TextChange)) Implements ISmartTokenFormatter.FormatTokenAsync Contract.ThrowIfTrue(token.Kind = SyntaxKind.None OrElse token.Kind = SyntaxKind.EndOfFileToken) ' get previous token Dim previousToken = token.GetPreviousToken() Dim spans = SpecializedCollections.SingletonEnumerable(TextSpan.FromBounds(previousToken.SpanStart, token.Span.End)) - Return Task.FromResult(Formatter.GetFormattedTextChanges(_root, spans, services, _options, _formattingRules, cancellationToken)) + Dim formatter = VisualBasicSyntaxFormatting.Instance + Dim result = formatter.GetFormattingResult(_root, spans, _options, _formattingRules, cancellationToken) + Return Task.FromResult(result.GetTextChanges(cancellationToken)) End Function End Class End Namespace diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/VisualBasicCompilerExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/VisualBasicCompilerExtensions.projitems index 123c5b5574bde..ce33db593dc13 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/VisualBasicCompilerExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/VisualBasicCompilerExtensions.projitems @@ -27,6 +27,7 @@ + diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.cs index 5591f9ac9bb57..b64807c7c73d4 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.cs @@ -39,8 +39,8 @@ public CSharpRemoveUnnecessaryImportsService() } #if CODE_STYLE - private static ISyntaxFormattingService GetSyntaxFormattingService() - => CSharpSyntaxFormattingService.Instance; + private static ISyntaxFormatting GetSyntaxFormatting() + => CSharpSyntaxFormatting.Instance; #endif protected override IUnnecessaryImportsProvider UnnecessaryImportsProvider @@ -68,7 +68,7 @@ public override async Task RemoveUnnecessaryImportsAsync( cancellationToken.ThrowIfCancellationRequested(); #if CODE_STYLE - var provider = GetSyntaxFormattingService(); + var provider = GetSyntaxFormatting(); var options = provider.GetFormattingOptions(document.Project.AnalyzerOptions.AnalyzerConfigOptionsProvider.GetOptions(oldRoot.SyntaxTree)); #else var provider = document.Project.Solution.Workspace.Services; diff --git a/src/Workspaces/VisualBasic/Portable/Formatting/VisualBasicSyntaxFormattingService.vb b/src/Workspaces/VisualBasic/Portable/Formatting/VisualBasicSyntaxFormattingService.vb index 250f610fb7f43..4508d31ea1fc5 100644 --- a/src/Workspaces/VisualBasic/Portable/Formatting/VisualBasicSyntaxFormattingService.vb +++ b/src/Workspaces/VisualBasic/Portable/Formatting/VisualBasicSyntaxFormattingService.vb @@ -16,35 +16,19 @@ Imports Microsoft.CodeAnalysis.Host.Mef #End If Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting -#If Not CODE_STYLE Then - - Friend Class VisualBasicSyntaxFormattingService -#Else - Friend Class VisualBasicSyntaxFormattingService -#End If - Inherits AbstractSyntaxFormattingService - Private ReadOnly _rules As ImmutableList(Of AbstractFormattingRule) + Friend Class VisualBasicSyntaxFormatting + Inherits AbstractSyntaxFormatting -#If CODE_STYLE Then - Public Shared ReadOnly Instance As New VisualBasicSyntaxFormattingService -#End If + Public Shared ReadOnly Instance As New VisualBasicSyntaxFormatting -#If Not CODE_STYLE Then - - - Public Sub New() -#Else - Public Sub New() -#End If - _rules = ImmutableList.Create(Of AbstractFormattingRule)( - New StructuredTriviaFormattingRule(), - New ElasticTriviaFormattingRule(), - New AdjustSpaceFormattingRule(), - New AlignTokensFormattingRule(), - New NodeBasedFormattingRule(), - DefaultOperationProvider.Instance) - End Sub + Private ReadOnly _rules As ImmutableList(Of AbstractFormattingRule) = ImmutableList.Create(Of AbstractFormattingRule)( + New StructuredTriviaFormattingRule(), + New ElasticTriviaFormattingRule(), + New AdjustSpaceFormattingRule(), + New AlignTokensFormattingRule(), + New NodeBasedFormattingRule(), + DefaultOperationProvider.Instance) Public Overrides Function GetDefaultFormattingRules() As IEnumerable(Of AbstractFormattingRule) Return _rules @@ -62,4 +46,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting Return New VisualBasicFormatEngine(root, options, formattingRules, startToken, endToken).Format(cancellationToken) End Function End Class + +#If Not CODE_STYLE Then + + Friend Class VisualBasicSyntaxFormattingService + Inherits VisualBasicSyntaxFormatting + Implements ISyntaxFormattingService + + + + Public Sub New() + End Sub + End Class +#End If End Namespace diff --git a/src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb b/src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb index e5274b39d6be0..23b611272d235 100644 --- a/src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb +++ b/src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb @@ -12,9 +12,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation Friend Class SpecialFormattingRule Inherits CompatAbstractFormattingRule - Private ReadOnly _indentStyle As FormattingOptions.IndentStyle + Private ReadOnly _indentStyle As FormattingOptions2.IndentStyle - Public Sub New(indentStyle As FormattingOptions.IndentStyle) + Public Sub New(indentStyle As FormattingOptions2.IndentStyle) _indentStyle = indentStyle End Sub diff --git a/src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.Indenter.vb b/src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.Indenter.vb index 969341de6fa91..39081b8765f6e 100644 --- a/src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.Indenter.vb +++ b/src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.Indenter.vb @@ -16,11 +16,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation indenter.Rules, indenter.Root, indenter.LineToBeIndented, indenter.Options.FormattingOptions, token) End Function - Protected Overrides Function CreateSmartTokenFormatter(indenter As Indenter) As ISmartTokenFormatter - Dim services = indenter.Document.Project.Solution.Workspace.Services + Protected Overrides Function CreateSmartTokenFormatter(document As Document, root As CompilationUnitSyntax, lineToBeIndented As TextLine, options As IndentationOptions) As ISmartTokenFormatter + Dim services = document.Project.Solution.Workspace.Services Dim formattingRuleFactory = services.GetService(Of IHostDependentFormattingRuleFactoryService)() - Dim rules = {New SpecialFormattingRule(indenter.Options.AutoFormattingOptions.IndentStyle), formattingRuleFactory.CreateRule(indenter.Document.Document, indenter.LineToBeIndented.Start)}.Concat(Formatter.GetDefaultFormattingRules(indenter.Document.Document)) - Return New VisualBasicSmartTokenFormatter(indenter.Options.FormattingOptions, rules, indenter.Root) + Dim rules = {New SpecialFormattingRule(options.AutoFormattingOptions.IndentStyle), formattingRuleFactory.CreateRule(document, lineToBeIndented.Start)}.Concat(VisualBasicSyntaxFormatting.Instance.GetDefaultFormattingRules()) + Return New VisualBasicSmartTokenFormatter(options.FormattingOptions, rules, root) End Function Protected Overrides Function GetDesiredIndentationWorker( diff --git a/src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.vb b/src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.vb index 99d57b198ddf9..a34c8cba6f539 100644 --- a/src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.vb +++ b/src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.vb @@ -32,7 +32,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation _specializedIndentationRule = specializedIndentationRule End Sub - Protected Overrides Function GetSpecializedIndentationFormattingRule(indentStyle As FormattingOptions.IndentStyle) As AbstractFormattingRule + Protected Overrides Function GetSpecializedIndentationFormattingRule(indentStyle As FormattingOptions2.IndentStyle) As AbstractFormattingRule Return If(_specializedIndentationRule, New SpecialFormattingRule(indentStyle)) End Function diff --git a/src/Workspaces/VisualBasic/Portable/Microsoft.CodeAnalysis.VisualBasic.Workspaces.vbproj b/src/Workspaces/VisualBasic/Portable/Microsoft.CodeAnalysis.VisualBasic.Workspaces.vbproj index de4b677c26798..74e8a9851cabc 100644 --- a/src/Workspaces/VisualBasic/Portable/Microsoft.CodeAnalysis.VisualBasic.Workspaces.vbproj +++ b/src/Workspaces/VisualBasic/Portable/Microsoft.CodeAnalysis.VisualBasic.Workspaces.vbproj @@ -13,6 +13,10 @@ .NET Compiler Platform ("Roslyn") support for analyzing Visual Basic projects and solutions. + + + + @@ -50,7 +54,6 @@ -