Skip to content

Commit

Permalink
Use OmniSharp LineFormatting fallback options in more places.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich authored and adamperlin committed Jul 19, 2022
1 parent 0c391e9 commit b94c28d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.DocumentationComments;
using Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.Options;
using Microsoft.CodeAnalysis.Formatting;

namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.DocumentationComments
Expand All @@ -19,12 +20,16 @@ internal OmniSharpDocumentationCommentOptionsWrapper(DocumentationCommentOptions

public OmniSharpDocumentationCommentOptionsWrapper(
bool autoXmlDocCommentGeneration,
int tabSize,
bool useTabs,
string newLine)
OmniSharpLineFormattingOptions lineFormattingOptions)
: this(new DocumentationCommentOptions()
{
LineFormatting = new LineFormattingOptions() { UseTabs = useTabs, TabSize = tabSize, IndentationSize = tabSize, NewLine = newLine },
LineFormatting = new LineFormattingOptions()
{
UseTabs = lineFormattingOptions.UseTabs,
TabSize = lineFormattingOptions.TabSize,
IndentationSize = lineFormattingOptions.IndentationSize,
NewLine = lineFormattingOptions.NewLine,
},
AutoXmlDocCommentGeneration = autoXmlDocCommentGeneration
})
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public OmniSharpOrganizeImportsOptionsWrapper(
{
}

public static async ValueTask<OmniSharpOrganizeImportsOptionsWrapper> FromDocumentAsync(Document document, CancellationToken cancellationToken)
=> new(await document.GetOrganizeImportsOptionsAsync(fallbackOptions: null, cancellationToken).ConfigureAwait(false));
public static async ValueTask<OmniSharpOrganizeImportsOptionsWrapper> FromDocumentAsync(Document document, OmniSharpOrganizeImportsOptionsWrapper fallbackOptions, CancellationToken cancellationToken)
=> new(await document.GetOrganizeImportsOptionsAsync(fallbackOptions.UnderlyingObject, cancellationToken).ConfigureAwait(false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeCleanup;
using Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.Options;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Simplification;

Expand All @@ -20,9 +21,21 @@ internal OmniSharpSyntaxFormattingOptionsWrapper(CodeCleanupOptions cleanupOptio
CleanupOptions = cleanupOptions;
}

public static async ValueTask<OmniSharpSyntaxFormattingOptionsWrapper> FromDocumentAsync(Document document, CancellationToken cancellationToken)
public static async ValueTask<OmniSharpSyntaxFormattingOptionsWrapper> FromDocumentAsync(Document document, OmniSharpLineFormattingOptions fallbackLineFormattingOptions, CancellationToken cancellationToken)
{
var cleanupOptions = await document.GetCodeCleanupOptionsAsync(CodeActionOptions.DefaultProvider, cancellationToken).ConfigureAwait(false);
var defaultOptions = CodeCleanupOptions.GetDefault(document.Project.LanguageServices);
var fallbackOptions = defaultOptions with
{
FormattingOptions = defaultOptions.FormattingOptions.With(new LineFormattingOptions
{
IndentationSize = fallbackLineFormattingOptions.IndentationSize,
TabSize = fallbackLineFormattingOptions.TabSize,
UseTabs = fallbackLineFormattingOptions.UseTabs,
NewLine = fallbackLineFormattingOptions.NewLine,
})
};

var cleanupOptions = await document.GetCodeCleanupOptionsAsync(fallbackOptions, cancellationToken).ConfigureAwait(false);
return new OmniSharpSyntaxFormattingOptionsWrapper(cleanupOptions);
}
}
Expand Down

0 comments on commit b94c28d

Please sign in to comment.