Permalink
Browse files

Merge pull request #32845 from sharwell/format-perf

Performance improvements for formatting analyzer
  • Loading branch information...
sharwell committed Feb 9, 2019
2 parents c818853 + 735f9df commit d260ee0c20ed31e1ef057bdc179a451e76cf24da
Showing with 1,013 additions and 709 deletions.
  1. +6 −6 src/CodeStyle/Core/Analyzers/Formatting/Formatter.cs
  2. +7 −7 src/CodeStyle/Core/Analyzers/Microsoft.CodeAnalysis.CodeStyle.csproj
  3. +9 −9 src/EditorFeatures/CSharp/AutomaticCompletion/Sessions/CurlyBraceCompletionSession.cs
  4. +1 −1 src/EditorFeatures/CSharp/Formatting/CSharpEditorFormattingService.PasteFormattingRule.cs
  5. +7 −7 src/EditorFeatures/CSharp/Formatting/CSharpEditorFormattingService.cs
  6. +1 −1 src/EditorFeatures/CSharp/Formatting/Indentation/CSharpIndentationService.Indenter.cs
  7. +6 −6 src/EditorFeatures/CSharp/Formatting/Indentation/CSharpIndentationService.cs
  8. +7 −7 src/EditorFeatures/CSharp/Formatting/Indentation/SmartTokenFormatter.cs
  9. +3 −3 src/EditorFeatures/CSharp/Formatting/Indentation/SmartTokenFormatterCommandHandler.cs
  10. +2 −2 src/EditorFeatures/CSharp/Formatting/TypingFormattingRule.cs
  11. +4 −4 src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTestBase.cs
  12. +1 −1 src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartTokenFormatterFormatRangeTests.cs
  13. +1 −1 src/EditorFeatures/Core/Implementation/AutomaticCompletion/Extensions.cs
  14. +5 −5 ...rFeatures/Core/Implementation/Formatting/Indentation/AbstractSmartTokenFormatterCommandHandler.cs
  15. +2 −2 src/EditorFeatures/Core/Implementation/SmartIndent/AbstractIndentationService.AbstractIndenter.cs
  16. +3 −3 src/EditorFeatures/Core/Implementation/SmartIndent/AbstractIndentationService.cs
  17. +2 −2 src/EditorFeatures/Core/Shared/Extensions/ITextSnapshotExtensions.cs
  18. +4 −4 src/EditorFeatures/TestUtilities/TestExportProvider.cs
  19. +2 −2 src/EditorFeatures/TestUtilities/Workspaces/TestFormattingRuleFactoryServiceFactory.cs
  20. +2 −2 src/EditorFeatures/VisualBasic/Formatting/Indentation/SmartTokenFormatter.vb
  21. +4 −4 src/EditorFeatures/VisualBasic/Formatting/Indentation/SmartTokenFormatterCommandHandler.vb
  22. +10 −10 src/EditorFeatures/VisualBasic/Formatting/Indentation/SpecialFormattingOperation.vb
  23. +1 −1 src/EditorFeatures/VisualBasic/Formatting/Indentation/VisualBasicIndentationService.Indenter.vb
  24. +4 −4 src/EditorFeatures/VisualBasic/Formatting/Indentation/VisualBasicIndentationService.vb
  25. +5 −5 src/EditorFeatures/VisualBasic/LineCommit/CommitFormatter.vb
  26. +1 −1 src/EditorFeatures/VisualBasic/NavigationBar/AbstractGenerateCodeItem.vb
  27. +5 −20 src/EditorFeatures/VisualBasic/Utilities/LineAdjustmentFormattingRule.vb
  28. +2 −2 ...eatures/VisualBasic/Wrapping/SeparatedSyntaxList/AbstractVisualBasicSeparatedSyntaxListWrapper.vb
  29. +1 −1 src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs
  30. +4 −4 src/Features/CSharp/Portable/ChangeSignature/ChangeSignatureFormattingRule.cs
  31. +4 −4 src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.FormattingProvider.cs
  32. +1 −1 src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.cs
  33. +4 −4 src/Features/CSharp/Portable/MetadataAsSource/CSharpMetadataAsSourceService.cs
  34. +6 −6 src/Features/CSharp/Portable/UseAutoProperty/CSharpUseAutoPropertyCodeFixProvider.cs
  35. +1 −1 ...le/UseConditionalExpression/CSharpUseConditionalExpressionForAssignmentCodeRefactoringProvider.cs
  36. +1 −1 ...rtable/UseConditionalExpression/CSharpUseConditionalExpressionForReturnCodeRefactoringProvider.cs
  37. +4 −4 ...Features/CSharp/Portable/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs
  38. +1 −1 src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs
  39. +1 −1 ...tures/Core/Portable/CodeRefactorings/AddMissingImports/AbstractAddMissingImportsFeatureService.cs
  40. +1 −1 src/Features/Core/Portable/ExtractMethod/MethodExtractor.cs
  41. +1 −1 ...e/Portable/GenerateEqualsAndGetHashCodeFromMembers/AbstractGenerateEqualsAndGetHashCodeService.cs
  42. +3 −3 ...Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/FormatLargeBinaryExpressionRule.cs
  43. +115 −0 ...Portable/MetadataAsSource/AbstractMetadataAsSourceService+CompatAbstractMetadataFormattingRule.cs
  44. +2 −2 ...ce.AbstractFormattingRule.cs → AbstractMetadataAsSourceService.AbstractMetadataFormattingRule.cs}
  45. +1 −1 src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.cs
  46. +1 −1 src/Features/Core/Portable/UseAutoProperty/AbstractUseAutoPropertyCodeFixProvider.cs
  47. +2 −2 ...eatures/Core/Portable/UseConditionalExpression/AbstractUseConditionalExpressionCodeFixProvider.cs
  48. +4 −4 src/Features/VisualBasic/Portable/ChangeSignature/ChangeSignatureFormattingRule.vb
  49. +2 −2 src/Features/VisualBasic/Portable/ChangeSignature/VisualBasicChangeSignatureService.vb
  50. +4 −4 src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicMethodExtractor.vb
  51. +4 −4 src/Features/VisualBasic/Portable/MetadataAsSource/VisualBasicMetadataAsSourceService.vb
  52. +1 −1 src/Features/VisualBasic/Portable/UseAutoProperty/VisualBasicUseAutoPropertyCodeFixProvider.vb
  53. +6 −6 ...res/VisualBasic/Portable/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.vb
  54. +1 −1 ...eConditionalExpression/VisualBasicUseConditionalExpressionForAssignmentCodeRefactoringProvider.vb
  55. +1 −1 ...e/UseConditionalExpression/VisualBasicUseConditionalExpressionForReturnCodeRefactoringProvider.vb
  56. +2 −2 src/VisualStudio/CSharp/Impl/CodeModel/CSharpCodeModelService.cs
  57. +4 −24 src/VisualStudio/CSharp/Impl/CodeModel/EndRegionFormattingRule.cs
  58. +4 −25 src/VisualStudio/CSharp/Impl/Utilities/BlankLineInGeneratedMethodFormattingRule.cs
  59. +2 −2 src/VisualStudio/CSharp/Impl/Venus/CSharpAdditionalFormattingRuleLanguageService.cs
  60. +4 −4 src/VisualStudio/Core/Def/Implementation/Venus/ContainedDocument.cs
  61. +5 −5 src/VisualStudio/Core/Def/Implementation/Venus/ContainedDocumentPreserveFormattingRule.cs
  62. +5 −3 src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguage.cs
  63. +1 −1 src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguageCodeSupport.cs
  64. +1 −1 src/VisualStudio/Core/Def/Implementation/Venus/IAdditionalFormattingRuleLanguageService.cs
  65. +5 −7 ...VisualStudio/Core/Def/Implementation/Workspace/VisualStudioFormattingRuleFactoryServiceFactory.cs
  66. +5 −5 src/VisualStudio/Core/Impl/CodeModel/AbstractCodeModelService.cs
  67. +2 −2 src/VisualStudio/Core/Test/Venus/CSharpContainedLanguageSupportTests.vb
  68. +4 −3 src/VisualStudio/Core/Test/Venus/VisualBasicContainedLanguageSupportTests.vb
  69. +4 −25 src/VisualStudio/VisualBasic/Impl/CodeModel/EndRegionFormattingRule.vb
  70. +2 −2 src/VisualStudio/VisualBasic/Impl/CodeModel/VisualBasicCodeModelService.vb
  71. +3 −3 src/VisualStudio/VisualBasic/Impl/Venus/VisualBasicAdditionalFormattingRuleLanguageService.vb
  72. +5 −5 src/VisualStudio/VisualBasic/Impl/Venus/VisualBasicContainedLanguage.vb
  73. +5 −5 src/Workspaces/CSharp/Portable/Formatting/CSharpSyntaxFormattingService.cs
  74. +16 −7 src/Workspaces/CSharp/Portable/Formatting/DefaultOperationProvider.cs
  75. +1 −1 src/Workspaces/CSharp/Portable/Formatting/Engine/CSharpFormatEngine.cs
  76. +2 −2 src/Workspaces/CSharp/Portable/Formatting/Rules/AnchorIndentationFormattingRule.cs
  77. +8 −5 src/Workspaces/CSharp/Portable/Formatting/Rules/ElasticTriviaFormattingRule.cs
  78. +5 −2 src/Workspaces/CSharp/Portable/Formatting/Rules/EndOfFileTokenFormattingRule.cs
  79. +2 −2 src/Workspaces/CSharp/Portable/Formatting/Rules/IndentBlockFormattingRule.cs
  80. +2 −2 src/Workspaces/CSharp/Portable/Formatting/Rules/IndentUserSettingsFormattingRule.cs
  81. +5 −2 src/Workspaces/CSharp/Portable/Formatting/Rules/NewLineUserSettingFormattingRule.cs
  82. +11 −8 src/Workspaces/CSharp/Portable/Formatting/Rules/QueryExpressionFormattingRule.cs
  83. +3 −3 src/Workspaces/CSharp/Portable/Formatting/Rules/SpacingFormattingRule.cs
  84. +7 −4 src/Workspaces/CSharp/Portable/Formatting/Rules/StructuredTriviaFormattingRule.cs
  85. +2 −2 src/Workspaces/CSharp/Portable/Formatting/Rules/SuppressFormattingRule.cs
  86. +5 −2 src/Workspaces/CSharp/Portable/Formatting/Rules/TokenBasedFormattingRule.cs
  87. +2 −2 src/Workspaces/CSharp/Portable/Formatting/Rules/WrappingFormattingRule.cs
  88. +6 −6 src/Workspaces/Core/Portable/Formatting/AbstractSyntaxFormattingService.cs
  89. +1 −1 src/Workspaces/Core/Portable/Formatting/Engine/AbstractFormatEngine.cs
  90. +0 −22 src/Workspaces/Core/Portable/Formatting/Engine/ActionCache`1.cs
  91. +61 −72 src/Workspaces/Core/Portable/Formatting/Engine/ChainedFormattingRules.cs
  92. +0 −24 src/Workspaces/Core/Portable/Formatting/Engine/OperationCache`1.cs
  93. +10 −10 src/Workspaces/Core/Portable/Formatting/Formatter.cs
  94. +1 −1 src/Workspaces/Core/Portable/Formatting/FormattingExtensions.cs
  95. +2 −2 src/Workspaces/Core/Portable/Formatting/ISyntaxFormattingService.cs
  96. +32 −13 src/Workspaces/Core/Portable/Formatting/Rules/AbstractFormattingRule.cs
  97. +7 −7 src/Workspaces/Core/Portable/Formatting/Rules/BaseIndentationFormattingRule.cs
  98. +114 −0 src/Workspaces/Core/Portable/Formatting/Rules/CompatAbstractFormattingRule.cs
  99. +2 −4 src/Workspaces/Core/Portable/Formatting/Rules/DefaultFormattingRuleFactoryServiceFactory.cs
  100. +0 −13 src/Workspaces/Core/Portable/Formatting/Rules/IActionHolder`1.cs
  101. +2 −36 src/Workspaces/Core/Portable/Formatting/Rules/IFormattingRule.cs
  102. +1 −1 src/Workspaces/Core/Portable/Formatting/Rules/IHostDependentFormattingRuleFactoryService.cs
  103. +0 −15 src/Workspaces/Core/Portable/Formatting/Rules/IOperationHolder`1.cs
  104. +0 −28 src/Workspaces/Core/Portable/Formatting/Rules/NextAction`1.cs
  105. +52 −0 src/Workspaces/Core/Portable/Formatting/Rules/NextAlignTokensOperationAction.cs
  106. +52 −0 src/Workspaces/Core/Portable/Formatting/Rules/NextAnchorIndentationOperationAction.cs
  107. +50 −0 src/Workspaces/Core/Portable/Formatting/Rules/NextGetAdjustNewLinesOperation.cs
  108. +50 −0 src/Workspaces/Core/Portable/Formatting/Rules/NextGetAdjustSpacesOperation.cs
  109. +52 −0 src/Workspaces/Core/Portable/Formatting/Rules/NextIndentBlockOperationAction.cs
  110. +0 −29 src/Workspaces/Core/Portable/Formatting/Rules/NextOperation`1.cs
  111. +52 −0 src/Workspaces/Core/Portable/Formatting/Rules/NextSuppressOperationAction.cs
  112. +3 −30 src/Workspaces/Core/Portable/Formatting/Rules/NoOpFormattingRule.cs
  113. +6 −6 src/Workspaces/Core/Portable/Formatting/Rules/Operations/FormattingOperations.cs
  114. +11 −9 src/Workspaces/VisualBasic/Portable/Formatting/DefaultOperationProvider.vb
  115. +1 −1 src/Workspaces/VisualBasic/Portable/Formatting/Engine/VisualBasicFormatEngine.vb
  116. +1 −1 src/Workspaces/VisualBasic/Portable/Formatting/Rules/AdjustSpaceFormattingRule.vb
  117. +2 −2 src/Workspaces/VisualBasic/Portable/Formatting/Rules/AlignTokensFormattingRule.vb
  118. +1 −1 src/Workspaces/VisualBasic/Portable/Formatting/Rules/BaseFormattingRule.vb
  119. +10 −10 src/Workspaces/VisualBasic/Portable/Formatting/Rules/ElasticTriviaFormattingRule.vb
  120. +6 −6 src/Workspaces/VisualBasic/Portable/Formatting/Rules/NodeBasedFormattingRule.vb
  121. +2 −2 src/Workspaces/VisualBasic/Portable/Formatting/Rules/StructuredTriviaFormattingRule.vb
  122. +5 −5 src/Workspaces/VisualBasic/Portable/Formatting/VisualBasicSyntaxFormattingService.vb
@@ -19,15 +19,15 @@ internal static class Formatter
/// <summary>
/// Gets the formatting rules that would be applied if left unspecified.
/// </summary>
internal static IEnumerable<IFormattingRule> GetDefaultFormattingRules(ISyntaxFormattingService syntaxFormattingService)
internal static IEnumerable<AbstractFormattingRule> GetDefaultFormattingRules(ISyntaxFormattingService syntaxFormattingService)
{
if (syntaxFormattingService != null)
{
return syntaxFormattingService.GetDefaultFormattingRules();
}
else
{
return SpecializedCollections.EmptyEnumerable<IFormattingRule>();
return SpecializedCollections.EmptyEnumerable<AbstractFormattingRule>();
}
}

@@ -55,7 +55,7 @@ public static Task<SyntaxTree> FormatAsync(SyntaxTree syntaxTree, ISyntaxFormatt
return FormatAsync(syntaxTree, syntaxFormattingService, spans, options, rules: null, cancellationToken);
}

internal static async Task<SyntaxTree> FormatAsync(SyntaxTree syntaxTree, ISyntaxFormattingService syntaxFormattingService, IEnumerable<TextSpan> spans, OptionSet options, IEnumerable<IFormattingRule> rules, CancellationToken cancellationToken)
internal static async Task<SyntaxTree> FormatAsync(SyntaxTree syntaxTree, ISyntaxFormattingService syntaxFormattingService, IEnumerable<TextSpan> spans, OptionSet options, IEnumerable<AbstractFormattingRule> rules, CancellationToken cancellationToken)
{
if (syntaxTree == null)
{
@@ -77,21 +77,21 @@ internal static async Task<SyntaxTree> FormatAsync(SyntaxTree syntaxTree, ISynta
public static SyntaxNode Format(SyntaxNode node, ISyntaxFormattingService syntaxFormattingService, OptionSet options, CancellationToken cancellationToken)
=> Format(node, syntaxFormattingService, SpecializedCollections.SingletonEnumerable(node.FullSpan), options, rules: null, cancellationToken: cancellationToken);

internal static SyntaxNode Format(SyntaxNode node, ISyntaxFormattingService syntaxFormattingService, IEnumerable<TextSpan> spans, OptionSet options, IEnumerable<IFormattingRule> rules, CancellationToken cancellationToken)
internal static SyntaxNode Format(SyntaxNode node, ISyntaxFormattingService syntaxFormattingService, IEnumerable<TextSpan> spans, OptionSet options, IEnumerable<AbstractFormattingRule> rules, CancellationToken cancellationToken)
{
var formattingResult = GetFormattingResult(node, syntaxFormattingService, spans, options, rules, cancellationToken);
return formattingResult == null ? node : formattingResult.GetFormattedRoot(cancellationToken);
}

internal static IList<TextChange> GetFormattedTextChanges(SyntaxNode node, ISyntaxFormattingService syntaxFormattingService, IEnumerable<TextSpan> spans, OptionSet options, IEnumerable<IFormattingRule> rules, CancellationToken cancellationToken)
internal static IList<TextChange> GetFormattedTextChanges(SyntaxNode node, ISyntaxFormattingService syntaxFormattingService, IEnumerable<TextSpan> spans, OptionSet options, IEnumerable<AbstractFormattingRule> rules, CancellationToken cancellationToken)
{
var formattingResult = GetFormattingResult(node, syntaxFormattingService, spans, options, rules, cancellationToken);
return formattingResult == null
? SpecializedCollections.EmptyList<TextChange>()
: formattingResult.GetTextChanges(cancellationToken);
}

internal static IFormattingResult GetFormattingResult(SyntaxNode node, ISyntaxFormattingService syntaxFormattingService, IEnumerable<TextSpan> spans, OptionSet options, IEnumerable<IFormattingRule> rules, CancellationToken cancellationToken)
internal static IFormattingResult GetFormattingResult(SyntaxNode node, ISyntaxFormattingService syntaxFormattingService, IEnumerable<TextSpan> spans, OptionSet options, IEnumerable<AbstractFormattingRule> rules, CancellationToken cancellationToken)
{
if (node == null)
{
@@ -75,10 +75,8 @@
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Engine\AbstractTriviaDataFactory.FormattedWhitespace.cs" Link="Formatting\Engine\AbstractTriviaDataFactory.FormattedWhitespace.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Engine\AbstractTriviaDataFactory.ModifiedWhitespace.cs" Link="Formatting\Engine\AbstractTriviaDataFactory.ModifiedWhitespace.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Engine\AbstractTriviaDataFactory.Whitespace.cs" Link="Formatting\Engine\AbstractTriviaDataFactory.Whitespace.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Engine\ActionCache`1.cs" Link="Formatting\Engine\ActionCache`1.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Engine\ChainedFormattingRules.cs" Link="Formatting\Engine\ChainedFormattingRules.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Engine\NodeOperations.cs" Link="Formatting\Engine\NodeOperations.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Engine\OperationCache`1.cs" Link="Formatting\Engine\OperationCache`1.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Engine\TokenData.cs" Link="Formatting\Engine\TokenData.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Engine\TokenPairWithOperations.cs" Link="Formatting\Engine\TokenPairWithOperations.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Engine\TokenStream.Changes.cs" Link="Formatting\Engine\TokenStream.Changes.cs" />
@@ -98,11 +96,13 @@
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\ListPool.cs" Link="Formatting\ListPool.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\AbstractFormattingRule.cs" Link="Formatting\Rules\AbstractFormattingRule.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\BaseIndentationFormattingRule.cs" Link="Formatting\Rules\BaseIndentationFormattingRule.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\IActionHolder`1.cs" Link="Formatting\Rules\IActionHolder`1.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\IFormattingRule.cs" Link="Formatting\Rules\IFormattingRule.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\IOperationHolder`1.cs" Link="Formatting\Rules\IOperationHolder`1.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\NextAction`1.cs" Link="Formatting\Rules\NextAction`1.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\NextOperation`1.cs" Link="Formatting\Rules\NextOperation`1.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\CompatAbstractFormattingRule.cs" Link="Formatting\Rules\CompatAbstractFormattingRule.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\NextAlignTokensOperationAction.cs" Link="Formatting\Rules\NextAlignTokensOperationAction.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\NextAnchorIndentationOperationAction.cs" Link="Formatting\Rules\NextAnchorIndentationOperationAction.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\NextGetAdjustNewLinesOperation.cs" Link="Formatting\Rules\NextGetAdjustNewLinesOperation.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\NextGetAdjustSpacesOperation.cs" Link="Formatting\Rules\NextGetAdjustSpacesOperation.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\NextIndentBlockOperationAction.cs" Link="Formatting\Rules\NextIndentBlockOperationAction.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\NextSuppressOperationAction.cs" Link="Formatting\Rules\NextSuppressOperationAction.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\NoOpFormattingRule.cs" Link="Formatting\Rules\NoOpFormattingRule.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\Operations\AdjustNewLinesOperation.cs" Link="Formatting\Rules\Operations\AdjustNewLinesOperation.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\Operations\AdjustNewLinesOption.cs" Link="Formatting\Rules\Operations\AdjustNewLinesOption.cs" />
@@ -105,12 +105,12 @@ private static bool ContainsOnlyWhitespace(IBraceCompletionSession session)
return true;
}

private IEnumerable<IFormattingRule> GetFormattingRules(Document document)
private IEnumerable<AbstractFormattingRule> GetFormattingRules(Document document)
{
return SpecializedCollections.SingletonEnumerable(BraceCompletionFormattingRule.Instance).Concat(Formatter.GetDefaultFormattingRules(document));
}

private void FormatTrackingSpan(IBraceCompletionSession session, bool shouldHonorAutoFormattingOnCloseBraceOption, IEnumerable<IFormattingRule> rules = null)
private void FormatTrackingSpan(IBraceCompletionSession session, bool shouldHonorAutoFormattingOnCloseBraceOption, IEnumerable<AbstractFormattingRule> rules = null)
{
if (!session.SubjectBuffer.GetFeatureOnOffOption(FeatureOnOffOptions.AutoFormattingOnCloseBrace) && shouldHonorAutoFormattingOnCloseBraceOption)
{
@@ -195,9 +195,9 @@ private class BraceCompletionFormattingRule : BaseFormattingRule
{
private static readonly Predicate<SuppressOperation> s_predicate = o => o == null || o.Option.IsOn(SuppressOption.NoWrapping);

public static readonly IFormattingRule Instance = new BraceCompletionFormattingRule();
public static readonly AbstractFormattingRule Instance = new BraceCompletionFormattingRule();

public override AdjustNewLinesOperation GetAdjustNewLinesOperation(SyntaxToken previousToken, SyntaxToken currentToken, OptionSet optionSet, NextOperation<AdjustNewLinesOperation> nextOperation)
public override AdjustNewLinesOperation GetAdjustNewLinesOperation(SyntaxToken previousToken, SyntaxToken currentToken, OptionSet optionSet, in NextGetAdjustNewLinesOperation nextOperation)
{
// Eg Cases -
// new MyObject {
@@ -221,12 +221,12 @@ public override AdjustNewLinesOperation GetAdjustNewLinesOperation(SyntaxToken p
}
}

return base.GetAdjustNewLinesOperation(previousToken, currentToken, optionSet, nextOperation);
return base.GetAdjustNewLinesOperation(previousToken, currentToken, optionSet, in nextOperation);
}

public override void AddAlignTokensOperations(List<AlignTokensOperation> list, SyntaxNode node, OptionSet optionSet, NextAction<AlignTokensOperation> nextOperation)
public override void AddAlignTokensOperations(List<AlignTokensOperation> list, SyntaxNode node, OptionSet optionSet, in NextAlignTokensOperationAction nextOperation)
{
base.AddAlignTokensOperations(list, node, optionSet, nextOperation);
base.AddAlignTokensOperations(list, node, optionSet, in nextOperation);
if (optionSet.GetOption(SmartIndent, node.Language) == IndentStyle.Block)
{
var bracePair = node.GetBracePair();
@@ -237,9 +237,9 @@ public override void AddAlignTokensOperations(List<AlignTokensOperation> list, S
}
}

public override void AddSuppressOperations(List<SuppressOperation> list, SyntaxNode node, OptionSet optionSet, NextAction<SuppressOperation> nextOperation)
public override void AddSuppressOperations(List<SuppressOperation> list, SyntaxNode node, OptionSet optionSet, in NextSuppressOperationAction nextOperation)
{
base.AddSuppressOperations(list, node, optionSet, nextOperation);
base.AddSuppressOperations(list, node, optionSet, in nextOperation);

// remove suppression rules for array and collection initializer
if (node.IsInitializerForArrayOrCollectionCreationExpression())
@@ -10,7 +10,7 @@ internal partial class CSharpEditorFormattingService : IEditorFormattingService
{
internal class PasteFormattingRule : AbstractFormattingRule
{
public override AdjustNewLinesOperation GetAdjustNewLinesOperation(SyntaxToken previousToken, SyntaxToken currentToken, OptionSet optionSet, NextOperation<AdjustNewLinesOperation> nextOperation)
public override AdjustNewLinesOperation GetAdjustNewLinesOperation(SyntaxToken previousToken, SyntaxToken currentToken, OptionSet optionSet, in NextGetAdjustNewLinesOperation nextOperation)
{
if (currentToken.Parent != null)
{
@@ -115,13 +115,13 @@ public async Task<IList<TextChange>> GetFormattingChangesOnPasteAsync(Document d
return SpecializedCollections.EmptyList<TextChange>();
}

var rules = new List<IFormattingRule>() { new PasteFormattingRule() };
var rules = new List<AbstractFormattingRule>() { new PasteFormattingRule() };
rules.AddRange(service.GetDefaultFormattingRules());

return Formatter.GetFormattedTextChanges(root, SpecializedCollections.SingletonEnumerable(formattingSpan), document.Project.Solution.Workspace, options, rules, cancellationToken);
}

private IEnumerable<IFormattingRule> GetFormattingRules(Document document, int position, SyntaxToken tokenBeforeCaret)
private IEnumerable<AbstractFormattingRule> GetFormattingRules(Document document, int position, SyntaxToken tokenBeforeCaret)
{
var workspace = document.Project.Solution.Workspace;
var formattingRuleFactory = workspace.Services.GetService<IHostDependentFormattingRuleFactoryService>();
@@ -311,7 +311,7 @@ private static async Task<SyntaxToken> GetTokenBeforeTheCaretAsync(Document docu
return token;
}

private async Task<IList<TextChange>> FormatTokenAsync(Document document, SyntaxToken token, IEnumerable<IFormattingRule> formattingRules, CancellationToken cancellationToken)
private async Task<IList<TextChange>> FormatTokenAsync(Document document, SyntaxToken token, IEnumerable<AbstractFormattingRule> formattingRules, CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var options = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);
@@ -320,13 +320,13 @@ private async Task<IList<TextChange>> FormatTokenAsync(Document document, Syntax
return changes;
}

private ISmartTokenFormatter CreateSmartTokenFormatter(OptionSet optionSet, IEnumerable<IFormattingRule> formattingRules, SyntaxNode root)
private ISmartTokenFormatter CreateSmartTokenFormatter(OptionSet optionSet, IEnumerable<AbstractFormattingRule> formattingRules, SyntaxNode root)
{
return new SmartTokenFormatter(optionSet, formattingRules, (CompilationUnitSyntax)root);
}

private async Task<IList<TextChange>> FormatRangeAsync(
Document document, SyntaxToken endToken, IEnumerable<IFormattingRule> formattingRules,
Document document, SyntaxToken endToken, IEnumerable<AbstractFormattingRule> formattingRules,
CancellationToken cancellationToken)
{
if (!IsEndToken(endToken))
@@ -354,7 +354,7 @@ private ISmartTokenFormatter CreateSmartTokenFormatter(OptionSet optionSet, IEnu
return changes;
}

private IEnumerable<IFormattingRule> GetTypingRules(Document document, SyntaxToken tokenBeforeCaret)
private IEnumerable<AbstractFormattingRule> GetTypingRules(Document document, SyntaxToken tokenBeforeCaret)
{
// Typing introduces several challenges around formatting.
// Historically we've shipped several triggers that cause formatting to happen directly while typing.
@@ -431,7 +431,7 @@ private IEnumerable<IFormattingRule> GetTypingRules(Document document, SyntaxTok
if (tokenBeforeCaret.Kind() == SyntaxKind.CloseBraceToken ||
tokenBeforeCaret.Kind() == SyntaxKind.EndOfFileToken)
{
return SpecializedCollections.EmptyEnumerable<IFormattingRule>();
return SpecializedCollections.EmptyEnumerable<AbstractFormattingRule>();
}

return SpecializedCollections.SingletonEnumerable(TypingFormattingRule.Instance);
@@ -27,7 +27,7 @@ internal class Indenter : AbstractIndenter
public Indenter(
ISyntaxFactsService syntaxFacts,
SyntaxTree syntaxTree,
IEnumerable<IFormattingRule> rules,
IEnumerable<AbstractFormattingRule> rules,
OptionSet optionSet,
TextLine line,
CancellationToken cancellationToken) :
@@ -25,23 +25,23 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.Formatting.Indentation
[ExportLanguageService(typeof(ISynchronousIndentationService), LanguageNames.CSharp), Shared]
internal partial class CSharpIndentationService : AbstractIndentationService<CompilationUnitSyntax>
{
private static readonly IFormattingRule s_instance = new FormattingRule();
private static readonly AbstractFormattingRule s_instance = new FormattingRule();

protected override IFormattingRule GetSpecializedIndentationFormattingRule()
protected override AbstractFormattingRule GetSpecializedIndentationFormattingRule()
{
return s_instance;
}

protected override AbstractIndenter GetIndenter(
ISyntaxFactsService syntaxFacts, SyntaxTree syntaxTree, TextLine lineToBeIndented, IEnumerable<IFormattingRule> formattingRules, OptionSet optionSet, CancellationToken cancellationToken)
ISyntaxFactsService syntaxFacts, SyntaxTree syntaxTree, TextLine lineToBeIndented, IEnumerable<AbstractFormattingRule> formattingRules, OptionSet optionSet, CancellationToken cancellationToken)
{
return new Indenter(
syntaxFacts, syntaxTree, formattingRules,
optionSet, lineToBeIndented, cancellationToken);
}

public static bool ShouldUseSmartTokenFormatterInsteadOfIndenter(
IEnumerable<IFormattingRule> formattingRules,
IEnumerable<AbstractFormattingRule> formattingRules,
CompilationUnitSyntax root,
TextLine line,
OptionSet optionSet,
@@ -96,13 +96,13 @@ protected override IFormattingRule GetSpecializedIndentationFormattingRule()

private class FormattingRule : AbstractFormattingRule
{
public override void AddIndentBlockOperations(List<IndentBlockOperation> list, SyntaxNode node, OptionSet optionSet, NextAction<IndentBlockOperation> nextOperation)
public override void AddIndentBlockOperations(List<IndentBlockOperation> list, SyntaxNode node, OptionSet optionSet, in NextIndentBlockOperationAction nextOperation)
{
// these nodes should be from syntax tree from ITextSnapshot.
Debug.Assert(node.SyntaxTree != null);
Debug.Assert(node.SyntaxTree.GetText() != null);

nextOperation.Invoke(list);
nextOperation.Invoke();

ReplaceCaseIndentationRules(list, node);

Oops, something went wrong.

0 comments on commit d260ee0

Please sign in to comment.