Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
b03a0623
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b03a0623
编写于
4月 13, 2020
作者:
S
Sam Harwell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid passing options to AddIndentBlockOperations
上级
4a180e39
变更
21
隐藏空白更改
内联
并排
Showing
21 changed file
with
194 addition
and
61 deletion
+194
-61
src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs
...xpression/MultiLineConditionalExpressionFormattingRule.cs
+1
-1
src/Analyzers/VisualBasic/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.vb
...xpression/MultiLineConditionalExpressionFormattingRule.vb
+1
-1
src/Features/CSharp/Portable/ChangeSignature/ChangeSignatureFormattingRule.cs
...Portable/ChangeSignature/ChangeSignatureFormattingRule.cs
+1
-1
src/Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/FormatLargeBinaryExpressionRule.cs
...GetHashCodeFromMembers/FormatLargeBinaryExpressionRule.cs
+1
-1
src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService+CompatAbstractMetadataFormattingRule.cs
...taAsSourceService+CompatAbstractMetadataFormattingRule.cs
+4
-4
src/Features/VisualBasic/Portable/ChangeSignature/ChangeSignatureFormattingRule.vb
...Portable/ChangeSignature/ChangeSignatureFormattingRule.vb
+1
-1
src/VisualStudio/VisualBasic/Impl/Venus/VisualBasicContainedLanguage.vb
...io/VisualBasic/Impl/Venus/VisualBasicContainedLanguage.vb
+2
-2
src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.cs
...s/CSharp/Portable/Indentation/CSharpIndentationService.cs
+1
-2
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/DefaultOperationProvider.cs
...ns/Compiler/CSharp/Formatting/DefaultOperationProvider.cs
+1
-1
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/IndentBlockFormattingRule.cs
...iler/CSharp/Formatting/Rules/IndentBlockFormattingRule.cs
+96
-20
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/IndentUserSettingsFormattingRule.cs
...harp/Formatting/Rules/IndentUserSettingsFormattingRule.cs
+68
-3
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/QueryExpressionFormattingRule.cs
.../CSharp/Formatting/Rules/QueryExpressionFormattingRule.cs
+1
-1
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/ChainedFormattingRules.cs
...Compiler/Core/Formatting/Engine/ChainedFormattingRules.cs
+1
-1
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/AbstractFormattingRule.cs
.../Compiler/Core/Formatting/Rules/AbstractFormattingRule.cs
+1
-1
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/BaseIndentationFormattingRule.cs
...er/Core/Formatting/Rules/BaseIndentationFormattingRule.cs
+5
-6
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/CompatAbstractFormattingRule.cs
...ler/Core/Formatting/Rules/CompatAbstractFormattingRule.cs
+4
-4
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/NextIndentBlockOperationAction.cs
...r/Core/Formatting/Rules/NextIndentBlockOperationAction.cs
+2
-6
src/Workspaces/VisualBasic/Portable/Formatting/DefaultOperationProvider.vb
...sualBasic/Portable/Formatting/DefaultOperationProvider.vb
+1
-1
src/Workspaces/VisualBasic/Portable/Formatting/Rules/ElasticTriviaFormattingRule.vb
.../Portable/Formatting/Rules/ElasticTriviaFormattingRule.vb
+1
-1
src/Workspaces/VisualBasic/Portable/Formatting/Rules/NodeBasedFormattingRule.vb
...asic/Portable/Formatting/Rules/NodeBasedFormattingRule.vb
+0
-2
src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb
...lBasic/Portable/Indentation/SpecialFormattingOperation.vb
+1
-1
未找到文件。
src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs
浏览文件 @
b03a0623
...
...
@@ -54,7 +54,7 @@ private bool IsQuestionOrColonOfNewConditional(SyntaxToken token)
}
public
override
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
,
in
NextIndentBlockOperationAction
nextOperation
)
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
in
NextIndentBlockOperationAction
nextOperation
)
{
if
(
node
.
HasAnnotation
(
SpecializedFormattingAnnotation
)
&&
node
is
ConditionalExpressionSyntax
conditional
)
...
...
src/Analyzers/VisualBasic/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.vb
浏览文件 @
b03a0623
...
...
@@ -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
...
...
src/Features/CSharp/Portable/ChangeSignature/ChangeSignatureFormattingRule.cs
浏览文件 @
b03a0623
...
...
@@ -22,7 +22,7 @@ internal sealed class ChangeSignatureFormattingRule : BaseFormattingRule
SyntaxKind
.
BracketedArgumentList
,
SyntaxKind
.
AttributeArgumentList
);
public
override
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
,
in
NextIndentBlockOperationAction
nextOperation
)
public
override
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
in
NextIndentBlockOperationAction
nextOperation
)
{
nextOperation
.
Invoke
();
...
...
src/Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/FormatLargeBinaryExpressionRule.cs
浏览文件 @
b03a0623
...
...
@@ -45,7 +45,7 @@ public FormatLargeBinaryExpressionRule(ISyntaxFactsService syntaxFacts)
/// ...
/// </summary>
public
override
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
,
in
NextIndentBlockOperationAction
nextOperation
)
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
in
NextIndentBlockOperationAction
nextOperation
)
{
if
(
_syntaxFacts
.
IsReturnStatement
(
node
))
{
...
...
src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService+CompatAbstractMetadataFormattingRule.cs
浏览文件 @
b03a0623
...
...
@@ -33,10 +33,10 @@ public override sealed void AddAnchorIndentationOperations(List<AnchorIndentatio
[
Obsolete
(
"Do not call this method directly (it will Stack Overflow)."
,
error
:
true
)]
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
public
override
sealed
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
,
in
NextIndentBlockOperationAction
nextOperation
)
public
override
sealed
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
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<AnchorIndentationOpe
/// <summary>
/// returns IndentBlockOperations under a node either by itself or by filtering/replacing operations returned by NextOperation
/// </summary>
public
virtual
void
AddIndentBlockOperationsSlow
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
,
ref
NextIndentBlockOperationAction
nextOperation
)
=>
base
.
AddIndentBlockOperations
(
list
,
node
,
options
,
in
nextOperation
);
public
virtual
void
AddIndentBlockOperationsSlow
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
ref
NextIndentBlockOperationAction
nextOperation
)
=>
base
.
AddIndentBlockOperations
(
list
,
node
,
in
nextOperation
);
/// <summary>
/// returns AlignTokensOperations under a node either by itself or by filtering/replacing operations returned by NextOperation
...
...
src/Features/VisualBasic/Portable/ChangeSignature/ChangeSignatureFormattingRule.vb
浏览文件 @
b03a0623
...
...
@@ -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
...
...
src/VisualStudio/VisualBasic/Impl/Venus/VisualBasicContainedLanguage.vb
浏览文件 @
b03a0623
...
...
@@ -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
...
...
src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.cs
浏览文件 @
b03a0623
...
...
@@ -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
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
,
in
NextIndentBlockOperationAction
nextOperation
)
public
override
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
in
NextIndentBlockOperationAction
nextOperation
)
{
// these nodes should be from syntax tree from ITextSnapshot.
Debug
.
Assert
(
node
.
SyntaxTree
!=
null
);
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/DefaultOperationProvider.cs
浏览文件 @
b03a0623
...
...
@@ -30,7 +30,7 @@ public override void AddAnchorIndentationOperations(List<AnchorIndentationOperat
{
}
public
override
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
,
in
NextIndentBlockOperationAction
nextOperation
)
public
override
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
in
NextIndentBlockOperationAction
nextOperation
)
{
}
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/IndentBlockFormattingRule.cs
浏览文件 @
b03a0623
...
...
@@ -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
<
IndentBlockOperation
>
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
<
IndentBlockOperation
>
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<IndentBlockOperation
}
}
private
void
AddSwitchIndentationOperation
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
)
private
void
AddSwitchIndentationOperation
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
)
{
if
(!(
node
is
SwitchSectionSyntax
section
))
{
...
...
@@ -62,25 +87,23 @@ private void AddSwitchIndentationOperation(List<IndentBlockOperation> 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
&&
indentSwitchCase
WhenBlock
;
var
alwaysIndent
=
_options
.
IndentSwitchCaseSection
&&
_options
.
IndentSwitchCaseSection
WhenBlock
;
if
(!
alwaysIndent
)
{
// Only one of these values can be true at this point.
Debug
.
Assert
(
indentSwitchCase
!=
indentSwitchCase
WhenBlock
);
Debug
.
Assert
(
_options
.
IndentSwitchCaseSection
!=
_options
.
IndentSwitchCaseSection
WhenBlock
);
var
firstStatementIsBlock
=
section
.
Statements
.
Count
>
0
&&
section
.
Statements
[
0
].
IsKind
(
SyntaxKind
.
Block
);
if
(
indentSwitchCase
WhenBlock
!=
firstStatementIsBlock
)
if
(
_options
.
IndentSwitchCaseSection
WhenBlock
!=
firstStatementIsBlock
)
{
return
;
}
...
...
@@ -113,18 +136,16 @@ private void AddSwitchIndentationOperation(List<IndentBlockOperation> list, Synt
AddIndentBlockOperation
(
list
,
startToken
,
endToken
,
span
);
}
private
void
AddLabelIndentationOperation
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
)
private
void
AddLabelIndentationOperation
(
List
<
IndentBlockOperation
>
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<IndentBlockOperation> list, SyntaxN
SetAlignmentBlockOperation
(
list
,
baseToken
,
firstToken
,
lastToken
,
option
);
}
private
void
AddBlockIndentationOperation
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
)
private
void
AddBlockIndentationOperation
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
)
{
var
bracePair
=
node
.
GetBracePair
();
...
...
@@ -200,13 +221,13 @@ private void AddBlockIndentationOperation(List<IndentBlockOperation> 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<IndentBlockOperation
AddIndentBlockOperation
(
list
,
firstToken
,
lastToken
,
TextSpan
.
FromBounds
(
firstToken
.
FullSpan
.
Start
,
lastToken
.
FullSpan
.
End
));
}
}
private
readonly
struct
CachedOptions
:
IEquatable
<
CachedOptions
>
{
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
<
T
>(
AnalyzerConfigOptions
?
options
,
Option2
<
T
>
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
;
}
}
}
}
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/IndentUserSettingsFormattingRule.cs
浏览文件 @
b03a0623
...
...
@@ -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
<
IndentBlockOperation
>
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
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
in
NextIndentBlockOperationAction
nextOperation
)
{
nextOperation
.
Invoke
();
...
...
@@ -24,11 +50,50 @@ public override void AddIndentBlockOperations(List<IndentBlockOperation> 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
<
CachedOptions
>
{
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
<
T
>(
AnalyzerConfigOptions
?
options
,
Option2
<
T
>
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
;
}
}
}
}
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/QueryExpressionFormattingRule.cs
浏览文件 @
b03a0623
...
...
@@ -56,7 +56,7 @@ private void AddIndentBlockOperationsForFromClause(List<IndentBlockOperation> li
AddIndentBlockOperation
(
list
,
baseToken
,
startToken
,
endToken
);
}
public
override
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
,
in
NextIndentBlockOperationAction
nextOperation
)
public
override
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
in
NextIndentBlockOperationAction
nextOperation
)
{
nextOperation
.
Invoke
();
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/ChainedFormattingRules.cs
浏览文件 @
b03a0623
...
...
@@ -60,7 +60,7 @@ public void AddAnchorIndentationOperations(List<AnchorIndentationOperation> list
public
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
currentNode
)
{
var
action
=
new
NextIndentBlockOperationAction
(
_addIndentBlockOperationsRules
,
index
:
0
,
currentNode
,
_options
,
list
);
var
action
=
new
NextIndentBlockOperationAction
(
_addIndentBlockOperationsRules
,
index
:
0
,
currentNode
,
list
);
action
.
Invoke
();
}
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/AbstractFormattingRule.cs
浏览文件 @
b03a0623
...
...
@@ -34,7 +34,7 @@ public virtual void AddAnchorIndentationOperations(List<AnchorIndentationOperati
/// <summary>
/// returns IndentBlockOperations under a node either by itself or by filtering/replacing operations returned by NextOperation
/// </summary>
public
virtual
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
,
in
NextIndentBlockOperationAction
nextOperation
)
public
virtual
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
in
NextIndentBlockOperationAction
nextOperation
)
=>
nextOperation
.
Invoke
();
/// <summary>
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/BaseIndentationFormattingRule.cs
浏览文件 @
b03a0623
...
...
@@ -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
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
,
in
NextIndentBlockOperationAction
nextOperation
)
public
override
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
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<IndentBlockOperation> 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
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
,
in
NextIndentBlockOperationAction
nextOperation
)
private
void
AddNextIndentBlockOperations
(
List
<
IndentBlockOperation
>
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
<
IndentBlockOperation
>
list
)
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/CompatAbstractFormattingRule.cs
浏览文件 @
b03a0623
...
...
@@ -32,10 +32,10 @@ public override sealed void AddAnchorIndentationOperations(List<AnchorIndentatio
[
Obsolete
(
"Do not call this method directly (it will Stack Overflow)."
,
error
:
true
)]
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
public
override
sealed
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
,
in
NextIndentBlockOperationAction
nextOperation
)
public
override
sealed
void
AddIndentBlockOperations
(
List
<
IndentBlockOperation
>
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<AnchorIndentationOpe
/// <summary>
/// returns IndentBlockOperations under a node either by itself or by filtering/replacing operations returned by NextOperation
/// </summary>
public
virtual
void
AddIndentBlockOperationsSlow
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
,
ref
NextIndentBlockOperationAction
nextOperation
)
=>
base
.
AddIndentBlockOperations
(
list
,
node
,
options
,
in
nextOperation
);
public
virtual
void
AddIndentBlockOperationsSlow
(
List
<
IndentBlockOperation
>
list
,
SyntaxNode
node
,
ref
NextIndentBlockOperationAction
nextOperation
)
=>
base
.
AddIndentBlockOperations
(
list
,
node
,
in
nextOperation
);
/// <summary>
/// returns AlignTokensOperations under a node either by itself or by filtering/replacing operations returned by NextOperation
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/NextIndentBlockOperationAction.cs
浏览文件 @
b03a0623
...
...
@@ -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
<
AbstractFormattingRule
>
_formattingRules
;
private
readonly
int
_index
;
private
readonly
SyntaxNode
_node
;
private
readonly
AnalyzerConfigOptions
_options
;
private
readonly
List
<
IndentBlockOperation
>
_list
;
public
NextIndentBlockOperationAction
(
ImmutableArray
<
AbstractFormattingRule
>
formattingRules
,
int
index
,
SyntaxNode
node
,
AnalyzerConfigOptions
options
,
List
<
IndentBlockOperation
>
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
;
}
}
...
...
src/Workspaces/VisualBasic/Portable/Formatting/DefaultOperationProvider.vb
浏览文件 @
b03a0623
...
...
@@ -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
)
...
...
src/Workspaces/VisualBasic/Portable/Formatting/Rules/ElasticTriviaFormattingRule.vb
浏览文件 @
b03a0623
...
...
@@ -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
...
...
src/Workspaces/VisualBasic/Portable/Formatting/Rules/NodeBasedFormattingRule.vb
浏览文件 @
b03a0623
...
...
@@ -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
()
...
...
src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb
浏览文件 @
b03a0623
...
...
@@ -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
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录