Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Apr 24, 2022
1 parent a71c5e7 commit 6f0c6da
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ namespace Microsoft.CodeAnalysis.Diagnostics;
/// </summary>
internal readonly struct CSharpAnalyzerOptionsProvider
{
/// <summary>
/// Document editorconfig options.
/// </summary>
private readonly AnalyzerConfigOptions _options;

/// <summary>
/// Fallback options - the default options in Code Style layer.
/// </summary>
private readonly IdeAnalyzerOptions _fallbackOptions;

public CSharpAnalyzerOptionsProvider(AnalyzerConfigOptions options, IdeAnalyzerOptions fallbackOptions)
Expand Down Expand Up @@ -80,13 +87,8 @@ private TValue GetOption<TValue>(Option2<TValue> option, TValue defaultValue)
private CSharpIdeCodeStyleOptions FallbackCodeStyleOptions
=> (CSharpIdeCodeStyleOptions?)_fallbackOptions.CodeStyleOptions ?? CSharpIdeCodeStyleOptions.Default;

#if CODE_STYLE
private static CSharpSimplifierOptions FallbackSimplifierOptions
=> CSharpSimplifierOptions.Default;
#else
private CSharpSimplifierOptions FallbackSimplifierOptions
=> (CSharpSimplifierOptions?)_fallbackOptions.CleanupOptions?.SimplifierOptions ?? CSharpSimplifierOptions.Default;
#endif

public static explicit operator CSharpAnalyzerOptionsProvider(AnalyzerOptionsProvider provider)
=> new(provider.GetAnalyzerConfigOptions(), provider.GetFallbackOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ Namespace Microsoft.CodeAnalysis.Diagnostics
''' Provides convenient access to Visual Basic editorconfig options with fallback to IDE default values.
''' </summary>
Friend Structure VisualBasicAnalyzerOptionsProvider
''' <summary>
''' Document editorconfig options.
''' </summary>
Private ReadOnly _options As AnalyzerConfigOptions

''' <summary>
''' Fallback options - the default options in Code Style layer.
''' </summary>
Private ReadOnly _fallbackOptions As IdeAnalyzerOptions

Public Sub New(options As AnalyzerConfigOptions, fallbackOptions As IdeAnalyzerOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ namespace Microsoft.CodeAnalysis.Diagnostics;
/// </summary>
internal readonly struct AnalyzerOptionsProvider
{
/// <summary>
/// Document editorconfig options.
/// </summary>
private readonly AnalyzerConfigOptions _options;

/// <summary>
/// Fallback options - the default options in Code Style layer.
/// </summary>
private readonly IdeAnalyzerOptions _fallbackOptions;

public AnalyzerOptionsProvider(AnalyzerConfigOptions options, IdeAnalyzerOptions fallbackOptions)
Expand Down Expand Up @@ -83,13 +90,8 @@ private TValue GetOption<TValue>(PerLanguageOption2<TValue> option, TValue defau
private IdeCodeStyleOptions.CommonOptions FallbackCodeStyleOptions
=> _fallbackOptions.CodeStyleOptions?.Common ?? IdeCodeStyleOptions.CommonOptions.Default;

#if CODE_STYLE
private static SimplifierOptions.CommonOptions FallbackSimplifierOptions
=> SimplifierOptions.CommonOptions.Default;
#else
private SimplifierOptions.CommonOptions FallbackSimplifierOptions
=> _fallbackOptions.CleanupOptions?.SimplifierOptions.Common ?? SimplifierOptions.CommonOptions.Default;
#endif

internal AnalyzerConfigOptions GetAnalyzerConfigOptions()
=> _options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ internal static async ValueTask<SyntaxFormattingOptions> GetSyntaxFormattingOpti
}

#if CODE_STYLE
#pragma warning disable IDE0060 // Fallback options currently unused in code style fixers
public static async ValueTask<LineFormattingOptions> GetLineFormattingOptionsAsync(this Document document, LineFormattingOptionsProvider fallbackOptionsProvider, CancellationToken cancellationToken)
#pragma warning restore
{
var syntaxTree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
return LineFormattingOptions.Create(document.Project.AnalyzerOptions.AnalyzerConfigOptionsProvider.GetOptions(syntaxTree), fallbackOptions: null);
Expand Down

0 comments on commit 6f0c6da

Please sign in to comment.