Skip to content

Commit

Permalink
Razor
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Mar 9, 2022
1 parent 1b1cfe1 commit 0a38518
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@

namespace Microsoft.CodeAnalysis.ExternalAccess.Razor
{
internal readonly record struct RazorFormattingOptions(bool UseTabs, int TabSize, int IndentationSize);
internal readonly record struct RazorFormattingOptions(
bool UseTabs,
int TabSize,
int IndentationSize,
FormattingOptions.IndentStyle IndentStyle,
bool FormatOnReturn,
bool FormatOnTyping,
bool FormatOnSemicolon,
bool FormatOnCloseBrace);

/// <summary>
/// Enables Razor to utilize Roslyn's C# formatting service.
Expand Down Expand Up @@ -64,12 +72,17 @@ public static async Task<ImmutableArray<TextChange>> GetFormattingChangesAsync(
var formattingService = document.GetRequiredLanguageService<IFormattingInteractionService>();
var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false);

// TODO: get auto-formatting options from Razor
var globalOptions = document.Project.Solution.Workspace.Services.GetRequiredService<ILegacyGlobalOptionsWorkspaceService>();

var indentationOptions = new IndentationOptions(
formattingOptions.With(options.UseTabs, options.TabSize, options.IndentationSize),
globalOptions.GlobalOptions.GetAutoFormattingOptions(document.Project.Language));
formattingOptions.With(
useTabs: options.UseTabs,
tabSize: options.TabSize,
indentationSize: options.IndentationSize),
new AutoFormattingOptions(
IndentStyle: options.IndentStyle,
FormatOnReturn: options.FormatOnReturn,
FormatOnTyping: options.FormatOnTyping,
FormatOnSemicolon: options.FormatOnSemicolon,
FormatOnCloseBrace: options.FormatOnCloseBrace));

return await formattingService.GetFormattingChangesAsync(document, typedChar, position, indentationOptions, cancellationToken).ConfigureAwait(false);
}
Expand Down

0 comments on commit 0a38518

Please sign in to comment.