diff --git a/src/Analyzers/Core/CodeFixes/RemoveUnnecessaryImports/AbstractRemoveUnnecessaryImportsCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/RemoveUnnecessaryImports/AbstractRemoveUnnecessaryImportsCodeFixProvider.cs index ef34d9c820201..01d12be50f4d8 100644 --- a/src/Analyzers/Core/CodeFixes/RemoveUnnecessaryImports/AbstractRemoveUnnecessaryImportsCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/RemoveUnnecessaryImports/AbstractRemoveUnnecessaryImportsCodeFixProvider.cs @@ -37,7 +37,11 @@ public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) protected abstract string GetTitle(); +#if CODE_STYLE private async Task RemoveUnnecessaryImportsAsync( +#else + private static async Task RemoveUnnecessaryImportsAsync( +#endif Document document, CancellationToken cancellationToken) { diff --git a/src/EditorFeatures/Core/CommentSelection/AbstractCommentSelectionBase.cs b/src/EditorFeatures/Core/CommentSelection/AbstractCommentSelectionBase.cs index fecd79365b410..a80f3f720441e 100644 --- a/src/EditorFeatures/Core/CommentSelection/AbstractCommentSelectionBase.cs +++ b/src/EditorFeatures/Core/CommentSelection/AbstractCommentSelectionBase.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; +using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; @@ -197,8 +198,9 @@ private static Document Format(ICommentSelectionService service, ITextSnapshot s return null; } + var formattingOptions = SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).WaitAndGetResult(cancellationToken); var textSpans = changes.SelectAsArray(change => change.Span.ToTextSpan()); - return service.FormatAsync(document, textSpans, cancellationToken).WaitAndGetResult(cancellationToken); + return service.FormatAsync(document, textSpans, formattingOptions, cancellationToken).WaitAndGetResult(cancellationToken); } /// diff --git a/src/Features/CSharp/Portable/Wrapping/CSharpSyntaxWrappingOptions.cs b/src/Features/CSharp/Portable/Wrapping/CSharpSyntaxWrappingOptions.cs index 467df8966f241..b426cf79f8422 100644 --- a/src/Features/CSharp/Portable/Wrapping/CSharpSyntaxWrappingOptions.cs +++ b/src/Features/CSharp/Portable/Wrapping/CSharpSyntaxWrappingOptions.cs @@ -16,22 +16,18 @@ internal sealed class CSharpSyntaxWrappingOptions : SyntaxWrappingOptions public readonly bool NewLinesForBracesInObjectCollectionArrayInitializers; public CSharpSyntaxWrappingOptions( - bool useTabs, - int tabSize, - string newLine, + SyntaxFormattingOptions formattingOptions, int wrappingColumn, OperatorPlacementWhenWrappingPreference operatorPlacement, bool newLinesForBracesInObjectCollectionArrayInitializers) - : base(useTabs, tabSize, newLine, wrappingColumn, operatorPlacement) + : base(formattingOptions, wrappingColumn, operatorPlacement) { NewLinesForBracesInObjectCollectionArrayInitializers = newLinesForBracesInObjectCollectionArrayInitializers; } public static CSharpSyntaxWrappingOptions Create(AnalyzerConfigOptions options, CodeActionOptions ideOptions) => new( - useTabs: options.GetOption(FormattingOptions2.UseTabs), - tabSize: options.GetOption(FormattingOptions2.TabSize), - newLine: options.GetOption(FormattingOptions2.NewLine), + CSharpSyntaxFormattingOptions.Create(options), operatorPlacement: options.GetOption(CodeStyleOptions2.OperatorPlacementWhenWrapping), wrappingColumn: ideOptions.WrappingColumn, newLinesForBracesInObjectCollectionArrayInitializers: options.GetOption(CSharpFormattingOptions2.NewLinesForBracesInObjectCollectionArrayInitializers)); diff --git a/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs b/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs index 79a9778e0f8c9..48915313eab50 100644 --- a/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs +++ b/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs @@ -417,9 +417,11 @@ private static async Task> FindChangeSignatureR { var updatedDoc = currentSolution.GetRequiredDocument(docId).WithSyntaxRoot(updatedRoots[docId]); var addImportOptions = await AddImportPlacementOptions.FromDocumentAsync(updatedDoc, cancellationToken).ConfigureAwait(false); + var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(updatedDoc, cancellationToken).ConfigureAwait(false); + var docWithImports = await ImportAdder.AddImportsFromSymbolAnnotationAsync(updatedDoc, addImportOptions, cancellationToken).ConfigureAwait(false); var reducedDoc = await Simplifier.ReduceAsync(docWithImports, Simplifier.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false); - var formattedDoc = await Formatter.FormatAsync(reducedDoc, SyntaxAnnotation.ElasticAnnotation, cancellationToken: cancellationToken).ConfigureAwait(false); + var formattedDoc = await Formatter.FormatAsync(reducedDoc, SyntaxAnnotation.ElasticAnnotation, formattingOptions, cancellationToken).ConfigureAwait(false); currentSolution = currentSolution.WithDocumentSyntaxRoot(docId, (await formattedDoc.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false))!); } diff --git a/src/Features/Core/Portable/CodeRefactorings/SyncNamespace/AbstractChangeNamespaceService.cs b/src/Features/Core/Portable/CodeRefactorings/SyncNamespace/AbstractChangeNamespaceService.cs index 4cb3e618af696..8e2fa98735110 100644 --- a/src/Features/Core/Portable/CodeRefactorings/SyncNamespace/AbstractChangeNamespaceService.cs +++ b/src/Features/Core/Portable/CodeRefactorings/SyncNamespace/AbstractChangeNamespaceService.cs @@ -651,7 +651,7 @@ private static async Task FixReferencingDocumentAsync( await FixReferencesAsync(document, changeNamespaceService, addImportService, refLocations, newNamespaceParts, cancellationToken) .ConfigureAwait(false); - var optionSet = await documentWithRefFixed.GetOptionsAsync(cancellationToken).ConfigureAwait(false); + var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); var addImportsOptions = await AddImportPlacementOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); var documentWithAdditionalImports = await AddImportsInContainersAsync( @@ -663,9 +663,10 @@ await FixReferencesAsync(document, changeNamespaceService, addImportService, ref cancellationToken).ConfigureAwait(false); // Need to invoke formatter explicitly since we are doing the diff merge ourselves. - var formattedDocument = await Formatter.FormatAsync(documentWithAdditionalImports, Formatter.Annotation, optionSet, cancellationToken) + var formattedDocument = await Formatter.FormatAsync(documentWithAdditionalImports, Formatter.Annotation, formattingOptions, cancellationToken) .ConfigureAwait(false); + var optionSet = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); return await Simplifier.ReduceAsync(formattedDocument, optionSet, cancellationToken).ConfigureAwait(false); } diff --git a/src/Features/Core/Portable/CommentSelection/AbstractCommentSelectionService.cs b/src/Features/Core/Portable/CommentSelection/AbstractCommentSelectionService.cs index 5efd09ce5313b..9d779836ebe77 100644 --- a/src/Features/Core/Portable/CommentSelection/AbstractCommentSelectionService.cs +++ b/src/Features/Core/Portable/CommentSelection/AbstractCommentSelectionService.cs @@ -20,12 +20,12 @@ internal abstract class AbstractCommentSelectionService : ICommentSelectionServi public abstract string SingleLineCommentString { get; } public abstract bool SupportsBlockComment { get; } - public Task FormatAsync(Document document, ImmutableArray changes, CancellationToken cancellationToken) + public Task FormatAsync(Document document, ImmutableArray changes, SyntaxFormattingOptions formattingOptions, CancellationToken cancellationToken) { var root = document.GetRequiredSyntaxRootSynchronously(cancellationToken); var formattingSpans = changes.Select(s => CommonFormattingHelpers.GetFormattingSpan(root, s)); - return Formatter.FormatAsync(document, formattingSpans, cancellationToken: cancellationToken); + return Formatter.FormatAsync(document, formattingSpans, formattingOptions, rules: null, cancellationToken); } public Task GetInfoAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken) diff --git a/src/Features/Core/Portable/CommentSelection/ICommentSelectionService.cs b/src/Features/Core/Portable/CommentSelection/ICommentSelectionService.cs index 7c53adf59b2f2..49858bbf8a298 100644 --- a/src/Features/Core/Portable/CommentSelection/ICommentSelectionService.cs +++ b/src/Features/Core/Portable/CommentSelection/ICommentSelectionService.cs @@ -5,6 +5,7 @@ using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Text; @@ -14,6 +15,6 @@ internal interface ICommentSelectionService : ILanguageService { Task GetInfoAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken); - Task FormatAsync(Document document, ImmutableArray changes, CancellationToken cancellationToken); + Task FormatAsync(Document document, ImmutableArray changes, SyntaxFormattingOptions formattingOptions, CancellationToken cancellationToken); } } diff --git a/src/Features/Core/Portable/Completion/Providers/AbstractMemberInsertingCompletionProvider.cs b/src/Features/Core/Portable/Completion/Providers/AbstractMemberInsertingCompletionProvider.cs index 37fd238b56cce..f67477d53f949 100644 --- a/src/Features/Core/Portable/Completion/Providers/AbstractMemberInsertingCompletionProvider.cs +++ b/src/Features/Core/Portable/Completion/Providers/AbstractMemberInsertingCompletionProvider.cs @@ -98,7 +98,8 @@ private async Task DetermineNewDocumentAsync(Document document, Comple var declaration = GetSyntax(newRoot.FindToken(destinationSpan.End)); document = document.WithSyntaxRoot(newRoot.ReplaceNode(declaration, declaration.WithAdditionalAnnotations(_annotation))); - return await Formatter.FormatAsync(document, _annotation, cancellationToken: cancellationToken).ConfigureAwait(false); + var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); + return await Formatter.FormatAsync(document, _annotation, formattingOptions, cancellationToken).ConfigureAwait(false); } private async Task GenerateMemberAndUsingsAsync( @@ -179,8 +180,10 @@ private TextSpan ComputeDestinationSpan(SyntaxNode insertionRoot) private async Task GenerateInsertionTextAsync( Document memberContainingDocument, CancellationToken cancellationToken) { + var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(memberContainingDocument, cancellationToken).ConfigureAwait(false); + memberContainingDocument = await Simplifier.ReduceAsync(memberContainingDocument, Simplifier.Annotation, optionSet: null, cancellationToken).ConfigureAwait(false); - memberContainingDocument = await Formatter.FormatAsync(memberContainingDocument, Formatter.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false); + memberContainingDocument = await Formatter.FormatAsync(memberContainingDocument, Formatter.Annotation, formattingOptions, cancellationToken).ConfigureAwait(false); var root = await memberContainingDocument.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); return root.GetAnnotatedNodes(_annotation).Single().ToString().Trim(); diff --git a/src/Features/Core/Portable/EncapsulateField/AbstractEncapsulateFieldService.cs b/src/Features/Core/Portable/EncapsulateField/AbstractEncapsulateFieldService.cs index af5430aa1b366..f7f7226721e08 100644 --- a/src/Features/Core/Portable/EncapsulateField/AbstractEncapsulateFieldService.cs +++ b/src/Features/Core/Portable/EncapsulateField/AbstractEncapsulateFieldService.cs @@ -201,14 +201,16 @@ private async Task EncapsulateFieldAsync( var markFieldPrivate = field.DeclaredAccessibility != Accessibility.Private; var rewrittenFieldDeclaration = await RewriteFieldNameAndAccessibilityAsync(finalFieldName, markFieldPrivate, document, declarationAnnotation, cancellationToken).ConfigureAwait(false); - document = await Formatter.FormatAsync(document.WithSyntaxRoot(rewrittenFieldDeclaration), Formatter.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false); + var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); + document = await Formatter.FormatAsync(document.WithSyntaxRoot(rewrittenFieldDeclaration), Formatter.Annotation, formattingOptions, cancellationToken).ConfigureAwait(false); solution = document.Project.Solution; foreach (var linkedDocumentId in document.GetLinkedDocumentIds()) { var linkedDocument = solution.GetDocument(linkedDocumentId); + var linkedDocumentFormattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(linkedDocument, cancellationToken).ConfigureAwait(false); var updatedLinkedRoot = await RewriteFieldNameAndAccessibilityAsync(finalFieldName, markFieldPrivate, linkedDocument, declarationAnnotation, cancellationToken).ConfigureAwait(false); - var updatedLinkedDocument = await Formatter.FormatAsync(linkedDocument.WithSyntaxRoot(updatedLinkedRoot), Formatter.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false); + var updatedLinkedDocument = await Formatter.FormatAsync(linkedDocument.WithSyntaxRoot(updatedLinkedRoot), Formatter.Annotation, linkedDocumentFormattingOptions, cancellationToken).ConfigureAwait(false); solution = updatedLinkedDocument.Project.Solution; } @@ -230,7 +232,7 @@ private async Task EncapsulateFieldAsync( document); var solutionWithProperty = await AddPropertyAsync( - document, document.Project.Solution, field, generatedProperty, cancellationToken).ConfigureAwait(false); + document, document.Project.Solution, field, generatedProperty, formattingOptions, cancellationToken).ConfigureAwait(false); return solutionWithProperty; } @@ -316,7 +318,7 @@ private ISet GetConstructorLocations(INamedTypeSymbol containingType) internal abstract IEnumerable GetConstructorNodes(INamedTypeSymbol containingType); - protected static async Task AddPropertyAsync(Document document, Solution destinationSolution, IFieldSymbol field, IPropertySymbol property, CancellationToken cancellationToken) + protected static async Task AddPropertyAsync(Document document, Solution destinationSolution, IFieldSymbol field, IPropertySymbol property, SyntaxFormattingOptions formattingOptions, CancellationToken cancellationToken) { var codeGenerationService = document.GetLanguageService(); @@ -329,7 +331,7 @@ protected static async Task AddPropertyAsync(Document document, Soluti var updatedDocument = await codeGenerationService.AddPropertyAsync( destinationSolution, destination, property, context, cancellationToken).ConfigureAwait(false); - updatedDocument = await Formatter.FormatAsync(updatedDocument, Formatter.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false); + updatedDocument = await Formatter.FormatAsync(updatedDocument, Formatter.Annotation, formattingOptions, cancellationToken).ConfigureAwait(false); updatedDocument = await Simplifier.ReduceAsync(updatedDocument, cancellationToken: cancellationToken).ConfigureAwait(false); return updatedDocument.Project.Solution; diff --git a/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs b/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs index 11ca09855708a..0ea7726d5142a 100644 --- a/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs +++ b/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs @@ -287,10 +287,14 @@ private static async Task GetFormattedSolutionAsync(Solution unformatt foreach (var documentId in documentIds) { var document = formattedSolution.GetDocument(documentId); + + var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); + var formattedDocument = await Formatter.FormatAsync( document, Formatter.Annotation, - cancellationToken: cancellationToken).ConfigureAwait(false); + formattingOptions, + cancellationToken).ConfigureAwait(false); var simplifiedDocument = await Simplifier.ReduceAsync( formattedDocument, diff --git a/src/Features/Core/Portable/IntroduceVariable/AbstractIntroduceVariableService.IntroduceVariableAllOccurrenceCodeAction.cs b/src/Features/Core/Portable/IntroduceVariable/AbstractIntroduceVariableService.IntroduceVariableAllOccurrenceCodeAction.cs index 4dc4d1a6a2f64..b48273827f380 100644 --- a/src/Features/Core/Portable/IntroduceVariable/AbstractIntroduceVariableService.IntroduceVariableAllOccurrenceCodeAction.cs +++ b/src/Features/Core/Portable/IntroduceVariable/AbstractIntroduceVariableService.IntroduceVariableAllOccurrenceCodeAction.cs @@ -30,8 +30,9 @@ internal IntroduceVariableAllOccurrenceCodeAction( protected override async Task PostProcessChangesAsync(Document document, CancellationToken cancellationToken) { + var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); document = await Simplifier.ReduceAsync(document, Simplifier.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false); - document = await Formatter.FormatAsync(document, Formatter.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false); + document = await Formatter.FormatAsync(document, Formatter.Annotation, formattingOptions, cancellationToken).ConfigureAwait(false); document = await CaseCorrector.CaseCorrectAsync(document, CaseCorrector.Annotation, cancellationToken).ConfigureAwait(false); return document; } diff --git a/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceService.cs b/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceService.cs index e97d1133a52c4..11e92a4f545f9 100644 --- a/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceService.cs +++ b/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceService.cs @@ -278,7 +278,8 @@ private static async Task MoveTypeToNamespaceAsync( private static async Task PropagateChangeToLinkedDocumentsAsync(Document document, CancellationToken cancellationToken) { // Need to make sure elastic trivia is formatted properly before pushing the text to other documents. - var formattedDocument = await Formatter.FormatAsync(document, SyntaxAnnotation.ElasticAnnotation, cancellationToken: cancellationToken).ConfigureAwait(false); + var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); + var formattedDocument = await Formatter.FormatAsync(document, SyntaxAnnotation.ElasticAnnotation, formattingOptions, cancellationToken).ConfigureAwait(false); var formattedText = await formattedDocument.GetTextAsync(cancellationToken).ConfigureAwait(false); var solution = formattedDocument.Project.Solution; diff --git a/src/Features/Core/Portable/Shared/Utilities/ExtractTypeHelpers.cs b/src/Features/Core/Portable/Shared/Utilities/ExtractTypeHelpers.cs index c075b5a90e15c..46694e12c7e5f 100644 --- a/src/Features/Core/Portable/Shared/Utilities/ExtractTypeHelpers.cs +++ b/src/Features/Core/Portable/Shared/Utilities/ExtractTypeHelpers.cs @@ -103,8 +103,9 @@ internal static class ExtractTypeHelpers newTypeDocument = newTypeDocument.WithSyntaxRoot(annotatedRoot); + var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(newTypeDocument, cancellationToken).ConfigureAwait(false); var simplified = await Simplifier.ReduceAsync(newTypeDocument, cancellationToken: cancellationToken).ConfigureAwait(false); - var formattedDocument = await Formatter.FormatAsync(simplified, cancellationToken: cancellationToken).ConfigureAwait(false); + var formattedDocument = await Formatter.FormatAsync(simplified, formattingOptions, cancellationToken).ConfigureAwait(false); return (formattedDocument, typeAnnotation); } diff --git a/src/Features/Core/Portable/Wrapping/AbstractCodeActionComputer.cs b/src/Features/Core/Portable/Wrapping/AbstractCodeActionComputer.cs index 09f3e7c4a5fe3..15b740e11a519 100644 --- a/src/Features/Core/Portable/Wrapping/AbstractCodeActionComputer.cs +++ b/src/Features/Core/Portable/Wrapping/AbstractCodeActionComputer.cs @@ -158,7 +158,7 @@ private async Task FormatDocumentAsync(SyntaxNode rewrittenRoot, TextS { var newDocument = OriginalDocument.WithSyntaxRoot(rewrittenRoot); var formattedDocument = await Formatter.FormatAsync( - newDocument, spanToFormat, cancellationToken: CancellationToken).ConfigureAwait(false); + newDocument, spanToFormat, Options.FormattingOptions, CancellationToken).ConfigureAwait(false); return formattedDocument; } diff --git a/src/Features/Core/Portable/Wrapping/SyntaxWrappingOptions.cs b/src/Features/Core/Portable/Wrapping/SyntaxWrappingOptions.cs index a7a2883923fd4..763fe50c8a34e 100644 --- a/src/Features/Core/Portable/Wrapping/SyntaxWrappingOptions.cs +++ b/src/Features/Core/Portable/Wrapping/SyntaxWrappingOptions.cs @@ -2,33 +2,29 @@ // 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.CodeActions; using Microsoft.CodeAnalysis.CodeStyle; -using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Formatting; namespace Microsoft.CodeAnalysis.Wrapping { internal abstract class SyntaxWrappingOptions { - public readonly bool UseTabs; - public readonly int TabSize; - public readonly string NewLine; + public readonly SyntaxFormattingOptions FormattingOptions; public readonly int WrappingColumn; public readonly OperatorPlacementWhenWrappingPreference OperatorPlacement; protected SyntaxWrappingOptions( - bool useTabs, - int tabSize, - string newLine, + SyntaxFormattingOptions formattingOptions, int wrappingColumn, OperatorPlacementWhenWrappingPreference operatorPlacement) { - UseTabs = useTabs; - TabSize = tabSize; - NewLine = newLine; + FormattingOptions = formattingOptions; WrappingColumn = wrappingColumn; OperatorPlacement = operatorPlacement; } + + public bool UseTabs => FormattingOptions.UseTabs; + public int TabSize => FormattingOptions.TabSize; + public string NewLine => FormattingOptions.NewLine; } } diff --git a/src/Features/VisualBasic/Portable/Wrapping/VisualBasicSyntaxWrappingOptions.vb b/src/Features/VisualBasic/Portable/Wrapping/VisualBasicSyntaxWrappingOptions.vb index 5d843197b09b7..6c5fd2b5677dc 100644 --- a/src/Features/VisualBasic/Portable/Wrapping/VisualBasicSyntaxWrappingOptions.vb +++ b/src/Features/VisualBasic/Portable/Wrapping/VisualBasicSyntaxWrappingOptions.vb @@ -7,6 +7,7 @@ Imports Microsoft.CodeAnalysis.CodeStyle Imports Microsoft.CodeAnalysis.Wrapping Imports Microsoft.CodeAnalysis.Diagnostics Imports Microsoft.CodeAnalysis.Formatting +Imports Microsoft.CodeAnalysis.VisualBasic.Formatting Namespace Microsoft.CodeAnalysis.VisualBasic.Wrapping @@ -14,20 +15,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Wrapping Inherits SyntaxWrappingOptions Public Sub New( - useTabs As Boolean, - tabSize As Integer, - newLine As String, + formattingOptions As SyntaxFormattingOptions, wrappingColumn As Integer, operatorPlacement As OperatorPlacementWhenWrappingPreference) - MyBase.New(useTabs, tabSize, newLine, wrappingColumn, operatorPlacement) + MyBase.New(formattingOptions, wrappingColumn, operatorPlacement) End Sub Public Shared Function Create(options As AnalyzerConfigOptions, ideOptions As CodeActionOptions) As VisualBasicSyntaxWrappingOptions Return New VisualBasicSyntaxWrappingOptions( - useTabs:=options.GetOption(FormattingOptions2.UseTabs), - tabSize:=options.GetOption(FormattingOptions2.TabSize), - newLine:=options.GetOption(FormattingOptions2.NewLine), + formattingOptions:=VisualBasicSyntaxFormattingOptions.Create(options), operatorPlacement:=options.GetOption(CodeStyleOptions2.OperatorPlacementWhenWrapping), wrappingColumn:=ideOptions.WrappingColumn) End Function diff --git a/src/Tools/ExternalAccess/FSharp/Internal/CommentSelection/FSharpCommentSelectionService.cs b/src/Tools/ExternalAccess/FSharp/Internal/CommentSelection/FSharpCommentSelectionService.cs index e0080070f65df..41ef91a2f850f 100644 --- a/src/Tools/ExternalAccess/FSharp/Internal/CommentSelection/FSharpCommentSelectionService.cs +++ b/src/Tools/ExternalAccess/FSharp/Internal/CommentSelection/FSharpCommentSelectionService.cs @@ -10,6 +10,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CommentSelection; +using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Text; @@ -25,7 +26,7 @@ public FSharpCommentSelectionService() { } - public Task FormatAsync(Document document, ImmutableArray changes, CancellationToken cancellationToken) + public Task FormatAsync(Document document, ImmutableArray changes, SyntaxFormattingOptions formattingOptions, CancellationToken cancellationToken) { return Task.FromResult(document); } diff --git a/src/Workspaces/Core/Portable/CodeActions/CodeAction.cs b/src/Workspaces/Core/Portable/CodeActions/CodeAction.cs index 507618035aba8..1a61ead515f00 100644 --- a/src/Workspaces/Core/Portable/CodeActions/CodeAction.cs +++ b/src/Workspaces/Core/Portable/CodeActions/CodeAction.cs @@ -284,6 +284,7 @@ internal static async Task CleanupDocumentAsync( if (document.SupportsSyntaxTree) { var addImportOptions = await AddImportPlacementOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); + var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); document = await ImportAdder.AddImportsFromSymbolAnnotationAsync( document, Simplifier.AddImportsAnnotation, addImportOptions, cancellationToken).ConfigureAwait(false); @@ -291,10 +292,10 @@ internal static async Task CleanupDocumentAsync( document = await Simplifier.ReduceAsync(document, Simplifier.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false); // format any node with explicit formatter annotation - document = await Formatter.FormatAsync(document, Formatter.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false); + document = await Formatter.FormatAsync(document, Formatter.Annotation, formattingOptions, cancellationToken).ConfigureAwait(false); // format any elastic whitespace - document = await Formatter.FormatAsync(document, SyntaxAnnotation.ElasticAnnotation, cancellationToken: cancellationToken).ConfigureAwait(false); + document = await Formatter.FormatAsync(document, SyntaxAnnotation.ElasticAnnotation, formattingOptions, cancellationToken).ConfigureAwait(false); document = await CaseCorrector.CaseCorrectAsync(document, CaseCorrector.Annotation, cancellationToken).ConfigureAwait(false); } diff --git a/src/Workspaces/Core/Portable/Rename/ConflictEngine/RenamedSpansTracker.cs b/src/Workspaces/Core/Portable/Rename/ConflictEngine/RenamedSpansTracker.cs index d4a54f03c5dcc..81103af8b8978 100644 --- a/src/Workspaces/Core/Portable/Rename/ConflictEngine/RenamedSpansTracker.cs +++ b/src/Workspaces/Core/Portable/Rename/ConflictEngine/RenamedSpansTracker.cs @@ -158,8 +158,10 @@ internal async Task SimplifyAsync(Solution solution, IEnumerable