From b03a06238247c875799c0bfaa739441d6f852ebe Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 13 Apr 2020 10:23:42 -0700 Subject: [PATCH] Avoid passing options to AddIndentBlockOperations --- ...LineConditionalExpressionFormattingRule.cs | 2 +- ...LineConditionalExpressionFormattingRule.vb | 2 +- .../ChangeSignatureFormattingRule.cs | 2 +- .../FormatLargeBinaryExpressionRule.cs | 2 +- ...ce+CompatAbstractMetadataFormattingRule.cs | 8 +- .../ChangeSignatureFormattingRule.vb | 2 +- .../Venus/VisualBasicContainedLanguage.vb | 4 +- .../Indentation/CSharpIndentationService.cs | 3 +- .../Formatting/DefaultOperationProvider.cs | 2 +- .../Rules/IndentBlockFormattingRule.cs | 116 +++++++++++++++--- .../Rules/IndentUserSettingsFormattingRule.cs | 71 ++++++++++- .../Rules/QueryExpressionFormattingRule.cs | 2 +- .../Engine/ChainedFormattingRules.cs | 2 +- .../Rules/AbstractFormattingRule.cs | 2 +- .../Rules/BaseIndentationFormattingRule.cs | 11 +- .../Rules/CompatAbstractFormattingRule.cs | 8 +- .../Rules/NextIndentBlockOperationAction.cs | 8 +- .../Formatting/DefaultOperationProvider.vb | 2 +- .../Rules/ElasticTriviaFormattingRule.vb | 2 +- .../Rules/NodeBasedFormattingRule.vb | 2 - .../Indentation/SpecialFormattingOperation.vb | 2 +- 21 files changed, 194 insertions(+), 61 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs b/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs index 3602a14d35a..842074bcd22 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs @@ -54,7 +54,7 @@ private bool IsQuestionOrColonOfNewConditional(SyntaxToken token) } public override void AddIndentBlockOperations( - List list, SyntaxNode node, AnalyzerConfigOptions options, in NextIndentBlockOperationAction nextOperation) + List list, SyntaxNode node, in NextIndentBlockOperationAction nextOperation) { if (node.HasAnnotation(SpecializedFormattingAnnotation) && node is ConditionalExpressionSyntax conditional) diff --git a/src/Analyzers/VisualBasic/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.vb b/src/Analyzers/VisualBasic/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.vb index 8e8ae6cbe1f..6474a1524e0 100644 --- a/src/Analyzers/VisualBasic/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.vb +++ b/src/Analyzers/VisualBasic/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.vb @@ -50,7 +50,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UseConditionalExpression End Function Public Overrides Sub AddIndentBlockOperationsSlow( - list As List(Of IndentBlockOperation), node As SyntaxNode, options As AnalyzerConfigOptions, ByRef nextOperation As NextIndentBlockOperationAction) + list As List(Of IndentBlockOperation), node As SyntaxNode, ByRef nextOperation As NextIndentBlockOperationAction) If node.HasAnnotation(UseConditionalExpressionCodeFixHelpers.SpecializedFormattingAnnotation) AndAlso TypeOf node Is TernaryConditionalExpressionSyntax Then diff --git a/src/Features/CSharp/Portable/ChangeSignature/ChangeSignatureFormattingRule.cs b/src/Features/CSharp/Portable/ChangeSignature/ChangeSignatureFormattingRule.cs index 55ffeecbdc3..01bdf5cbc38 100644 --- a/src/Features/CSharp/Portable/ChangeSignature/ChangeSignatureFormattingRule.cs +++ b/src/Features/CSharp/Portable/ChangeSignature/ChangeSignatureFormattingRule.cs @@ -22,7 +22,7 @@ internal sealed class ChangeSignatureFormattingRule : BaseFormattingRule SyntaxKind.BracketedArgumentList, SyntaxKind.AttributeArgumentList); - public override void AddIndentBlockOperations(List list, SyntaxNode node, AnalyzerConfigOptions options, in NextIndentBlockOperationAction nextOperation) + public override void AddIndentBlockOperations(List list, SyntaxNode node, in NextIndentBlockOperationAction nextOperation) { nextOperation.Invoke(); diff --git a/src/Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/FormatLargeBinaryExpressionRule.cs b/src/Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/FormatLargeBinaryExpressionRule.cs index 37e306323dc..d3ac6f10db4 100644 --- a/src/Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/FormatLargeBinaryExpressionRule.cs +++ b/src/Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/FormatLargeBinaryExpressionRule.cs @@ -45,7 +45,7 @@ public FormatLargeBinaryExpressionRule(ISyntaxFactsService syntaxFacts) /// ... /// public override void AddIndentBlockOperations( - List list, SyntaxNode node, AnalyzerConfigOptions options, in NextIndentBlockOperationAction nextOperation) + List list, SyntaxNode node, in NextIndentBlockOperationAction nextOperation) { if (_syntaxFacts.IsReturnStatement(node)) { diff --git a/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService+CompatAbstractMetadataFormattingRule.cs b/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService+CompatAbstractMetadataFormattingRule.cs index 3dddbdfba0b..8365c471000 100644 --- a/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService+CompatAbstractMetadataFormattingRule.cs +++ b/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService+CompatAbstractMetadataFormattingRule.cs @@ -33,10 +33,10 @@ public override sealed void AddAnchorIndentationOperations(List list, SyntaxNode node, AnalyzerConfigOptions options, in NextIndentBlockOperationAction nextOperation) + public override sealed void AddIndentBlockOperations(List list, SyntaxNode node, in NextIndentBlockOperationAction nextOperation) { var nextOperationCopy = nextOperation; - AddIndentBlockOperationsSlow(list, node, options, ref nextOperationCopy); + AddIndentBlockOperationsSlow(list, node, ref nextOperationCopy); } [Obsolete("Do not call this method directly (it will Stack Overflow).", error: true)] @@ -80,8 +80,8 @@ public virtual void AddAnchorIndentationOperationsSlow(List /// returns IndentBlockOperations under a node either by itself or by filtering/replacing operations returned by NextOperation /// - public virtual void AddIndentBlockOperationsSlow(List list, SyntaxNode node, AnalyzerConfigOptions options, ref NextIndentBlockOperationAction nextOperation) - => base.AddIndentBlockOperations(list, node, options, in nextOperation); + public virtual void AddIndentBlockOperationsSlow(List list, SyntaxNode node, ref NextIndentBlockOperationAction nextOperation) + => base.AddIndentBlockOperations(list, node, in nextOperation); /// /// returns AlignTokensOperations under a node either by itself or by filtering/replacing operations returned by NextOperation diff --git a/src/Features/VisualBasic/Portable/ChangeSignature/ChangeSignatureFormattingRule.vb b/src/Features/VisualBasic/Portable/ChangeSignature/ChangeSignatureFormattingRule.vb index 3dc2fda3234..b9bcd435866 100644 --- a/src/Features/VisualBasic/Portable/ChangeSignature/ChangeSignatureFormattingRule.vb +++ b/src/Features/VisualBasic/Portable/ChangeSignature/ChangeSignatureFormattingRule.vb @@ -11,7 +11,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ChangeSignature Friend NotInheritable Class ChangeSignatureFormattingRule Inherits BaseFormattingRule - Public Overrides Sub AddIndentBlockOperationsSlow(list As List(Of IndentBlockOperation), node As SyntaxNode, options As AnalyzerConfigOptions, ByRef nextOperation As NextIndentBlockOperationAction) + Public Overrides Sub AddIndentBlockOperationsSlow(list As List(Of IndentBlockOperation), node As SyntaxNode, ByRef nextOperation As NextIndentBlockOperationAction) nextOperation.Invoke() If node.IsKind(SyntaxKind.ParameterList) OrElse node.IsKind(SyntaxKind.ArgumentList) Then diff --git a/src/VisualStudio/VisualBasic/Impl/Venus/VisualBasicContainedLanguage.vb b/src/VisualStudio/VisualBasic/Impl/Venus/VisualBasicContainedLanguage.vb index 03c7744fb20..73439c12726 100644 --- a/src/VisualStudio/VisualBasic/Impl/Venus/VisualBasicContainedLanguage.vb +++ b/src/VisualStudio/VisualBasic/Impl/Venus/VisualBasicContainedLanguage.vb @@ -138,7 +138,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Venus Public Shared Shadows Instance As AbstractFormattingRule = New VisualBasicHelperFormattingRule() - Public Overrides Sub AddIndentBlockOperationsSlow(list As List(Of IndentBlockOperation), node As SyntaxNode, options As AnalyzerConfigOptions, ByRef nextOperation As NextIndentBlockOperationAction) + Public Overrides Sub AddIndentBlockOperationsSlow(list As List(Of IndentBlockOperation), node As SyntaxNode, ByRef nextOperation As NextIndentBlockOperationAction) ' we need special behavior for VB due to @Helper code generation weird-ness. ' this will looking for code gen specific style to make it not so expansive If IsEndHelperPattern(node) Then @@ -150,7 +150,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Venus Return End If - MyBase.AddIndentBlockOperationsSlow(list, node, options, nextOperation) + MyBase.AddIndentBlockOperationsSlow(list, node, nextOperation) End Sub Private Shared Function IsHelperSubLambda(multiLineLambda As MultiLineLambdaExpressionSyntax) As Boolean diff --git a/src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.cs b/src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.cs index 0aa0762e613..f465680bd8a 100644 --- a/src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.cs +++ b/src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.cs @@ -8,7 +8,6 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Formatting.Rules; using Microsoft.CodeAnalysis.Host.Mef; @@ -107,7 +106,7 @@ private static bool IsInvalidToken(SyntaxToken token) private class FormattingRule : AbstractFormattingRule { - public override void AddIndentBlockOperations(List list, SyntaxNode node, AnalyzerConfigOptions options, in NextIndentBlockOperationAction nextOperation) + public override void AddIndentBlockOperations(List list, SyntaxNode node, in NextIndentBlockOperationAction nextOperation) { // these nodes should be from syntax tree from ITextSnapshot. Debug.Assert(node.SyntaxTree != null); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/DefaultOperationProvider.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/DefaultOperationProvider.cs index 0456aca99ec..d2c24e3798b 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/DefaultOperationProvider.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/DefaultOperationProvider.cs @@ -30,7 +30,7 @@ public override void AddAnchorIndentationOperations(List list, SyntaxNode node, AnalyzerConfigOptions options, in NextIndentBlockOperationAction nextOperation) + public override void AddIndentBlockOperations(List list, SyntaxNode node, in NextIndentBlockOperationAction nextOperation) { } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/IndentBlockFormattingRule.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/IndentBlockFormattingRule.cs index ba0a237c62d..fd39a9a96a3 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/IndentBlockFormattingRule.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/IndentBlockFormattingRule.cs @@ -11,6 +11,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Formatting.Rules; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Utilities; using Microsoft.CodeAnalysis.Text; @@ -18,21 +19,45 @@ namespace Microsoft.CodeAnalysis.CSharp.Formatting { - internal class IndentBlockFormattingRule : BaseFormattingRule + internal sealed class IndentBlockFormattingRule : BaseFormattingRule { internal const string Name = "CSharp IndentBlock Formatting Rule"; - public override void AddIndentBlockOperations(List list, SyntaxNode node, AnalyzerConfigOptions options, in NextIndentBlockOperationAction nextOperation) + private readonly CachedOptions _options; + + public IndentBlockFormattingRule() + : this(new CachedOptions(null)) + { + } + + private IndentBlockFormattingRule(CachedOptions options) + { + _options = options; + } + + public override AbstractFormattingRule WithOptions(AnalyzerConfigOptions options) + { + var cachedOptions = new CachedOptions(options); + + if (cachedOptions == _options) + { + return this; + } + + return new IndentBlockFormattingRule(cachedOptions); + } + + public override void AddIndentBlockOperations(List list, SyntaxNode node, in NextIndentBlockOperationAction nextOperation) { nextOperation.Invoke(); AddAlignmentBlockOperation(list, node); - AddBlockIndentationOperation(list, node, options); + AddBlockIndentationOperation(list, node); - AddLabelIndentationOperation(list, node, options); + AddLabelIndentationOperation(list, node); - AddSwitchIndentationOperation(list, node, options); + AddSwitchIndentationOperation(list, node); AddEmbeddedStatementsIndentationOperation(list, node); @@ -48,7 +73,7 @@ private void AddTypeParameterConstraintClauseOperation(List list, SyntaxNode node, AnalyzerConfigOptions options) + private void AddSwitchIndentationOperation(List list, SyntaxNode node) { if (!(node is SwitchSectionSyntax section)) { @@ -62,25 +87,23 @@ private void AddSwitchIndentationOperation(List list, Synt return; } - var indentSwitchCase = options.GetOption(CSharpFormattingOptions2.IndentSwitchCaseSection); - var indentSwitchCaseWhenBlock = options.GetOption(CSharpFormattingOptions2.IndentSwitchCaseSectionWhenBlock); - if (!indentSwitchCase && !indentSwitchCaseWhenBlock) + if (!_options.IndentSwitchCaseSection && !_options.IndentSwitchCaseSectionWhenBlock) { // Never indent return; } - var alwaysIndent = indentSwitchCase && indentSwitchCaseWhenBlock; + var alwaysIndent = _options.IndentSwitchCaseSection && _options.IndentSwitchCaseSectionWhenBlock; if (!alwaysIndent) { // Only one of these values can be true at this point. - Debug.Assert(indentSwitchCase != indentSwitchCaseWhenBlock); + Debug.Assert(_options.IndentSwitchCaseSection != _options.IndentSwitchCaseSectionWhenBlock); var firstStatementIsBlock = section.Statements.Count > 0 && section.Statements[0].IsKind(SyntaxKind.Block); - if (indentSwitchCaseWhenBlock != firstStatementIsBlock) + if (_options.IndentSwitchCaseSectionWhenBlock != firstStatementIsBlock) { return; } @@ -113,18 +136,16 @@ private void AddSwitchIndentationOperation(List list, Synt AddIndentBlockOperation(list, startToken, endToken, span); } - private void AddLabelIndentationOperation(List list, SyntaxNode node, AnalyzerConfigOptions options) + private void AddLabelIndentationOperation(List list, SyntaxNode node) { // label statement if (node is LabeledStatementSyntax labeledStatement) { - var labelPositioningOption = options.GetOption(CSharpFormattingOptions2.LabelPositioning); - - if (labelPositioningOption == LabelPositionOptions.OneLess) + if (_options.LabelPositioning == LabelPositionOptions.OneLess) { AddUnindentBlockOperation(list, labeledStatement.Identifier, labeledStatement.ColonToken); } - else if (labelPositioningOption == LabelPositionOptions.LeftMost) + else if (_options.LabelPositioning == LabelPositionOptions.LeftMost) { AddAbsoluteZeroIndentBlockOperation(list, labeledStatement.Identifier, labeledStatement.ColonToken); } @@ -178,7 +199,7 @@ private void SetAlignmentBlockOperation(List list, SyntaxN SetAlignmentBlockOperation(list, baseToken, firstToken, lastToken, option); } - private void AddBlockIndentationOperation(List list, SyntaxNode node, AnalyzerConfigOptions options) + private void AddBlockIndentationOperation(List list, SyntaxNode node) { var bracePair = node.GetBracePair(); @@ -200,13 +221,13 @@ private void AddBlockIndentationOperation(List list, Synta AddAlignmentBlockOperationRelativeToFirstTokenOnBaseTokenLine(list, bracePair); } - if (node is BlockSyntax && !options.GetOption(CSharpFormattingOptions2.IndentBlock)) + if (node is BlockSyntax && !_options.IndentBlock) { // do not add indent operation for block return; } - if (node is SwitchStatementSyntax && !options.GetOption(CSharpFormattingOptions2.IndentSwitchSection)) + if (node is SwitchStatementSyntax && !_options.IndentSwitchSection) { // do not add indent operation for switch statement return; @@ -299,5 +320,60 @@ private void AddEmbeddedStatementsIndentationOperation(List + { + public readonly LabelPositionOptions LabelPositioning; + public readonly bool IndentBlock; + public readonly bool IndentSwitchCaseSection; + public readonly bool IndentSwitchCaseSectionWhenBlock; + public readonly bool IndentSwitchSection; + + public CachedOptions(AnalyzerConfigOptions? options) + { + LabelPositioning = GetOptionOrDefault(options, CSharpFormattingOptions2.LabelPositioning); + IndentBlock = GetOptionOrDefault(options, CSharpFormattingOptions2.IndentBlock); + IndentSwitchCaseSection = GetOptionOrDefault(options, CSharpFormattingOptions2.IndentSwitchCaseSection); + IndentSwitchCaseSectionWhenBlock = GetOptionOrDefault(options, CSharpFormattingOptions2.IndentSwitchCaseSectionWhenBlock); + IndentSwitchSection = GetOptionOrDefault(options, CSharpFormattingOptions2.IndentSwitchSection); + } + + public static bool operator ==(CachedOptions left, CachedOptions right) + => left.Equals(right); + + public static bool operator !=(CachedOptions left, CachedOptions right) + => !(left == right); + + private static T GetOptionOrDefault(AnalyzerConfigOptions? options, Option2 option) + { + if (options is null) + return option.DefaultValue; + + return options.GetOption(option); + } + + public override bool Equals(object? obj) + => obj is CachedOptions options && Equals(options); + + public bool Equals(CachedOptions other) + { + return LabelPositioning == other.LabelPositioning + && IndentBlock == other.IndentBlock + && IndentSwitchCaseSection == other.IndentSwitchCaseSection + && IndentSwitchCaseSectionWhenBlock == other.IndentSwitchCaseSectionWhenBlock + && IndentSwitchSection == other.IndentSwitchSection; + } + + public override int GetHashCode() + { + var hashCode = 0; + hashCode = (hashCode << 2) + (int)LabelPositioning; + hashCode = (hashCode << 1) + (IndentBlock ? 1 : 0); + hashCode = (hashCode << 1) + (IndentSwitchCaseSection ? 1 : 0); + hashCode = (hashCode << 1) + (IndentSwitchCaseSectionWhenBlock ? 1 : 0); + hashCode = (hashCode << 1) + (IndentSwitchSection ? 1 : 0); + return hashCode; + } + } } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/IndentUserSettingsFormattingRule.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/IndentUserSettingsFormattingRule.cs index c8619111bcb..76ab8b4c515 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/IndentUserSettingsFormattingRule.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/IndentUserSettingsFormattingRule.cs @@ -4,15 +4,41 @@ #nullable enable +using System; using System.Collections.Generic; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Formatting.Rules; +using Microsoft.CodeAnalysis.Options; namespace Microsoft.CodeAnalysis.CSharp.Formatting { - internal class IndentUserSettingsFormattingRule : BaseFormattingRule + internal sealed class IndentUserSettingsFormattingRule : BaseFormattingRule { - public override void AddIndentBlockOperations(List list, SyntaxNode node, AnalyzerConfigOptions options, in NextIndentBlockOperationAction nextOperation) + private readonly CachedOptions _options; + + public IndentUserSettingsFormattingRule() + : this(new CachedOptions(null)) + { + } + + private IndentUserSettingsFormattingRule(CachedOptions options) + { + _options = options; + } + + public override AbstractFormattingRule WithOptions(AnalyzerConfigOptions options) + { + var cachedOptions = new CachedOptions(options); + + if (cachedOptions == _options) + { + return this; + } + + return new IndentUserSettingsFormattingRule(cachedOptions); + } + + public override void AddIndentBlockOperations(List list, SyntaxNode node, in NextIndentBlockOperationAction nextOperation) { nextOperation.Invoke(); @@ -24,11 +50,50 @@ public override void AddIndentBlockOperations(List list, S return; } - if (options.GetOption(CSharpFormattingOptions2.IndentBraces)) + if (_options.IndentBraces) { AddIndentBlockOperation(list, bracePair.Item1, bracePair.Item1, bracePair.Item1.Span); AddIndentBlockOperation(list, bracePair.Item2, bracePair.Item2, bracePair.Item2.Span); } } + + private readonly struct CachedOptions : IEquatable + { + public readonly bool IndentBraces; + + public CachedOptions(AnalyzerConfigOptions? options) + { + IndentBraces = GetOptionOrDefault(options, CSharpFormattingOptions2.IndentBraces); + } + + public static bool operator ==(CachedOptions left, CachedOptions right) + => left.Equals(right); + + public static bool operator !=(CachedOptions left, CachedOptions right) + => !(left == right); + + private static T GetOptionOrDefault(AnalyzerConfigOptions? options, Option2 option) + { + if (options is null) + return option.DefaultValue; + + return options.GetOption(option); + } + + public override bool Equals(object? obj) + => obj is CachedOptions options && Equals(options); + + public bool Equals(CachedOptions other) + { + return IndentBraces == other.IndentBraces; + } + + public override int GetHashCode() + { + var hashCode = 0; + hashCode = (hashCode << 1) + (IndentBraces ? 1 : 0); + return hashCode; + } + } } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/QueryExpressionFormattingRule.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/QueryExpressionFormattingRule.cs index 1b7393a7532..67cde79448e 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/QueryExpressionFormattingRule.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/QueryExpressionFormattingRule.cs @@ -56,7 +56,7 @@ private void AddIndentBlockOperationsForFromClause(List li AddIndentBlockOperation(list, baseToken, startToken, endToken); } - public override void AddIndentBlockOperations(List list, SyntaxNode node, AnalyzerConfigOptions options, in NextIndentBlockOperationAction nextOperation) + public override void AddIndentBlockOperations(List list, SyntaxNode node, in NextIndentBlockOperationAction nextOperation) { nextOperation.Invoke(); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/ChainedFormattingRules.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/ChainedFormattingRules.cs index 67e227fc34c..90f48e243e9 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/ChainedFormattingRules.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/ChainedFormattingRules.cs @@ -60,7 +60,7 @@ public void AddAnchorIndentationOperations(List list public void AddIndentBlockOperations(List list, SyntaxNode currentNode) { - var action = new NextIndentBlockOperationAction(_addIndentBlockOperationsRules, index: 0, currentNode, _options, list); + var action = new NextIndentBlockOperationAction(_addIndentBlockOperationsRules, index: 0, currentNode, list); action.Invoke(); } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/AbstractFormattingRule.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/AbstractFormattingRule.cs index 3e8b4ff86da..0c2981425d2 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/AbstractFormattingRule.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/AbstractFormattingRule.cs @@ -34,7 +34,7 @@ public virtual void AddAnchorIndentationOperations(List /// returns IndentBlockOperations under a node either by itself or by filtering/replacing operations returned by NextOperation /// - public virtual void AddIndentBlockOperations(List list, SyntaxNode node, AnalyzerConfigOptions options, in NextIndentBlockOperationAction nextOperation) + public virtual void AddIndentBlockOperations(List list, SyntaxNode node, in NextIndentBlockOperationAction nextOperation) => nextOperation.Invoke(); /// diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/BaseIndentationFormattingRule.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/BaseIndentationFormattingRule.cs index 9d77c39b874..7d549c811d1 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/BaseIndentationFormattingRule.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/BaseIndentationFormattingRule.cs @@ -6,7 +6,6 @@ using System; using System.Collections.Generic; -using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; @@ -31,7 +30,7 @@ public BaseIndentationFormattingRule(SyntaxNode root, TextSpan span, int baseInd _vbHelperFormattingRule = vbHelperFormattingRule; } - public override void AddIndentBlockOperations(List list, SyntaxNode node, AnalyzerConfigOptions options, in NextIndentBlockOperationAction nextOperation) + public override void AddIndentBlockOperations(List list, SyntaxNode node, in NextIndentBlockOperationAction nextOperation) { // for the common node itself, return absolute indentation if (_commonNode == node) @@ -48,21 +47,21 @@ public override void AddIndentBlockOperations(List list, S } // Add everything to the list. - AddNextIndentBlockOperations(list, node, options, in nextOperation); + AddNextIndentBlockOperations(list, node, in nextOperation); // Filter out everything that encompasses our span. AdjustIndentBlockOperation(list); } - private void AddNextIndentBlockOperations(List list, SyntaxNode node, AnalyzerConfigOptions options, in NextIndentBlockOperationAction nextOperation) + private void AddNextIndentBlockOperations(List list, SyntaxNode node, in NextIndentBlockOperationAction nextOperation) { if (_vbHelperFormattingRule == null) { - base.AddIndentBlockOperations(list, node, options, in nextOperation); + base.AddIndentBlockOperations(list, node, in nextOperation); return; } - _vbHelperFormattingRule.AddIndentBlockOperations(list, node, options, in nextOperation); + _vbHelperFormattingRule.AddIndentBlockOperations(list, node, in nextOperation); } private void AdjustIndentBlockOperation(List list) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/CompatAbstractFormattingRule.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/CompatAbstractFormattingRule.cs index 9c9e831dfdb..d9cb93ded49 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/CompatAbstractFormattingRule.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/CompatAbstractFormattingRule.cs @@ -32,10 +32,10 @@ public override sealed void AddAnchorIndentationOperations(List list, SyntaxNode node, AnalyzerConfigOptions options, in NextIndentBlockOperationAction nextOperation) + public override sealed void AddIndentBlockOperations(List list, SyntaxNode node, in NextIndentBlockOperationAction nextOperation) { var nextOperationCopy = nextOperation; - AddIndentBlockOperationsSlow(list, node, options, ref nextOperationCopy); + AddIndentBlockOperationsSlow(list, node, ref nextOperationCopy); } [Obsolete("Do not call this method directly (it will Stack Overflow).", error: true)] @@ -79,8 +79,8 @@ public virtual void AddAnchorIndentationOperationsSlow(List /// returns IndentBlockOperations under a node either by itself or by filtering/replacing operations returned by NextOperation /// - public virtual void AddIndentBlockOperationsSlow(List list, SyntaxNode node, AnalyzerConfigOptions options, ref NextIndentBlockOperationAction nextOperation) - => base.AddIndentBlockOperations(list, node, options, in nextOperation); + public virtual void AddIndentBlockOperationsSlow(List list, SyntaxNode node, ref NextIndentBlockOperationAction nextOperation) + => base.AddIndentBlockOperations(list, node, in nextOperation); /// /// returns AlignTokensOperations under a node either by itself or by filtering/replacing operations returned by NextOperation diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/NextIndentBlockOperationAction.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/NextIndentBlockOperationAction.cs index f4d067a1d5b..6002371dd08 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/NextIndentBlockOperationAction.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/NextIndentBlockOperationAction.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Collections.Immutable; -using Microsoft.CodeAnalysis.Diagnostics; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Formatting.Rules @@ -17,25 +16,22 @@ namespace Microsoft.CodeAnalysis.Formatting.Rules private readonly ImmutableArray _formattingRules; private readonly int _index; private readonly SyntaxNode _node; - private readonly AnalyzerConfigOptions _options; private readonly List _list; public NextIndentBlockOperationAction( ImmutableArray formattingRules, int index, SyntaxNode node, - AnalyzerConfigOptions options, List list) { _formattingRules = formattingRules; _index = index; _node = node; - _options = options; _list = list; } private NextIndentBlockOperationAction NextAction - => new NextIndentBlockOperationAction(_formattingRules, _index + 1, _node, _options, _list); + => new NextIndentBlockOperationAction(_formattingRules, _index + 1, _node, _list); public void Invoke() { @@ -47,7 +43,7 @@ public void Invoke() else { // Call the handler at the index, passing a continuation that will come back to here with index + 1 - _formattingRules[_index].AddIndentBlockOperations(_list, _node, _options, NextAction); + _formattingRules[_index].AddIndentBlockOperations(_list, _node, NextAction); return; } } diff --git a/src/Workspaces/VisualBasic/Portable/Formatting/DefaultOperationProvider.vb b/src/Workspaces/VisualBasic/Portable/Formatting/DefaultOperationProvider.vb index e18de161876..80782f4607c 100644 --- a/src/Workspaces/VisualBasic/Portable/Formatting/DefaultOperationProvider.vb +++ b/src/Workspaces/VisualBasic/Portable/Formatting/DefaultOperationProvider.vb @@ -28,7 +28,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting Public Overrides Sub AddAnchorIndentationOperationsSlow(operations As List(Of AnchorIndentationOperation), node As SyntaxNode, ByRef nextAction As NextAnchorIndentationOperationAction) End Sub - Public Overrides Sub AddIndentBlockOperationsSlow(operations As List(Of IndentBlockOperation), node As SyntaxNode, options As AnalyzerConfigOptions, ByRef nextAction As NextIndentBlockOperationAction) + Public Overrides Sub AddIndentBlockOperationsSlow(operations As List(Of IndentBlockOperation), node As SyntaxNode, ByRef nextAction As NextIndentBlockOperationAction) End Sub Public Overrides Sub AddAlignTokensOperationsSlow(operations As List(Of AlignTokensOperation), node As SyntaxNode, options As AnalyzerConfigOptions, ByRef nextAction As NextAlignTokensOperationAction) diff --git a/src/Workspaces/VisualBasic/Portable/Formatting/Rules/ElasticTriviaFormattingRule.vb b/src/Workspaces/VisualBasic/Portable/Formatting/Rules/ElasticTriviaFormattingRule.vb index bc8a2314532..bba657447e3 100644 --- a/src/Workspaces/VisualBasic/Portable/Formatting/Rules/ElasticTriviaFormattingRule.vb +++ b/src/Workspaces/VisualBasic/Portable/Formatting/Rules/ElasticTriviaFormattingRule.vb @@ -19,7 +19,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting nextOperation.Invoke() End Sub - Public Overrides Sub AddIndentBlockOperationsSlow(list As List(Of IndentBlockOperation), node As SyntaxNode, options As AnalyzerConfigOptions, ByRef nextOperation As NextIndentBlockOperationAction) + Public Overrides Sub AddIndentBlockOperationsSlow(list As List(Of IndentBlockOperation), node As SyntaxNode, ByRef nextOperation As NextIndentBlockOperationAction) nextOperation.Invoke() If node.Kind = SyntaxKind.ObjectMemberInitializer Then diff --git a/src/Workspaces/VisualBasic/Portable/Formatting/Rules/NodeBasedFormattingRule.vb b/src/Workspaces/VisualBasic/Portable/Formatting/Rules/NodeBasedFormattingRule.vb index 00b6666b612..d51a719714d 100644 --- a/src/Workspaces/VisualBasic/Portable/Formatting/Rules/NodeBasedFormattingRule.vb +++ b/src/Workspaces/VisualBasic/Portable/Formatting/Rules/NodeBasedFormattingRule.vb @@ -3,7 +3,6 @@ ' See the LICENSE file in the project root for more information. Imports Microsoft.CodeAnalysis -Imports Microsoft.CodeAnalysis.Diagnostics Imports Microsoft.CodeAnalysis.Formatting.Rules Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Syntax @@ -49,7 +48,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting Public Overrides Sub AddIndentBlockOperationsSlow(operations As List(Of IndentBlockOperation), node As SyntaxNode, - options As AnalyzerConfigOptions, ByRef nextOperation As NextIndentBlockOperationAction) nextOperation.Invoke() diff --git a/src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb b/src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb index 4a5ea8d3545..feac0f4d1f0 100644 --- a/src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb +++ b/src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb @@ -54,7 +54,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation Return spaceOperation End Function - Public Overrides Sub AddIndentBlockOperationsSlow(list As List(Of IndentBlockOperation), node As SyntaxNode, options As AnalyzerConfigOptions, ByRef nextOperation As NextIndentBlockOperationAction) + Public Overrides Sub AddIndentBlockOperationsSlow(list As List(Of IndentBlockOperation), node As SyntaxNode, ByRef nextOperation As NextIndentBlockOperationAction) nextOperation.Invoke() Dim singleLineLambdaFunction = TryCast(node, SingleLineLambdaExpressionSyntax) -- GitLab