Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
7525b7c0
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,发现更多精彩内容 >>
提交
7525b7c0
编写于
4月 13, 2020
作者:
S
Sam Harwell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid passing options to GetAdjustSpacesOperation
上级
93876173
变更
20
展开全部
隐藏空白更改
内联
并排
Showing
20 changed file
with
191 addition
and
128 deletion
+191
-128
src/Features/CSharp/Portable/UseAutoProperty/CSharpUseAutoPropertyCodeFixProvider.cs
...e/UseAutoProperty/CSharpUseAutoPropertyCodeFixProvider.cs
+2
-3
src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService+CompatAbstractMetadataFormattingRule.cs
...taAsSourceService+CompatAbstractMetadataFormattingRule.cs
+4
-5
src/VisualStudio/Core/Def/Implementation/Venus/ContainedDocumentPreserveFormattingRule.cs
...entation/Venus/ContainedDocumentPreserveFormattingRule.cs
+2
-3
src/Workspaces/CSharp/Portable/Indentation/CSharpSmartTokenFormatter.cs
.../CSharp/Portable/Indentation/CSharpSmartTokenFormatter.cs
+2
-3
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/DefaultOperationProvider.cs
...ns/Compiler/CSharp/Formatting/DefaultOperationProvider.cs
+1
-2
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/ElasticTriviaFormattingRule.cs
...er/CSharp/Formatting/Rules/ElasticTriviaFormattingRule.cs
+1
-2
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/EndOfFileTokenFormattingRule.cs
...r/CSharp/Formatting/Rules/EndOfFileTokenFormattingRule.cs
+1
-2
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/NewLineUserSettingFormattingRule.cs
...harp/Formatting/Rules/NewLineUserSettingFormattingRule.cs
+15
-15
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/SpacingFormattingRule.cs
...Compiler/CSharp/Formatting/Rules/SpacingFormattingRule.cs
+132
-45
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/StructuredTriviaFormattingRule.cs
...CSharp/Formatting/Rules/StructuredTriviaFormattingRule.cs
+15
-23
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/TokenBasedFormattingRule.cs
...piler/CSharp/Formatting/Rules/TokenBasedFormattingRule.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/CompatAbstractFormattingRule.cs
...ler/Core/Formatting/Rules/CompatAbstractFormattingRule.cs
+4
-5
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/NextGetAdjustSpacesOperation.cs
...ler/Core/Formatting/Rules/NextGetAdjustSpacesOperation.cs
+3
-7
src/Workspaces/VisualBasic/Portable/Formatting/DefaultOperationProvider.vb
...sualBasic/Portable/Formatting/DefaultOperationProvider.vb
+1
-1
src/Workspaces/VisualBasic/Portable/Formatting/Rules/AdjustSpaceFormattingRule.vb
...ic/Portable/Formatting/Rules/AdjustSpaceFormattingRule.vb
+1
-2
src/Workspaces/VisualBasic/Portable/Formatting/Rules/ElasticTriviaFormattingRule.vb
.../Portable/Formatting/Rules/ElasticTriviaFormattingRule.vb
+1
-2
src/Workspaces/VisualBasic/Portable/Formatting/Rules/StructuredTriviaFormattingRule.vb
...rtable/Formatting/Rules/StructuredTriviaFormattingRule.vb
+1
-2
src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb
...lBasic/Portable/Indentation/SpecialFormattingOperation.vb
+2
-3
未找到文件。
src/Features/CSharp/Portable/UseAutoProperty/CSharpUseAutoPropertyCodeFixProvider.cs
浏览文件 @
7525b7c0
...
...
@@ -10,7 +10,6 @@
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CodeFixes
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Editing
;
using
Microsoft.CodeAnalysis.Formatting
;
using
Microsoft.CodeAnalysis.Formatting.Rules
;
...
...
@@ -114,14 +113,14 @@ public override AdjustNewLinesOperation GetAdjustNewLinesOperation(SyntaxToken p
return
base
.
GetAdjustNewLinesOperation
(
previousToken
,
currentToken
,
in
nextOperation
);
}
public
override
AdjustSpacesOperation
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
,
in
NextGetAdjustSpacesOperation
nextOperation
)
public
override
AdjustSpacesOperation
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
in
NextGetAdjustSpacesOperation
nextOperation
)
{
if
(
ForceSingleSpace
(
previousToken
,
currentToken
))
{
return
new
AdjustSpacesOperation
(
1
,
AdjustSpacesOption
.
ForceSpaces
);
}
return
base
.
GetAdjustSpacesOperation
(
previousToken
,
currentToken
,
options
,
in
nextOperation
);
return
base
.
GetAdjustSpacesOperation
(
previousToken
,
currentToken
,
in
nextOperation
);
}
}
...
...
src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService+CompatAbstractMetadataFormattingRule.cs
浏览文件 @
7525b7c0
...
...
@@ -5,7 +5,6 @@
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Formatting.Rules
;
namespace
Microsoft.CodeAnalysis.MetadataAsSource
...
...
@@ -57,10 +56,10 @@ public override sealed AdjustNewLinesOperation GetAdjustNewLinesOperation(Syntax
[
Obsolete
(
"Do not call this method directly (it will Stack Overflow)."
,
error
:
true
)]
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
public
override
sealed
AdjustSpacesOperation
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
,
in
NextGetAdjustSpacesOperation
nextOperation
)
public
override
sealed
AdjustSpacesOperation
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
in
NextGetAdjustSpacesOperation
nextOperation
)
{
var
nextOperationCopy
=
nextOperation
;
return
GetAdjustSpacesOperationSlow
(
previousToken
,
currentToken
,
options
,
ref
nextOperationCopy
);
return
GetAdjustSpacesOperationSlow
(
previousToken
,
currentToken
,
ref
nextOperationCopy
);
}
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member
...
...
@@ -98,8 +97,8 @@ public virtual AdjustNewLinesOperation GetAdjustNewLinesOperationSlow(SyntaxToke
/// <summary>
/// returns AdjustSpacesOperation between two tokens either by itself or by filtering/replacing a operation returned by NextOperation
/// </summary>
public
virtual
AdjustSpacesOperation
GetAdjustSpacesOperationSlow
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
,
ref
NextGetAdjustSpacesOperation
nextOperation
)
=>
base
.
GetAdjustSpacesOperation
(
previousToken
,
currentToken
,
options
,
in
nextOperation
);
public
virtual
AdjustSpacesOperation
GetAdjustSpacesOperationSlow
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
ref
NextGetAdjustSpacesOperation
nextOperation
)
=>
base
.
GetAdjustSpacesOperation
(
previousToken
,
currentToken
,
in
nextOperation
);
}
}
}
src/VisualStudio/Core/Def/Implementation/Venus/ContainedDocumentPreserveFormattingRule.cs
浏览文件 @
7525b7c0
...
...
@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using
Microsoft.CodeAnalysis
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Formatting.Rules
;
namespace
Microsoft.VisualStudio.LanguageServices.Implementation.Venus
...
...
@@ -15,9 +14,9 @@ internal class ContainedDocumentPreserveFormattingRule : AbstractFormattingRule
private
static
readonly
AdjustSpacesOperation
s_preserveSpace
=
FormattingOperations
.
CreateAdjustSpacesOperation
(
0
,
AdjustSpacesOption
.
PreserveSpaces
);
private
static
readonly
AdjustNewLinesOperation
s_preserveLine
=
FormattingOperations
.
CreateAdjustNewLinesOperation
(
0
,
AdjustNewLinesOption
.
PreserveLines
);
public
override
AdjustSpacesOperation
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
,
in
NextGetAdjustSpacesOperation
nextOperation
)
public
override
AdjustSpacesOperation
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
in
NextGetAdjustSpacesOperation
nextOperation
)
{
var
operation
=
base
.
GetAdjustSpacesOperation
(
previousToken
,
currentToken
,
options
,
in
nextOperation
);
var
operation
=
base
.
GetAdjustSpacesOperation
(
previousToken
,
currentToken
,
in
nextOperation
);
if
(
operation
!=
null
)
{
return
s_preserveSpace
;
...
...
src/Workspaces/CSharp/Portable/Indentation/CSharpSmartTokenFormatter.cs
浏览文件 @
7525b7c0
...
...
@@ -9,7 +9,6 @@
using
Microsoft.CodeAnalysis.CSharp.Extensions
;
using
Microsoft.CodeAnalysis.CSharp.Formatting
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Formatting
;
using
Microsoft.CodeAnalysis.Formatting.Rules
;
using
Microsoft.CodeAnalysis.Indentation
;
...
...
@@ -148,9 +147,9 @@ public override void AddSuppressOperations(List<SuppressOperation> list, SyntaxN
// don't suppress anything
}
public
override
AdjustSpacesOperation
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
,
in
NextGetAdjustSpacesOperation
nextOperation
)
public
override
AdjustSpacesOperation
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
in
NextGetAdjustSpacesOperation
nextOperation
)
{
var
spaceOperation
=
base
.
GetAdjustSpacesOperation
(
previousToken
,
currentToken
,
options
,
in
nextOperation
);
var
spaceOperation
=
base
.
GetAdjustSpacesOperation
(
previousToken
,
currentToken
,
in
nextOperation
);
// if there is force space operation, convert it to ForceSpaceIfSingleLine operation.
// (force space basically means remove all line breaks)
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/DefaultOperationProvider.cs
浏览文件 @
7525b7c0
...
...
@@ -5,7 +5,6 @@
#
nullable
enable
using
System.Collections.Generic
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Formatting.Rules
;
namespace
Microsoft.CodeAnalysis.CSharp.Formatting
...
...
@@ -42,7 +41,7 @@ public override void AddAlignTokensOperations(List<AlignTokensOperation> list, S
=>
null
;
// return 1 space for every token pairs as a default operation
public
override
AdjustSpacesOperation
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
,
in
NextGetAdjustSpacesOperation
nextOperation
)
public
override
AdjustSpacesOperation
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
in
NextGetAdjustSpacesOperation
nextOperation
)
{
var
space
=
currentToken
.
Kind
()
==
SyntaxKind
.
EndOfFileToken
?
0
:
1
;
return
FormattingOperations
.
CreateAdjustSpacesOperation
(
space
,
AdjustSpacesOption
.
DefaultSpacesIfOnSingleLine
);
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/ElasticTriviaFormattingRule.cs
浏览文件 @
7525b7c0
...
...
@@ -11,7 +11,6 @@
using
Microsoft.CodeAnalysis.CSharp.Extensions
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.CSharp.Utilities
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Formatting.Rules
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Shared.Utilities
;
...
...
@@ -219,7 +218,7 @@ private void AddInitializerSuppressOperations(List<SuppressOperation> list, Synt
return
FormattingOperations
.
CreateAdjustNewLinesOperation
(
2
/* +1 for member itself and +1 for a blank line*/
,
AdjustNewLinesOption
.
ForceLines
);
}
public
override
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
,
in
NextGetAdjustSpacesOperation
nextOperation
)
public
override
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
in
NextGetAdjustSpacesOperation
nextOperation
)
{
var
operation
=
nextOperation
.
Invoke
();
if
(
operation
==
null
)
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/EndOfFileTokenFormattingRule.cs
浏览文件 @
7525b7c0
...
...
@@ -4,7 +4,6 @@
#
nullable
enable
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Formatting.Rules
;
namespace
Microsoft.CodeAnalysis.CSharp.Formatting
...
...
@@ -25,7 +24,7 @@ internal class EndOfFileTokenFormattingRule : BaseFormattingRule
return
nextOperation
.
Invoke
();
}
public
override
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
,
in
NextGetAdjustSpacesOperation
nextOperation
)
public
override
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
in
NextGetAdjustSpacesOperation
nextOperation
)
{
// * <End Of File) case
// for C#, make sure we have nothing between these two tokens
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/NewLineUserSettingFormattingRule.cs
浏览文件 @
7525b7c0
...
...
@@ -75,7 +75,7 @@ private bool IsControlBlock(SyntaxNode node)
}
}
public
override
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
,
in
NextGetAdjustSpacesOperation
nextOperation
)
public
override
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
in
NextGetAdjustSpacesOperation
nextOperation
)
{
RoslynDebug
.
AssertNotNull
(
currentToken
.
Parent
);
...
...
@@ -86,7 +86,7 @@ private bool IsControlBlock(SyntaxNode node)
&&
currentToken
.
IsKind
(
SyntaxKind
.
ElseKeyword
)
&&
previousToken
.
Parent
!.
Parent
==
currentToken
.
Parent
.
Parent
)
{
if
(!
options
.
GetOption
(
CSharpFormattingOptions2
.
NewLineForElse
)
)
if
(!
_options
.
NewLineForElse
)
{
operation
=
CreateAdjustSpacesOperation
(
1
,
AdjustSpacesOption
.
ForceSpaces
);
}
...
...
@@ -95,7 +95,7 @@ private bool IsControlBlock(SyntaxNode node)
// * catch in the try catch context
if
(
currentToken
.
IsKind
(
SyntaxKind
.
CatchKeyword
))
{
if
(!
options
.
GetOption
(
CSharpFormattingOptions2
.
NewLineForCatch
)
)
if
(!
_options
.
NewLineForCatch
)
{
operation
=
CreateAdjustSpacesOperation
(
1
,
AdjustSpacesOption
.
ForceSpaces
);
}
...
...
@@ -104,7 +104,7 @@ private bool IsControlBlock(SyntaxNode node)
// * finally
if
(
currentToken
.
IsKind
(
SyntaxKind
.
FinallyKeyword
))
{
if
(!
options
.
GetOption
(
CSharpFormattingOptions2
.
NewLineForFinally
)
)
if
(!
_options
.
NewLineForFinally
)
{
operation
=
CreateAdjustSpacesOperation
(
1
,
AdjustSpacesOption
.
ForceSpaces
);
}
...
...
@@ -113,7 +113,7 @@ private bool IsControlBlock(SyntaxNode node)
// * { in the type declaration context
if
(
currentToken
.
Kind
()
==
SyntaxKind
.
OpenBraceToken
&&
(
currentToken
.
Parent
is
BaseTypeDeclarationSyntax
||
currentToken
.
Parent
is
NamespaceDeclarationSyntax
))
{
if
(!
options
.
GetOption
(
CSharpFormattingOptions2
.
NewLinesForBracesInTypes
)
)
if
(!
_options
.
NewLinesForBracesInTypes
)
{
operation
=
CreateAdjustSpacesOperation
(
1
,
AdjustSpacesOption
.
ForceSpaces
);
}
...
...
@@ -122,7 +122,7 @@ private bool IsControlBlock(SyntaxNode node)
// new { - Anonymous object creation
if
(
currentToken
.
IsKind
(
SyntaxKind
.
OpenBraceToken
)
&&
currentToken
.
Parent
.
IsKind
(
SyntaxKind
.
AnonymousObjectCreationExpression
))
{
if
(!
options
.
GetOption
(
CSharpFormattingOptions2
.
NewLinesForBracesInAnonymousTypes
)
)
if
(!
_options
.
NewLinesForBracesInAnonymousTypes
)
{
operation
=
CreateAdjustSpacesOperation
(
1
,
AdjustSpacesOption
.
ForceSpaces
);
}
...
...
@@ -131,7 +131,7 @@ private bool IsControlBlock(SyntaxNode node)
// new { - Object Initialization
if
(
currentToken
.
IsKind
(
SyntaxKind
.
OpenBraceToken
)
&&
currentToken
.
Parent
.
IsKind
(
SyntaxKind
.
ObjectInitializerExpression
))
{
if
(!
options
.
GetOption
(
CSharpFormattingOptions2
.
NewLinesForBracesInObjectCollectionArrayInitializers
)
)
if
(!
_options
.
NewLinesForBracesInObjectCollectionArrayInitializers
)
{
operation
=
CreateAdjustSpacesOperation
(
1
,
AdjustSpacesOption
.
ForceSpaces
);
}
...
...
@@ -143,10 +143,10 @@ private bool IsControlBlock(SyntaxNode node)
if
(
currentToken
.
IsKind
(
SyntaxKind
.
OpenBraceToken
)
&&
currentTokenParentParent
!=
null
&&
currentTokenParentParent
is
MemberDeclarationSyntax
)
{
var
option
=
currentTokenParentParent
is
BasePropertyDeclarationSyntax
?
CSharpFormattingOptions2
.
NewLinesForBracesInProperties
:
CSharpFormattingOptions2
.
NewLinesForBracesInMethods
;
?
_options
.
NewLinesForBracesInProperties
:
_options
.
NewLinesForBracesInMethods
;
if
(!
option
s
.
GetOption
(
option
)
)
if
(!
option
)
{
operation
=
CreateAdjustSpacesOperation
(
1
,
AdjustSpacesOption
.
ForceSpaces
);
}
...
...
@@ -154,7 +154,7 @@ private bool IsControlBlock(SyntaxNode node)
if
(
currentToken
.
IsKind
(
SyntaxKind
.
OpenBraceToken
)
&&
currentTokenParentParent
!=
null
&&
currentTokenParentParent
is
AccessorDeclarationSyntax
)
{
if
(!
options
.
GetOption
(
CSharpFormattingOptions2
.
NewLinesForBracesInAccessors
)
)
if
(!
_options
.
NewLinesForBracesInAccessors
)
{
operation
=
CreateAdjustSpacesOperation
(
1
,
AdjustSpacesOption
.
ForceSpaces
);
}
...
...
@@ -163,7 +163,7 @@ private bool IsControlBlock(SyntaxNode node)
// * { - in the anonymous Method context
if
(
currentToken
.
IsKind
(
SyntaxKind
.
OpenBraceToken
)
&&
currentTokenParentParent
!=
null
&&
currentTokenParentParent
.
IsKind
(
SyntaxKind
.
AnonymousMethodExpression
))
{
if
(!
options
.
GetOption
(
CSharpFormattingOptions2
.
NewLinesForBracesInAnonymousMethods
)
)
if
(!
_options
.
NewLinesForBracesInAnonymousMethods
)
{
operation
=
CreateAdjustSpacesOperation
(
1
,
AdjustSpacesOption
.
ForceSpaces
);
}
...
...
@@ -172,7 +172,7 @@ private bool IsControlBlock(SyntaxNode node)
// * { - in the local function context
if
(
currentToken
.
IsKind
(
SyntaxKind
.
OpenBraceToken
)
&&
currentTokenParentParent
!=
null
&&
currentTokenParentParent
.
IsKind
(
SyntaxKind
.
LocalFunctionStatement
))
{
if
(!
options
.
GetOption
(
CSharpFormattingOptions2
.
NewLinesForBracesInMethods
)
)
if
(!
_options
.
NewLinesForBracesInMethods
)
{
operation
=
CreateAdjustSpacesOperation
(
1
,
AdjustSpacesOption
.
ForceSpaces
);
}
...
...
@@ -182,7 +182,7 @@ private bool IsControlBlock(SyntaxNode node)
if
(
currentToken
.
IsKind
(
SyntaxKind
.
OpenBraceToken
)
&&
currentTokenParentParent
!=
null
&&
(
currentTokenParentParent
.
IsKind
(
SyntaxKind
.
SimpleLambdaExpression
)
||
currentTokenParentParent
.
IsKind
(
SyntaxKind
.
ParenthesizedLambdaExpression
)))
{
if
(!
options
.
GetOption
(
CSharpFormattingOptions2
.
NewLinesForBracesInLambdaExpressionBody
)
)
if
(!
_options
.
NewLinesForBracesInLambdaExpressionBody
)
{
operation
=
CreateAdjustSpacesOperation
(
1
,
AdjustSpacesOption
.
ForceSpaces
);
}
...
...
@@ -191,7 +191,7 @@ private bool IsControlBlock(SyntaxNode node)
// * { - in the control statement context
if
(
currentToken
.
Kind
()
==
SyntaxKind
.
OpenBraceToken
&&
IsControlBlock
(
currentToken
.
Parent
))
{
if
(!
options
.
GetOption
(
CSharpFormattingOptions2
.
NewLinesForBracesInControlBlocks
)
)
if
(!
_options
.
NewLinesForBracesInControlBlocks
)
{
operation
=
CreateAdjustSpacesOperation
(
1
,
AdjustSpacesOption
.
ForceSpaces
);
}
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/SpacingFormattingRule.cs
浏览文件 @
7525b7c0
此差异已折叠。
点击以展开。
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/StructuredTriviaFormattingRule.cs
浏览文件 @
7525b7c0
...
...
@@ -5,7 +5,6 @@
#
nullable
enable
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Formatting.Rules
;
namespace
Microsoft.CodeAnalysis.CSharp.Formatting
...
...
@@ -24,32 +23,25 @@ internal class StructuredTriviaFormattingRule : BaseFormattingRule
return
nextOperation
.
Invoke
();
}
public
override
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
,
in
NextGetAdjustSpacesOperation
nextOperation
)
public
override
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
in
NextGetAdjustSpacesOperation
nextOperation
)
{
if
(
previousToken
.
Parent
is
StructuredTriviaSyntax
||
currentToken
.
Parent
is
StructuredTriviaSyntax
)
{
// this doesn't take care of all cases where tokens belong to structured trivia. this is only for cases we care
return
GetAdjustSpacesOperation
(
previousToken
,
currentToken
,
in
nextOperation
);
}
return
nextOperation
.
Invoke
();
}
private
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
in
NextGetAdjustSpacesOperation
nextOperation
)
{
if
(
previousToken
.
Kind
()
==
SyntaxKind
.
HashToken
&&
SyntaxFacts
.
IsPreprocessorKeyword
(
currentToken
.
Kind
()))
{
return
CreateAdjustSpacesOperation
(
space
:
0
,
option
:
AdjustSpacesOption
.
ForceSpacesIfOnSingleLine
);
}
if
(
previousToken
.
Kind
()
==
SyntaxKind
.
RegionKeyword
&&
currentToken
.
Kind
()
==
SyntaxKind
.
EndOfDirectiveToken
)
{
return
CreateAdjustSpacesOperation
(
space
:
0
,
option
:
AdjustSpacesOption
.
PreserveSpaces
);
}
if
(
currentToken
.
Kind
()
==
SyntaxKind
.
EndOfDirectiveToken
)
{
return
CreateAdjustSpacesOperation
(
space
:
0
,
option
:
AdjustSpacesOption
.
ForceSpacesIfOnSingleLine
);
if
(
previousToken
.
Kind
()
==
SyntaxKind
.
HashToken
&&
SyntaxFacts
.
IsPreprocessorKeyword
(
currentToken
.
Kind
()))
{
return
CreateAdjustSpacesOperation
(
space
:
0
,
option
:
AdjustSpacesOption
.
ForceSpacesIfOnSingleLine
);
}
if
(
previousToken
.
Kind
()
==
SyntaxKind
.
RegionKeyword
&&
currentToken
.
Kind
()
==
SyntaxKind
.
EndOfDirectiveToken
)
{
return
CreateAdjustSpacesOperation
(
space
:
0
,
option
:
AdjustSpacesOption
.
PreserveSpaces
);
}
if
(
currentToken
.
Kind
()
==
SyntaxKind
.
EndOfDirectiveToken
)
{
return
CreateAdjustSpacesOperation
(
space
:
0
,
option
:
AdjustSpacesOption
.
ForceSpacesIfOnSingleLine
);
}
}
return
nextOperation
.
Invoke
();
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/TokenBasedFormattingRule.cs
浏览文件 @
7525b7c0
...
...
@@ -256,7 +256,7 @@ private static SyntaxList<UsingDirectiveSyntax> GetUsings(SyntaxNode node)
_
=>
throw
ExceptionUtilities
.
UnexpectedValue
(
node
.
Kind
()),
};
public
override
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
,
in
NextGetAdjustSpacesOperation
nextOperation
)
public
override
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
in
NextGetAdjustSpacesOperation
nextOperation
)
{
//////////////////////////////////////////////////////
// ";" related operations
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/ChainedFormattingRules.cs
浏览文件 @
7525b7c0
...
...
@@ -78,7 +78,7 @@ public void AddAlignTokensOperations(List<AlignTokensOperation> list, SyntaxNode
public
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
)
{
var
action
=
new
NextGetAdjustSpacesOperation
(
_getAdjustSpacesOperationRules
,
index
:
0
,
previousToken
,
currentToken
,
_options
);
var
action
=
new
NextGetAdjustSpacesOperation
(
_getAdjustSpacesOperationRules
,
index
:
0
,
previousToken
,
currentToken
);
return
action
.
Invoke
();
}
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/AbstractFormattingRule.cs
浏览文件 @
7525b7c0
...
...
@@ -52,7 +52,7 @@ public virtual void AddAlignTokensOperations(List<AlignTokensOperation> list, Sy
/// <summary>
/// returns AdjustSpacesOperation between two tokens either by itself or by filtering/replacing a operation returned by NextOperation
/// </summary>
public
virtual
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
,
in
NextGetAdjustSpacesOperation
nextOperation
)
public
virtual
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
in
NextGetAdjustSpacesOperation
nextOperation
)
=>
nextOperation
.
Invoke
();
}
}
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/CompatAbstractFormattingRule.cs
浏览文件 @
7525b7c0
...
...
@@ -7,7 +7,6 @@
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
Microsoft.CodeAnalysis.Diagnostics
;
namespace
Microsoft.CodeAnalysis.Formatting.Rules
{
...
...
@@ -56,10 +55,10 @@ public override sealed void AddAlignTokensOperations(List<AlignTokensOperation>
[
Obsolete
(
"Do not call this method directly (it will Stack Overflow)."
,
error
:
true
)]
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
public
override
sealed
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
,
in
NextGetAdjustSpacesOperation
nextOperation
)
public
override
sealed
AdjustSpacesOperation
?
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
in
NextGetAdjustSpacesOperation
nextOperation
)
{
var
nextOperationCopy
=
nextOperation
;
return
GetAdjustSpacesOperationSlow
(
previousToken
,
currentToken
,
options
,
ref
nextOperationCopy
);
return
GetAdjustSpacesOperationSlow
(
previousToken
,
currentToken
,
ref
nextOperationCopy
);
}
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member
...
...
@@ -97,7 +96,7 @@ public virtual void AddAlignTokensOperationsSlow(List<AlignTokensOperation> list
/// <summary>
/// returns AdjustSpacesOperation between two tokens either by itself or by filtering/replacing a operation returned by NextOperation
/// </summary>
public
virtual
AdjustSpacesOperation
?
GetAdjustSpacesOperationSlow
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
,
ref
NextGetAdjustSpacesOperation
nextOperation
)
=>
base
.
GetAdjustSpacesOperation
(
previousToken
,
currentToken
,
options
,
in
nextOperation
);
public
virtual
AdjustSpacesOperation
?
GetAdjustSpacesOperationSlow
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
ref
NextGetAdjustSpacesOperation
nextOperation
)
=>
base
.
GetAdjustSpacesOperation
(
previousToken
,
currentToken
,
in
nextOperation
);
}
}
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Rules/NextGetAdjustSpacesOperation.cs
浏览文件 @
7525b7c0
...
...
@@ -5,7 +5,6 @@
#
nullable
enable
using
System.Collections.Immutable
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Formatting.Rules
...
...
@@ -17,24 +16,21 @@ namespace Microsoft.CodeAnalysis.Formatting.Rules
private
readonly
int
_index
;
private
readonly
SyntaxToken
_previousToken
;
private
readonly
SyntaxToken
_currentToken
;
private
readonly
AnalyzerConfigOptions
_options
;
public
NextGetAdjustSpacesOperation
(
ImmutableArray
<
AbstractFormattingRule
>
formattingRules
,
int
index
,
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
AnalyzerConfigOptions
options
)
SyntaxToken
currentToken
)
{
_formattingRules
=
formattingRules
;
_index
=
index
;
_previousToken
=
previousToken
;
_currentToken
=
currentToken
;
_options
=
options
;
}
private
NextGetAdjustSpacesOperation
NextOperation
=>
new
NextGetAdjustSpacesOperation
(
_formattingRules
,
_index
+
1
,
_previousToken
,
_currentToken
,
_options
);
=>
new
NextGetAdjustSpacesOperation
(
_formattingRules
,
_index
+
1
,
_previousToken
,
_currentToken
);
public
AdjustSpacesOperation
?
Invoke
()
{
...
...
@@ -46,7 +42,7 @@ private NextGetAdjustSpacesOperation NextOperation
else
{
// Call the handler at the index, passing a continuation that will come back to here with index + 1
return
_formattingRules
[
_index
].
GetAdjustSpacesOperation
(
_previousToken
,
_currentToken
,
_options
,
NextOperation
);
return
_formattingRules
[
_index
].
GetAdjustSpacesOperation
(
_previousToken
,
_currentToken
,
NextOperation
);
}
}
}
...
...
src/Workspaces/VisualBasic/Portable/Formatting/DefaultOperationProvider.vb
浏览文件 @
7525b7c0
...
...
@@ -209,7 +209,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting
End
Function
' return 1 space for every token pairs as a default operation
Public
Overrides
Function
GetAdjustSpacesOperationSlow
(
previousToken
As
SyntaxToken
,
currentToken
As
SyntaxToken
,
options
As
AnalyzerConfigOptions
,
ByRef
nextOperation
As
NextGetAdjustSpacesOperation
)
As
AdjustSpacesOperation
Public
Overrides
Function
GetAdjustSpacesOperationSlow
(
previousToken
As
SyntaxToken
,
currentToken
As
SyntaxToken
,
ByRef
nextOperation
As
NextGetAdjustSpacesOperation
)
As
AdjustSpacesOperation
If
previousToken
.
Kind
=
SyntaxKind
.
ColonToken
AndAlso
TypeOf
previousToken
.
Parent
Is
LabelStatementSyntax
AndAlso
currentToken
.
Kind
<>
SyntaxKind
.
EndOfFileToken
Then
...
...
src/Workspaces/VisualBasic/Portable/Formatting/Rules/AdjustSpaceFormattingRule.vb
浏览文件 @
7525b7c0
...
...
@@ -2,7 +2,6 @@
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports
Microsoft.CodeAnalysis.Diagnostics
Imports
Microsoft.CodeAnalysis.Formatting.Rules
Imports
Microsoft.CodeAnalysis.VisualBasic.Syntax
...
...
@@ -14,7 +13,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting
Public
Sub
New
()
End
Sub
Public
Overrides
Function
GetAdjustSpacesOperationSlow
(
previousToken
As
SyntaxToken
,
currentToken
As
SyntaxToken
,
options
As
AnalyzerConfigOptions
,
ByRef
nextFunc
As
NextGetAdjustSpacesOperation
)
As
AdjustSpacesOperation
Public
Overrides
Function
GetAdjustSpacesOperationSlow
(
previousToken
As
SyntaxToken
,
currentToken
As
SyntaxToken
,
ByRef
nextFunc
As
NextGetAdjustSpacesOperation
)
As
AdjustSpacesOperation
' * <end of file token>
If
currentToken
.
Kind
=
SyntaxKind
.
EndOfFileToken
Then
Return
CreateAdjustSpacesOperation
(
0
,
AdjustSpacesOption
.
ForceSpacesIfOnSingleLine
)
...
...
src/Workspaces/VisualBasic/Portable/Formatting/Rules/ElasticTriviaFormattingRule.vb
浏览文件 @
7525b7c0
...
...
@@ -2,7 +2,6 @@
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports
Microsoft.CodeAnalysis.Diagnostics
Imports
Microsoft.CodeAnalysis.Formatting
Imports
Microsoft.CodeAnalysis.Formatting.Rules
Imports
Microsoft.CodeAnalysis.VisualBasic.Syntax
...
...
@@ -85,7 +84,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting
End
If
End
Sub
Public
Overrides
Function
GetAdjustSpacesOperationSlow
(
previousToken
As
SyntaxToken
,
currentToken
As
SyntaxToken
,
options
As
AnalyzerConfigOptions
,
ByRef
nextOperation
As
NextGetAdjustSpacesOperation
)
As
AdjustSpacesOperation
Public
Overrides
Function
GetAdjustSpacesOperationSlow
(
previousToken
As
SyntaxToken
,
currentToken
As
SyntaxToken
,
ByRef
nextOperation
As
NextGetAdjustSpacesOperation
)
As
AdjustSpacesOperation
' if it doesn't have elastic trivia, pass it through
If
Not
CommonFormattingHelpers
.
HasAnyWhitespaceElasticTrivia
(
previousToken
,
currentToken
)
Then
Return
nextOperation
.
Invoke
()
...
...
src/Workspaces/VisualBasic/Portable/Formatting/Rules/StructuredTriviaFormattingRule.vb
浏览文件 @
7525b7c0
...
...
@@ -2,7 +2,6 @@
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports
Microsoft.CodeAnalysis.Diagnostics
Imports
Microsoft.CodeAnalysis.Formatting.Rules
Imports
Microsoft.CodeAnalysis.VisualBasic.Syntax
...
...
@@ -23,7 +22,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting
End
Function
Public
Overrides
Function
GetAdjustSpacesOperationSlow
(
previousToken
As
SyntaxToken
,
currentToken
As
SyntaxToken
,
options
As
AnalyzerConfigOptions
,
ByRef
nextOperation
As
NextGetAdjustSpacesOperation
)
As
AdjustSpacesOperation
Public
Overrides
Function
GetAdjustSpacesOperationSlow
(
previousToken
As
SyntaxToken
,
currentToken
As
SyntaxToken
,
ByRef
nextOperation
As
NextGetAdjustSpacesOperation
)
As
AdjustSpacesOperation
If
UnderStructuredTrivia
(
previousToken
,
currentToken
)
Then
If
previousToken
.
Kind
=
SyntaxKind
.
HashToken
AndAlso
SyntaxFacts
.
IsPreprocessorKeyword
(
CType
(
currentToken
.
Kind
,
SyntaxKind
))
Then
Return
CreateAdjustSpacesOperation
(
space
:
=
0
,
option
:
=
AdjustSpacesOption
.
ForceSpacesIfOnSingleLine
)
...
...
src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb
浏览文件 @
7525b7c0
...
...
@@ -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
Imports
Microsoft.CodeAnalysis.Formatting.Rules
Imports
Microsoft.CodeAnalysis.Text
...
...
@@ -42,8 +41,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation
Return
Nothing
End
Function
Public
Overrides
Function
GetAdjustSpacesOperationSlow
(
previousToken
As
SyntaxToken
,
currentToken
As
SyntaxToken
,
options
As
AnalyzerConfigOptions
,
ByRef
nextOperation
As
NextGetAdjustSpacesOperation
)
As
AdjustSpacesOperation
Dim
spaceOperation
=
MyBase
.
GetAdjustSpacesOperationSlow
(
previousToken
,
currentToken
,
options
,
nextOperation
)
Public
Overrides
Function
GetAdjustSpacesOperationSlow
(
previousToken
As
SyntaxToken
,
currentToken
As
SyntaxToken
,
ByRef
nextOperation
As
NextGetAdjustSpacesOperation
)
As
AdjustSpacesOperation
Dim
spaceOperation
=
MyBase
.
GetAdjustSpacesOperationSlow
(
previousToken
,
currentToken
,
nextOperation
)
' if there is force space operation, convert it to ForceSpaceIfSingleLine operation.
' (force space basically means remove all line breaks)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录