Skip to content

Commit

Permalink
Merge pull request #32845 from sharwell/format-perf
Browse files Browse the repository at this point in the history
Performance improvements for formatting analyzer
  • Loading branch information
sharwell committed Feb 9, 2019
2 parents c818853 + 735f9df commit d260ee0
Show file tree
Hide file tree
Showing 122 changed files with 1,013 additions and 709 deletions.
12 changes: 6 additions & 6 deletions src/CodeStyle/Core/Analyzers/Formatting/Formatter.cs
Expand Up @@ -19,15 +19,15 @@ internal static class Formatter
/// <summary> /// <summary>
/// Gets the formatting rules that would be applied if left unspecified. /// Gets the formatting rules that would be applied if left unspecified.
/// </summary> /// </summary>
internal static IEnumerable<IFormattingRule> GetDefaultFormattingRules(ISyntaxFormattingService syntaxFormattingService) internal static IEnumerable<AbstractFormattingRule> GetDefaultFormattingRules(ISyntaxFormattingService syntaxFormattingService)
{ {
if (syntaxFormattingService != null) if (syntaxFormattingService != null)
{ {
return syntaxFormattingService.GetDefaultFormattingRules(); return syntaxFormattingService.GetDefaultFormattingRules();
} }
else else
{ {
return SpecializedCollections.EmptyEnumerable<IFormattingRule>(); return SpecializedCollections.EmptyEnumerable<AbstractFormattingRule>();
} }
} }


Expand Down Expand Up @@ -55,7 +55,7 @@ public static Task<SyntaxTree> FormatAsync(SyntaxTree syntaxTree, ISyntaxFormatt
return FormatAsync(syntaxTree, syntaxFormattingService, spans, options, rules: null, cancellationToken); 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) if (syntaxTree == null)
{ {
Expand All @@ -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) public static SyntaxNode Format(SyntaxNode node, ISyntaxFormattingService syntaxFormattingService, OptionSet options, CancellationToken cancellationToken)
=> Format(node, syntaxFormattingService, SpecializedCollections.SingletonEnumerable(node.FullSpan), options, rules: null, 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); var formattingResult = GetFormattingResult(node, syntaxFormattingService, spans, options, rules, cancellationToken);
return formattingResult == null ? node : formattingResult.GetFormattedRoot(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); var formattingResult = GetFormattingResult(node, syntaxFormattingService, spans, options, rules, cancellationToken);
return formattingResult == null return formattingResult == null
? SpecializedCollections.EmptyList<TextChange>() ? SpecializedCollections.EmptyList<TextChange>()
: formattingResult.GetTextChanges(cancellationToken); : 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) if (node == null)
{ {
Expand Down
Expand Up @@ -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.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.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\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\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\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\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\TokenPairWithOperations.cs" Link="Formatting\Engine\TokenPairWithOperations.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Engine\TokenStream.Changes.cs" Link="Formatting\Engine\TokenStream.Changes.cs" /> <Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Engine\TokenStream.Changes.cs" Link="Formatting\Engine\TokenStream.Changes.cs" />
Expand All @@ -98,11 +96,13 @@
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\ListPool.cs" Link="Formatting\ListPool.cs" /> <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\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\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\CompatAbstractFormattingRule.cs" Link="Formatting\Rules\CompatAbstractFormattingRule.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\IFormattingRule.cs" Link="Formatting\Rules\IFormattingRule.cs" /> <Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\NextAlignTokensOperationAction.cs" Link="Formatting\Rules\NextAlignTokensOperationAction.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\IOperationHolder`1.cs" Link="Formatting\Rules\IOperationHolder`1.cs" /> <Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\NextAnchorIndentationOperationAction.cs" Link="Formatting\Rules\NextAnchorIndentationOperationAction.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\NextAction`1.cs" Link="Formatting\Rules\NextAction`1.cs" /> <Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\NextGetAdjustNewLinesOperation.cs" Link="Formatting\Rules\NextGetAdjustNewLinesOperation.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\NextOperation`1.cs" Link="Formatting\Rules\NextOperation`1.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\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\AdjustNewLinesOperation.cs" Link="Formatting\Rules\Operations\AdjustNewLinesOperation.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\Operations\AdjustNewLinesOption.cs" Link="Formatting\Rules\Operations\AdjustNewLinesOption.cs" /> <Compile Include="..\..\..\Workspaces\Core\Portable\Formatting\Rules\Operations\AdjustNewLinesOption.cs" Link="Formatting\Rules\Operations\AdjustNewLinesOption.cs" />
Expand Down
Expand Up @@ -105,12 +105,12 @@ private static bool ContainsOnlyWhitespace(IBraceCompletionSession session)
return true; return true;
} }


private IEnumerable<IFormattingRule> GetFormattingRules(Document document) private IEnumerable<AbstractFormattingRule> GetFormattingRules(Document document)
{ {
return SpecializedCollections.SingletonEnumerable(BraceCompletionFormattingRule.Instance).Concat(Formatter.GetDefaultFormattingRules(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) if (!session.SubjectBuffer.GetFeatureOnOffOption(FeatureOnOffOptions.AutoFormattingOnCloseBrace) && shouldHonorAutoFormattingOnCloseBraceOption)
{ {
Expand Down Expand Up @@ -195,9 +195,9 @@ private class BraceCompletionFormattingRule : BaseFormattingRule
{ {
private static readonly Predicate<SuppressOperation> s_predicate = o => o == null || o.Option.IsOn(SuppressOption.NoWrapping); 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 - // Eg Cases -
// new MyObject { // new MyObject {
Expand All @@ -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) if (optionSet.GetOption(SmartIndent, node.Language) == IndentStyle.Block)
{ {
var bracePair = node.GetBracePair(); var bracePair = node.GetBracePair();
Expand All @@ -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 // remove suppression rules for array and collection initializer
if (node.IsInitializerForArrayOrCollectionCreationExpression()) if (node.IsInitializerForArrayOrCollectionCreationExpression())
Expand Down
Expand Up @@ -10,7 +10,7 @@ internal partial class CSharpEditorFormattingService : IEditorFormattingService
{ {
internal class PasteFormattingRule : AbstractFormattingRule 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) if (currentToken.Parent != null)
{ {
Expand Down
Expand Up @@ -115,13 +115,13 @@ public async Task<IList<TextChange>> GetFormattingChangesOnPasteAsync(Document d
return SpecializedCollections.EmptyList<TextChange>(); return SpecializedCollections.EmptyList<TextChange>();
} }


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


return Formatter.GetFormattedTextChanges(root, SpecializedCollections.SingletonEnumerable(formattingSpan), document.Project.Solution.Workspace, options, rules, cancellationToken); 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 workspace = document.Project.Solution.Workspace;
var formattingRuleFactory = workspace.Services.GetService<IHostDependentFormattingRuleFactoryService>(); var formattingRuleFactory = workspace.Services.GetService<IHostDependentFormattingRuleFactoryService>();
Expand Down Expand Up @@ -311,7 +311,7 @@ private static async Task<SyntaxToken> GetTokenBeforeTheCaretAsync(Document docu
return token; 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 root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var options = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); var options = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);
Expand All @@ -320,13 +320,13 @@ private async Task<IList<TextChange>> FormatTokenAsync(Document document, Syntax
return changes; 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); return new SmartTokenFormatter(optionSet, formattingRules, (CompilationUnitSyntax)root);
} }


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


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


return SpecializedCollections.SingletonEnumerable(TypingFormattingRule.Instance); return SpecializedCollections.SingletonEnumerable(TypingFormattingRule.Instance);
Expand Down
Expand Up @@ -27,7 +27,7 @@ internal class Indenter : AbstractIndenter
public Indenter( public Indenter(
ISyntaxFactsService syntaxFacts, ISyntaxFactsService syntaxFacts,
SyntaxTree syntaxTree, SyntaxTree syntaxTree,
IEnumerable<IFormattingRule> rules, IEnumerable<AbstractFormattingRule> rules,
OptionSet optionSet, OptionSet optionSet,
TextLine line, TextLine line,
CancellationToken cancellationToken) : CancellationToken cancellationToken) :
Expand Down
Expand Up @@ -25,23 +25,23 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.Formatting.Indentation
[ExportLanguageService(typeof(ISynchronousIndentationService), LanguageNames.CSharp), Shared] [ExportLanguageService(typeof(ISynchronousIndentationService), LanguageNames.CSharp), Shared]
internal partial class CSharpIndentationService : AbstractIndentationService<CompilationUnitSyntax> 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; return s_instance;
} }


protected override AbstractIndenter GetIndenter( 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( return new Indenter(
syntaxFacts, syntaxTree, formattingRules, syntaxFacts, syntaxTree, formattingRules,
optionSet, lineToBeIndented, cancellationToken); optionSet, lineToBeIndented, cancellationToken);
} }


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


private class FormattingRule : AbstractFormattingRule 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. // these nodes should be from syntax tree from ITextSnapshot.
Debug.Assert(node.SyntaxTree != null); Debug.Assert(node.SyntaxTree != null);
Debug.Assert(node.SyntaxTree.GetText() != null); Debug.Assert(node.SyntaxTree.GetText() != null);


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


ReplaceCaseIndentationRules(list, node); ReplaceCaseIndentationRules(list, node);


Expand Down

0 comments on commit d260ee0

Please sign in to comment.