diff --git a/src/Tools/ExternalAccess/OmniSharp/DocumentationComments/OmniSharpDocumentationCommentOptionsWrapper.cs b/src/Tools/ExternalAccess/OmniSharp/DocumentationComments/OmniSharpDocumentationCommentOptionsWrapper.cs index 29cd5c5a935a4..2a1259aa52ca9 100644 --- a/src/Tools/ExternalAccess/OmniSharp/DocumentationComments/OmniSharpDocumentationCommentOptionsWrapper.cs +++ b/src/Tools/ExternalAccess/OmniSharp/DocumentationComments/OmniSharpDocumentationCommentOptionsWrapper.cs @@ -5,6 +5,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.DocumentationComments; +using Microsoft.CodeAnalysis.Formatting; namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.DocumentationComments { @@ -29,8 +30,13 @@ public static async ValueTask FromD bool autoXmlDocCommentGeneration, CancellationToken cancellationToken) { - var documentOptions = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); - return new(DocumentationCommentOptions.From(documentOptions) with { AutoXmlDocCommentGeneration = autoXmlDocCommentGeneration }); + var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); + + return new(new DocumentationCommentOptions( + AutoXmlDocCommentGeneration: autoXmlDocCommentGeneration, + TabSize: formattingOptions.TabSize, + UseTabs: formattingOptions.UseTabs, + NewLine: formattingOptions.NewLine)); } } } diff --git a/src/Tools/ExternalAccess/Razor/RazorCSharpFormattingInteractionService.cs b/src/Tools/ExternalAccess/Razor/RazorCSharpFormattingInteractionService.cs index 5b3ae0555f068..17cbcfedf4f45 100644 --- a/src/Tools/ExternalAccess/Razor/RazorCSharpFormattingInteractionService.cs +++ b/src/Tools/ExternalAccess/Razor/RazorCSharpFormattingInteractionService.cs @@ -22,6 +22,32 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.Razor /// internal static class RazorCSharpFormattingInteractionService { + /// + /// Returns the text changes necessary to format the document after the user enters a + /// character. The position provided is the position of the caret in the document after + /// the character been inserted into the document. + /// + [Obsolete("Use the other overload")] + public static Task> GetFormattingChangesAsync( + Document document, + char typedChar, + int position, + DocumentOptionSet documentOptions, + CancellationToken cancellationToken) + { + Contract.ThrowIfFalse(document.Project.Language is LanguageNames.CSharp); + var formattingService = document.GetRequiredLanguageService(); + var services = document.Project.Solution.Workspace.Services; + + var globalOptions = document.Project.Solution.Workspace.Services.GetRequiredService(); + + var indentationOptions = new IndentationOptions( + SyntaxFormattingOptions.Create(documentOptions, services, document.Project.Language), + globalOptions.GlobalOptions.GetAutoFormattingOptions(document.Project.Language)); + + return formattingService.GetFormattingChangesAsync(document, typedChar, position, indentationOptions, cancellationToken); + } + /// /// Returns the text changes necessary to format the document after the user enters a /// character. The position provided is the position of the caret in the document after @@ -38,9 +64,12 @@ public static async Task> GetFormattingChangesAsync( var formattingService = document.GetRequiredLanguageService(); var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); + // TODO: get auto-formatting options from Razor + var globalOptions = document.Project.Solution.Workspace.Services.GetRequiredService(); + var indentationOptions = new IndentationOptions( formattingOptions.With(options.UseTabs, options.TabSize, options.IndentationSize), - AutoFormattingOptions.Default); // TODO + globalOptions.GlobalOptions.GetAutoFormattingOptions(document.Project.Language)); return await formattingService.GetFormattingChangesAsync(document, typedChar, position, indentationOptions, cancellationToken).ConfigureAwait(false); }