Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Mar 11, 2022
1 parent cc8cbf8 commit 0f52cba
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -29,8 +30,13 @@ public static async ValueTask<OmniSharpDocumentationCommentOptionsWrapper> 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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,32 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.Razor
/// </summary>
internal static class RazorCSharpFormattingInteractionService
{
/// <summary>
/// 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.
/// </summary>
[Obsolete("Use the other overload")]
public static Task<ImmutableArray<TextChange>> GetFormattingChangesAsync(
Document document,
char typedChar,
int position,
DocumentOptionSet documentOptions,
CancellationToken cancellationToken)
{
Contract.ThrowIfFalse(document.Project.Language is LanguageNames.CSharp);
var formattingService = document.GetRequiredLanguageService<IFormattingInteractionService>();
var services = document.Project.Solution.Workspace.Services;

var globalOptions = document.Project.Solution.Workspace.Services.GetRequiredService<ILegacyGlobalOptionsWorkspaceService>();

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);
}

/// <summary>
/// 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
Expand All @@ -38,9 +64,12 @@ 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),
AutoFormattingOptions.Default); // TODO
globalOptions.GlobalOptions.GetAutoFormattingOptions(document.Project.Language));

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

0 comments on commit 0f52cba

Please sign in to comment.