Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Mar 17, 2022
1 parent 90c305a commit 96931cf
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ private static async Task AssertIndentUsingSmartTokenFormatterAsync(
var root = (await document.GetSyntaxRootAsync()) as CompilationUnitSyntax;

var options = new IndentationOptions(
CSharpSyntaxFormattingOptions.Default.With(useTabs: useTabs, tabSize: 4, indentationSize: 4),
CSharpSyntaxFormattingOptions.Default.With(new LineFormattingOptions(UseTabs: useTabs)),
AutoFormattingOptions.Default);

Assert.True(
Expand Down Expand Up @@ -1554,7 +1554,7 @@ private async Task AssertIndentNotUsingSmartTokenFormatterButUsingIndenterAsync(
var root = (await document.GetSyntaxRootAsync()) as CompilationUnitSyntax;

var options = new IndentationOptions(
CSharpSyntaxFormattingOptions.Default.With(useTabs: useTabs, tabSize: 4, indentationSize: 4),
CSharpSyntaxFormattingOptions.Default.With(new LineFormattingOptions(UseTabs: useTabs)),
new AutoFormattingOptions(IndentStyle: indentStyle));

Assert.False(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3588,7 +3588,7 @@ private static async Task AutoFormatOnMarkerAsync(string initialMarkup, string e
Assert.Equal(tokenKind, endToken.Kind());

var options = new IndentationOptions(
CSharpSyntaxFormattingOptions.Default.With(useTabs: useTabs, tabSize: 4, indentationSize: 4),
CSharpSyntaxFormattingOptions.Default.With(new LineFormattingOptions(UseTabs: useTabs)),
AutoFormattingOptions.Default);

var formatter = new CSharpSmartTokenFormatter(options, rules, root);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public static async Task<SyntaxFormattingOptions> GetInferredFormattingOptionsAs

indentationManager.GetIndentation(snapshot.TextBuffer, explicitFormat, out var convertTabsToSpaces, out var tabSize, out var indentSize);

return options.With(
useTabs: !convertTabsToSpaces,
indentationSize: indentSize,
tabSize: tabSize);
return options.With(new LineFormattingOptions(
UseTabs: !convertTabsToSpaces,
IndentationSize: indentSize,
TabSize: tabSize,
NewLine: options.NewLine));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ internal static class ExtractTypeHelpers
context,
cancellationToken).ConfigureAwait(false);

var newTypeFormattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(newTypeDocument, cancellationToken).ConfigureAwait(false);

var formattingService = newTypeDocument.GetLanguageService<INewDocumentFormattingService>();
if (formattingService is not null)
{
var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(newTypeDocument, cancellationToken).ConfigureAwait(false);
newTypeDocument = await formattingService.FormatNewDocumentAsync(newTypeDocument, hintDocument, formattingOptions, cancellationToken).ConfigureAwait(false);
newTypeDocument = await formattingService.FormatNewDocumentAsync(newTypeDocument, hintDocument, newTypeFormattingOptions, cancellationToken).ConfigureAwait(false);
}

var syntaxRoot = await newTypeDocument.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
Expand All @@ -104,9 +105,8 @@ internal static class ExtractTypeHelpers

newTypeDocument = newTypeDocument.WithSyntaxRoot(annotatedRoot);

var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(newTypeDocument, cancellationToken).ConfigureAwait(false);
var simplified = await Simplifier.ReduceAsync(newTypeDocument, cancellationToken: cancellationToken).ConfigureAwait(false);
var formattedDocument = await Formatter.FormatAsync(simplified, formattingOptions, cancellationToken).ConfigureAwait(false);
var formattedDocument = await Formatter.FormatAsync(simplified, newTypeFormattingOptions, cancellationToken).ConfigureAwait(false);

return (formattedDocument, typeAnnotation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,11 @@ public static async Task<SyntaxFormattingOptions> GetFormattingOptionsAsync(
{
// LSP doesn't currently support indent size as an option. However, except in special
// circumstances, indent size is usually equivalent to tab size, so we'll just set it.
formattingOptions = formattingOptions.With(
useTabs: !options.InsertSpaces,
tabSize: options.TabSize,
indentationSize: options.TabSize);
formattingOptions = formattingOptions.With(new LineFormattingOptions(
UseTabs: !options.InsertSpaces,
TabSize: options.TabSize,
IndentationSize: options.TabSize,
NewLine: formattingOptions.NewLine));
}

return formattingOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ public static SyntaxNode Format(
}

private static SyntaxFormattingOptions GetFormattingOptions(RazorIndentationOptions indentationOptions)
=> CSharpSyntaxFormattingOptions.Default.With(
useTabs: indentationOptions.UseTabs,
tabSize: indentationOptions.TabSize,
indentationSize: indentationOptions.IndentationSize);
=> CSharpSyntaxFormattingOptions.Default.With(new LineFormattingOptions(
UseTabs: indentationOptions.UseTabs,
TabSize: indentationOptions.TabSize,
IndentationSize: indentationOptions.IndentationSize,
NewLine: CSharpSyntaxFormattingOptions.Default.NewLine));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,9 @@ public static CSharpSyntaxFormattingOptions Create(AnalyzerConfigOptions options
wrappingKeepStatementsOnSingleLine: options.GetOption(CSharpFormattingOptions2.WrappingKeepStatementsOnSingleLine),
wrappingPreserveSingleLine: options.GetOption(CSharpFormattingOptions2.WrappingPreserveSingleLine));

public override SyntaxFormattingOptions With(bool useTabs, int tabSize, int indentationSize)
public override SyntaxFormattingOptions With(LineFormattingOptions lineFormatting)
=> new CSharpSyntaxFormattingOptions(
useTabs: useTabs,
tabSize: tabSize,
indentationSize: indentationSize,
NewLine,
lineFormatting,
SeparateImportDirectiveGroups,
Spacing,
SpacingAroundBinaryOperator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Threading;
using Microsoft.CodeAnalysis.Formatting.Rules;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Diagnostics;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Formatting.Rules;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text;

#if !CODE_STYLE
using Microsoft.CodeAnalysis.Host;
Expand Down Expand Up @@ -80,7 +79,7 @@ protected SyntaxFormattingOptions(
SeparateImportDirectiveGroups = separateImportDirectiveGroups;
}

public abstract SyntaxFormattingOptions With(bool useTabs, int tabSize, int indentationSize);
public abstract SyntaxFormattingOptions With(LineFormattingOptions lineFormatting);

public bool UseTabs => LineFormatting.UseTabs;
public int TabSize => LineFormatting.TabSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting
separateImportDirectiveGroups:=options.GetOption(GenerationOptions.SeparateImportDirectiveGroups))
End Function

Public Overrides Function [With](useTabs As Boolean, tabSize As Integer, indentationSize As Integer) As SyntaxFormattingOptions
Public Overrides Function [With](lineFormatting As LineFormattingOptions) As SyntaxFormattingOptions
Return New VisualBasicSyntaxFormattingOptions(
useTabs:=useTabs,
tabSize:=tabSize,
indentationSize:=indentationSize,
newLine:=NewLine,
lineFormatting:=lineFormatting,
separateImportDirectiveGroups:=SeparateImportDirectiveGroups)
End Function
End Class
Expand Down

0 comments on commit 96931cf

Please sign in to comment.