Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
994de1cd
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,发现更多精彩内容 >>
提交
994de1cd
编写于
11月 10, 2015
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make code more async.
上级
4593c127
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
79 addition
and
57 deletion
+79
-57
src/Features/CSharp/Portable/CodeFixes/Suppression/CSharpSuppressionCodeFixProvider.cs
...CodeFixes/Suppression/CSharpSuppressionCodeFixProvider.cs
+9
-6
src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.PragmaHelpers.cs
...ssion/AbstractSuppressionCodeFixProvider.PragmaHelpers.cs
+24
-12
src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.PragmaWarningCodeAction.cs
...ractSuppressionCodeFixProvider.PragmaWarningCodeAction.cs
+14
-4
src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction_Pragma.cs
...sionCodeFixProvider.RemoveSuppressionCodeAction_Pragma.cs
+24
-27
src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.cs
...deFixes/Suppression/AbstractSuppressionCodeFixProvider.cs
+2
-2
src/Features/VisualBasic/Portable/CodeFixes/Suppression/VisualBasicSuppressionCodeFixProvider.vb
...ixes/Suppression/VisualBasicSuppressionCodeFixProvider.vb
+6
-6
未找到文件。
src/Features/CSharp/Portable/CodeFixes/Suppression/CSharpSuppressionCodeFixProvider.cs
浏览文件 @
994de1cd
...
...
@@ -5,6 +5,7 @@
using
System.Globalization
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CodeFixes
;
using
Microsoft.CodeAnalysis.CodeFixes.Suppression
;
using
Microsoft.CodeAnalysis.CSharp.Extensions
;
...
...
@@ -16,24 +17,26 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.Suppression
[
ExportSuppressionFixProvider
(
PredefinedCodeFixProviderNames
.
Suppression
,
LanguageNames
.
CSharp
),
Shared
]
internal
class
CSharpSuppressionCodeFixProvider
:
AbstractSuppressionCodeFixProvider
{
protected
override
SyntaxTriviaList
CreatePragmaRestoreDirectiveTrivia
(
Diagnostic
diagnostic
,
Func
<
SyntaxNode
,
SyntaxNode
>
formatNode
,
bool
needsLeadingEndOfLine
,
bool
needsTrailingEndOfLine
)
protected
override
Task
<
SyntaxTriviaList
>
CreatePragmaRestoreDirectiveTriviaAsync
(
Diagnostic
diagnostic
,
Func
<
SyntaxNode
,
Task
<
SyntaxNode
>
>
formatNode
,
bool
needsLeadingEndOfLine
,
bool
needsTrailingEndOfLine
)
{
var
restoreKeyword
=
SyntaxFactory
.
Token
(
SyntaxKind
.
RestoreKeyword
);
return
CreatePragmaDirectiveTrivia
(
restoreKeyword
,
diagnostic
,
formatNode
,
needsLeadingEndOfLine
,
needsTrailingEndOfLine
);
return
CreatePragmaDirectiveTrivia
Async
(
restoreKeyword
,
diagnostic
,
formatNode
,
needsLeadingEndOfLine
,
needsTrailingEndOfLine
);
}
protected
override
SyntaxTriviaList
CreatePragmaDisableDirectiveTrivia
(
Diagnostic
diagnostic
,
Func
<
SyntaxNode
,
SyntaxNode
>
formatNode
,
bool
needsLeadingEndOfLine
,
bool
needsTrailingEndOfLine
)
protected
override
Task
<
SyntaxTriviaList
>
CreatePragmaDisableDirectiveTriviaAsync
(
Diagnostic
diagnostic
,
Func
<
SyntaxNode
,
Task
<
SyntaxNode
>>
formatNode
,
bool
needsLeadingEndOfLine
,
bool
needsTrailingEndOfLine
)
{
var
disableKeyword
=
SyntaxFactory
.
Token
(
SyntaxKind
.
DisableKeyword
);
return
CreatePragmaDirectiveTrivia
(
disableKeyword
,
diagnostic
,
formatNode
,
needsLeadingEndOfLine
,
needsTrailingEndOfLine
);
return
CreatePragmaDirectiveTrivia
Async
(
disableKeyword
,
diagnostic
,
formatNode
,
needsLeadingEndOfLine
,
needsTrailingEndOfLine
);
}
private
SyntaxTriviaList
CreatePragmaDirectiveTrivia
(
SyntaxToken
disableOrRestoreKeyword
,
Diagnostic
diagnostic
,
Func
<
SyntaxNode
,
SyntaxNode
>
formatNode
,
bool
needsLeadingEndOfLine
,
bool
needsTrailingEndOfLine
)
private
async
Task
<
SyntaxTriviaList
>
CreatePragmaDirectiveTriviaAsync
(
SyntaxToken
disableOrRestoreKeyword
,
Diagnostic
diagnostic
,
Func
<
SyntaxNode
,
Task
<
SyntaxNode
>>
formatNode
,
bool
needsLeadingEndOfLine
,
bool
needsTrailingEndOfLine
)
{
var
id
=
SyntaxFactory
.
IdentifierName
(
diagnostic
.
Id
);
var
ids
=
new
SeparatedSyntaxList
<
ExpressionSyntax
>().
Add
(
id
);
var
pragmaDirective
=
SyntaxFactory
.
PragmaWarningDirectiveTrivia
(
disableOrRestoreKeyword
,
ids
,
true
);
pragmaDirective
=
(
PragmaWarningDirectiveTriviaSyntax
)
formatNode
(
pragmaDirectiv
e
);
pragmaDirective
=
(
PragmaWarningDirectiveTriviaSyntax
)
await
formatNode
(
pragmaDirective
).
ConfigureAwait
(
fals
e
);
var
pragmaDirectiveTrivia
=
SyntaxFactory
.
Trivia
(
pragmaDirective
);
var
endOfLineTrivia
=
SyntaxFactory
.
ElasticCarriageReturnLineFeed
;
var
triviaList
=
SyntaxFactory
.
TriviaList
(
pragmaDirectiveTrivia
);
...
...
src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.PragmaHelpers.cs
浏览文件 @
994de1cd
...
...
@@ -22,8 +22,8 @@ private static class PragmaHelpers
Document
document
,
TextSpan
diagnosticSpan
,
SuppressionTargetInfo
suppressionTargetInfo
,
Func
<
SyntaxToken
,
TextSpan
,
SyntaxToken
>
getNewStartToken
,
Func
<
SyntaxToken
,
TextSpan
,
SyntaxToken
>
getNewEndToken
,
Func
<
SyntaxToken
,
TextSpan
,
Task
<
SyntaxToken
>
>
getNewStartToken
,
Func
<
SyntaxToken
,
TextSpan
,
Task
<
SyntaxToken
>
>
getNewEndToken
,
CancellationToken
cancellationToken
)
{
var
startToken
=
suppressionTargetInfo
.
StartToken
;
...
...
@@ -32,7 +32,7 @@ private static class PragmaHelpers
var
root
=
await
nodeWithTokens
.
SyntaxTree
.
GetRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
startAndEndTokenAreTheSame
=
startToken
==
endToken
;
SyntaxToken
newStartToken
=
getNewStartToken
(
startToken
,
diagnosticSpan
);
SyntaxToken
newStartToken
=
await
getNewStartToken
(
startToken
,
diagnosticSpan
).
ConfigureAwait
(
false
);
SyntaxToken
newEndToken
=
endToken
;
if
(
startAndEndTokenAreTheSame
)
...
...
@@ -43,7 +43,7 @@ private static class PragmaHelpers
diagnosticSpan
=
new
TextSpan
(
diagnosticSpan
.
Start
+
spanChange
,
diagnosticSpan
.
Length
);
}
newEndToken
=
getNewEndToken
(
newEndToken
,
diagnosticSpan
);
newEndToken
=
await
getNewEndToken
(
newEndToken
,
diagnosticSpan
).
ConfigureAwait
(
false
);
SyntaxNode
newNode
;
if
(
startAndEndTokenAreTheSame
)
...
...
@@ -98,7 +98,13 @@ private static int GetPositionForPragmaInsertion(ImmutableArray<SyntaxTrivia> tr
return
index
;
}
internal
static
SyntaxToken
GetNewStartTokenWithAddedPragma
(
SyntaxToken
startToken
,
TextSpan
currentDiagnosticSpan
,
Diagnostic
diagnostic
,
AbstractSuppressionCodeFixProvider
fixer
,
Func
<
SyntaxNode
,
SyntaxNode
>
formatNode
,
bool
isRemoveSuppression
=
false
)
internal
static
async
Task
<
SyntaxToken
>
GetNewStartTokenWithAddedPragmaAsync
(
SyntaxToken
startToken
,
TextSpan
currentDiagnosticSpan
,
Diagnostic
diagnostic
,
AbstractSuppressionCodeFixProvider
fixer
,
Func
<
SyntaxNode
,
Task
<
SyntaxNode
>>
formatNode
,
bool
isRemoveSuppression
=
false
)
{
var
trivia
=
startToken
.
LeadingTrivia
.
ToImmutableArray
();
SyntaxTrivia
insertAfterTrivia
;
...
...
@@ -119,14 +125,20 @@ internal static SyntaxToken GetNewStartTokenWithAddedPragma(SyntaxToken startTok
needsLeadingEOL
=
true
;
}
var
pragmaTrivia
=
!
isRemoveSuppression
?
fixer
.
CreatePragmaDisableDirectiveTrivia
(
diagnostic
,
formatNode
,
needsLeadingEOL
,
needsTrailingEndOfLine
:
true
)
:
fixer
.
CreatePragmaRestoreDirectiveTrivia
(
diagnostic
,
formatNode
,
needsLeadingEOL
,
needsTrailingEndOfLine
:
tru
e
);
var
pragmaTrivia
=
!
isRemoveSuppression
?
await
fixer
.
CreatePragmaDisableDirectiveTriviaAsync
(
diagnostic
,
formatNode
,
needsLeadingEOL
,
needsTrailingEndOfLine
:
true
).
ConfigureAwait
(
false
)
:
await
fixer
.
CreatePragmaRestoreDirectiveTriviaAsync
(
diagnostic
,
formatNode
,
needsLeadingEOL
,
needsTrailingEndOfLine
:
true
).
ConfigureAwait
(
fals
e
);
return
startToken
.
WithLeadingTrivia
(
trivia
.
InsertRange
(
index
,
pragmaTrivia
));
}
internal
static
SyntaxToken
GetNewEndTokenWithAddedPragma
(
SyntaxToken
endToken
,
TextSpan
currentDiagnosticSpan
,
Diagnostic
diagnostic
,
AbstractSuppressionCodeFixProvider
fixer
,
Func
<
SyntaxNode
,
SyntaxNode
>
formatNode
,
bool
isRemoveSuppression
=
false
)
internal
static
async
Task
<
SyntaxToken
>
GetNewEndTokenWithAddedPragmaAsync
(
SyntaxToken
endToken
,
TextSpan
currentDiagnosticSpan
,
Diagnostic
diagnostic
,
AbstractSuppressionCodeFixProvider
fixer
,
Func
<
SyntaxNode
,
Task
<
SyntaxNode
>>
formatNode
,
bool
isRemoveSuppression
=
false
)
{
ImmutableArray
<
SyntaxTrivia
>
trivia
;
var
isEOF
=
fixer
.
IsEndOfFileToken
(
endToken
);
...
...
@@ -156,9 +168,9 @@ internal static SyntaxToken GetNewEndTokenWithAddedPragma(SyntaxToken endToken,
needsTrailingEOL
=
true
;
}
var
pragmaTrivia
=
!
isRemoveSuppression
?
fixer
.
CreatePragmaRestoreDirectiveTrivia
(
diagnostic
,
formatNode
,
needsLeadingEndOfLine
:
true
,
needsTrailingEndOfLine
:
needsTrailingEOL
)
:
fixer
.
CreatePragmaDisableDirectiveTrivia
(
diagnostic
,
formatNode
,
needsLeadingEndOfLine
:
true
,
needsTrailingEndOfLine
:
needsTrailingEOL
);
var
pragmaTrivia
=
!
isRemoveSuppression
?
await
fixer
.
CreatePragmaRestoreDirectiveTriviaAsync
(
diagnostic
,
formatNode
,
needsLeadingEndOfLine
:
true
,
needsTrailingEndOfLine
:
needsTrailingEOL
).
ConfigureAwait
(
false
)
:
await
fixer
.
CreatePragmaDisableDirectiveTriviaAsync
(
diagnostic
,
formatNode
,
needsLeadingEndOfLine
:
true
,
needsTrailingEndOfLine
:
needsTrailingEOL
).
ConfigureAwait
(
false
);
if
(
isEOF
)
{
...
...
src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.PragmaWarningCodeAction.cs
浏览文件 @
994de1cd
...
...
@@ -61,17 +61,27 @@ public async Task<Document> GetChangedDocumentAsync(bool includeStartTokenChange
_document
,
_diagnostic
.
Location
.
SourceSpan
,
_suppressionTargetInfo
,
(
startToken
,
currentDiagnosticSpan
)
=>
includeStartTokenChange
?
PragmaHelpers
.
GetNewStartTokenWithAddedPragma
(
startToken
,
currentDiagnosticSpan
,
_diagnostic
,
Fixer
,
FormatNode
)
:
startToken
,
(
endToken
,
currentDiagnosticSpan
)
=>
includeEndTokenChange
?
PragmaHelpers
.
GetNewEndTokenWithAddedPragma
(
endToken
,
currentDiagnosticSpan
,
_diagnostic
,
Fixer
,
FormatNode
)
:
endToken
,
async
(
startToken
,
currentDiagnosticSpan
)
=>
{
return
includeStartTokenChange
?
await
PragmaHelpers
.
GetNewStartTokenWithAddedPragmaAsync
(
startToken
,
currentDiagnosticSpan
,
_diagnostic
,
Fixer
,
FormatNodeAsync
).
ConfigureAwait
(
false
)
:
startToken
;
},
async
(
endToken
,
currentDiagnosticSpan
)
=>
{
return
includeEndTokenChange
?
await
PragmaHelpers
.
GetNewEndTokenWithAddedPragmaAsync
(
endToken
,
currentDiagnosticSpan
,
_diagnostic
,
Fixer
,
FormatNodeAsync
).
ConfigureAwait
(
false
)
:
endToken
;
},
cancellationToken
).
ConfigureAwait
(
false
);
}
public
SyntaxToken
StartToken_TestOnly
=>
_suppressionTargetInfo
.
StartToken
;
public
SyntaxToken
EndToken_TestOnly
=>
_suppressionTargetInfo
.
EndToken
;
private
SyntaxNode
FormatNode
(
SyntaxNode
node
)
private
Task
<
SyntaxNode
>
FormatNodeAsync
(
SyntaxNode
node
)
{
return
Formatter
.
Format
(
node
,
_document
.
Project
.
Solution
.
Workspace
);
return
Formatter
.
Format
Async
(
node
,
_document
.
Project
.
Solution
.
Workspace
);
}
}
}
...
...
src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction_Pragma.cs
浏览文件 @
994de1cd
...
...
@@ -81,13 +81,13 @@ public async Task<Document> GetChangedDocumentAsync(bool includeStartTokenChange
add
=
true
;
}
Func
<
SyntaxToken
,
TextSpan
,
SyntaxToken
>
getNewStartToken
=
(
startToken
,
currentDiagnosticSpan
)
=>
includeStartTokenChange
?
GetNewTokenWithModifiedPragma
(
startToken
,
currentDiagnosticSpan
,
add
,
toggle
,
indexOfLeadingPragmaDisableToRemove
,
isStartToken
:
true
)
:
startToken
;
Func
<
SyntaxToken
,
TextSpan
,
Task
<
SyntaxToken
>>
getNewStartToken
=
(
startToken
,
currentDiagnosticSpan
)
=>
includeStartTokenChange
?
GetNewTokenWithModifiedPragmaAsync
(
startToken
,
currentDiagnosticSpan
,
add
,
toggle
,
indexOfLeadingPragmaDisableToRemove
,
isStartToken
:
true
)
:
Task
.
FromResult
(
startToken
)
;
Func
<
SyntaxToken
,
TextSpan
,
SyntaxToken
>
getNewEndToken
=
(
endToken
,
currentDiagnosticSpan
)
=>
includeEndTokenChange
?
GetNewTokenWithModifiedPragma
(
endToken
,
currentDiagnosticSpan
,
add
,
toggle
,
indexOfTrailingPragmaEnableToRemove
,
isStartToken
:
false
)
:
endToken
;
Func
<
SyntaxToken
,
TextSpan
,
Task
<
SyntaxToken
>>
getNewEndToken
=
(
endToken
,
currentDiagnosticSpan
)
=>
includeEndTokenChange
?
GetNewTokenWithModifiedPragmaAsync
(
endToken
,
currentDiagnosticSpan
,
add
,
toggle
,
indexOfTrailingPragmaEnableToRemove
,
isStartToken
:
false
)
:
Task
.
FromResult
(
endToken
)
;
return
await
PragmaHelpers
.
GetChangeDocumentWithPragmaAdjustedAsync
(
_document
,
...
...
@@ -107,9 +107,9 @@ private static SyntaxTriviaList GetTriviaListForSuppression(SyntaxToken token, b
private
static
SyntaxToken
UpdateTriviaList
(
SyntaxToken
token
,
bool
isStartToken
,
SyntaxTriviaList
triviaList
,
AbstractSuppressionCodeFixProvider
fixer
)
{
return
isStartToken
||
fixer
.
IsEndOfFileToken
(
token
)
?
token
.
WithLeadingTrivia
(
triviaList
)
:
token
.
WithTrailingTrivia
(
triviaList
);
return
isStartToken
||
fixer
.
IsEndOfFileToken
(
token
)
?
token
.
WithLeadingTrivia
(
triviaList
)
:
token
.
WithTrailingTrivia
(
triviaList
);
}
private
static
bool
CanRemovePragmaTrivia
(
SyntaxToken
token
,
Diagnostic
diagnostic
,
AbstractSuppressionCodeFixProvider
fixer
,
bool
isStartToken
,
out
int
indexOfTriviaToRemove
)
...
...
@@ -153,35 +153,32 @@ private static bool CanRemovePragmaTrivia(SyntaxToken token, Diagnostic diagnost
return
false
;
}
private
SyntaxToken
GetNewTokenWithModifiedPragma
(
SyntaxToken
token
,
TextSpan
currentDiagnosticSpan
,
bool
add
,
bool
toggle
,
int
indexOfTriviaToRemoveOrToggle
,
bool
isStartToken
)
private
Task
<
SyntaxToken
>
GetNewTokenWithModifiedPragmaAsync
(
SyntaxToken
token
,
TextSpan
currentDiagnosticSpan
,
bool
add
,
bool
toggle
,
int
indexOfTriviaToRemoveOrToggle
,
bool
isStartToken
)
{
return
add
?
GetNewTokenWithAddedPragma
(
token
,
currentDiagnosticSpan
,
isStartToken
)
:
GetNewTokenWithRemovedOrToggledPragma
(
token
,
indexOfTriviaToRemoveOrToggle
,
isStartToken
,
toggle
);
return
add
?
GetNewTokenWithAddedPragmaAsync
(
token
,
currentDiagnosticSpan
,
isStartToken
)
:
GetNewTokenWithRemovedOrToggledPragmaAsync
(
token
,
indexOfTriviaToRemoveOrToggle
,
isStartToken
,
toggle
);
}
private
SyntaxToken
GetNewTokenWithAddedPragma
(
SyntaxToken
token
,
TextSpan
currentDiagnosticSpan
,
bool
isStartToken
)
private
Task
<
SyntaxToken
>
GetNewTokenWithAddedPragmaAsync
(
SyntaxToken
token
,
TextSpan
currentDiagnosticSpan
,
bool
isStartToken
)
{
if
(
isStartToken
)
{
return
PragmaHelpers
.
GetNewStartTokenWithAddedPragma
(
token
,
currentDiagnosticSpan
,
_diagnostic
,
Fixer
,
FormatNode
,
isRemoveSuppression
:
true
);
return
PragmaHelpers
.
GetNewStartTokenWithAddedPragma
Async
(
token
,
currentDiagnosticSpan
,
_diagnostic
,
Fixer
,
FormatNode
,
isRemoveSuppression
:
true
);
}
else
{
return
PragmaHelpers
.
GetNewEndTokenWithAddedPragma
(
token
,
currentDiagnosticSpan
,
_diagnostic
,
Fixer
,
FormatNode
,
isRemoveSuppression
:
true
);
return
PragmaHelpers
.
GetNewEndTokenWithAddedPragma
Async
(
token
,
currentDiagnosticSpan
,
_diagnostic
,
Fixer
,
FormatNode
,
isRemoveSuppression
:
true
);
}
}
private
SyntaxToken
GetNewTokenWithRemovedOrToggledPragma
(
SyntaxToken
token
,
int
indexOfTriviaToRemoveOrToggle
,
bool
isStartToken
,
bool
toggle
)
private
Task
<
SyntaxToken
>
GetNewTokenWithRemovedOrToggledPragmaAsync
(
SyntaxToken
token
,
int
indexOfTriviaToRemoveOrToggle
,
bool
isStartToken
,
bool
toggle
)
{
if
(
isStartToken
)
{
return
GetNewTokenWithPragmaUnsuppress
(
token
,
indexOfTriviaToRemoveOrToggle
,
_diagnostic
,
Fixer
,
isStartToken
,
toggle
);
}
else
{
return
GetNewTokenWithPragmaUnsuppress
(
token
,
indexOfTriviaToRemoveOrToggle
,
_diagnostic
,
Fixer
,
isStartToken
,
toggle
);
}
var
result
=
isStartToken
?
GetNewTokenWithPragmaUnsuppress
(
token
,
indexOfTriviaToRemoveOrToggle
,
_diagnostic
,
Fixer
,
isStartToken
,
toggle
)
:
GetNewTokenWithPragmaUnsuppress
(
token
,
indexOfTriviaToRemoveOrToggle
,
_diagnostic
,
Fixer
,
isStartToken
,
toggle
);
return
Task
.
FromResult
(
result
);
}
private
static
SyntaxToken
GetNewTokenWithPragmaUnsuppress
(
SyntaxToken
token
,
int
indexOfTriviaToRemoveOrToggle
,
Diagnostic
diagnostic
,
AbstractSuppressionCodeFixProvider
fixer
,
bool
isStartToken
,
bool
toggle
)
...
...
@@ -224,9 +221,9 @@ private async Task<bool> IsDiagnosticSuppressedBeforeLeadingPragmaAsync(int inde
public
SyntaxToken
StartToken_TestOnly
=>
_suppressionTargetInfo
.
StartToken
;
public
SyntaxToken
EndToken_TestOnly
=>
_suppressionTargetInfo
.
EndToken
;
private
SyntaxNode
FormatNode
(
SyntaxNode
node
)
private
Task
<
SyntaxNode
>
FormatNode
(
SyntaxNode
node
)
{
return
Formatter
.
Format
(
node
,
_document
.
Project
.
Solution
.
Workspace
);
return
Formatter
.
Format
Async
(
node
,
_document
.
Project
.
Solution
.
Workspace
);
}
}
}
...
...
src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.cs
浏览文件 @
994de1cd
...
...
@@ -39,8 +39,8 @@ public bool CanBeSuppressedOrUnsuppressed(Diagnostic diagnostic)
return
SuppressionHelpers
.
CanBeSuppressed
(
diagnostic
)
||
SuppressionHelpers
.
CanBeUnsuppressed
(
diagnostic
);
}
protected
abstract
SyntaxTriviaList
CreatePragmaDisableDirectiveTrivia
(
Diagnostic
diagnostic
,
Func
<
SyntaxNode
,
SyntaxNode
>
formatNode
,
bool
needsLeadingEndOfLine
,
bool
needsTrailingEndOfLine
);
protected
abstract
SyntaxTriviaList
CreatePragmaRestoreDirectiveTrivia
(
Diagnostic
diagnostic
,
Func
<
SyntaxNode
,
SyntaxNode
>
formatNode
,
bool
needsLeadingEndOfLine
,
bool
needsTrailingEndOfLine
);
protected
abstract
Task
<
SyntaxTriviaList
>
CreatePragmaDisableDirectiveTriviaAsync
(
Diagnostic
diagnostic
,
Func
<
SyntaxNode
,
Task
<
SyntaxNode
>
>
formatNode
,
bool
needsLeadingEndOfLine
,
bool
needsTrailingEndOfLine
);
protected
abstract
Task
<
SyntaxTriviaList
>
CreatePragmaRestoreDirectiveTriviaAsync
(
Diagnostic
diagnostic
,
Func
<
SyntaxNode
,
Task
<
SyntaxNode
>
>
formatNode
,
bool
needsLeadingEndOfLine
,
bool
needsTrailingEndOfLine
);
protected
abstract
SyntaxNode
AddGlobalSuppressMessageAttribute
(
SyntaxNode
newRoot
,
ISymbol
targetSymbol
,
Diagnostic
diagnostic
,
Workspace
workspace
,
CancellationToken
cancellationToken
);
...
...
src/Features/VisualBasic/Portable/CodeFixes/Suppression/VisualBasicSuppressionCodeFixProvider.vb
浏览文件 @
994de1cd
...
...
@@ -14,16 +14,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.Suppression
Friend
Class
VisualBasicSuppressionCodeFixProvider
Inherits
AbstractSuppressionCodeFixProvider
Protected
Overrides
Function
CreatePragmaRestoreDirectiveTrivia
(
diagnostic
As
Diagnostic
,
formatNode
As
Func
(
Of
SyntaxNode
,
SyntaxNode
),
needsLeadingEndOfLine
As
Boolean
,
needsTrailingEndOfLine
As
Boolean
)
As
SyntaxTriviaList
Protected
Overrides
Function
CreatePragmaRestoreDirectiveTrivia
Async
(
diagnostic
As
Diagnostic
,
formatNode
As
Func
(
Of
SyntaxNode
,
Task
(
Of
SyntaxNode
)),
needsLeadingEndOfLine
As
Boolean
,
needsTrailingEndOfLine
As
Boolean
)
As
Task
(
Of
SyntaxTriviaList
)
Dim
errorCodes
=
GetErrorCodes
(
diagnostic
)
Dim
pragmaDirective
=
SyntaxFactory
.
EnableWarningDirectiveTrivia
(
errorCodes
)
Return
CreatePragmaDirectiveTrivia
(
pragmaDirective
,
diagnostic
,
formatNode
,
needsLeadingEndOfLine
,
needsTrailingEndOfLine
)
Return
CreatePragmaDirectiveTrivia
Async
(
pragmaDirective
,
diagnostic
,
formatNode
,
needsLeadingEndOfLine
,
needsTrailingEndOfLine
)
End
Function
Protected
Overrides
Function
CreatePragmaDisableDirectiveTrivia
(
diagnostic
As
Diagnostic
,
formatNode
As
Func
(
Of
SyntaxNode
,
SyntaxNode
),
needsLeadingEndOfLine
As
Boolean
,
needsTrailingEndOfLine
As
Boolean
)
As
SyntaxTriviaList
Protected
Overrides
Function
CreatePragmaDisableDirectiveTrivia
Async
(
diagnostic
As
Diagnostic
,
formatNode
As
Func
(
Of
SyntaxNode
,
Task
(
Of
SyntaxNode
)),
needsLeadingEndOfLine
As
Boolean
,
needsTrailingEndOfLine
As
Boolean
)
As
Task
(
Of
SyntaxTriviaList
)
Dim
errorCodes
=
GetErrorCodes
(
diagnostic
)
Dim
pragmaDirective
=
SyntaxFactory
.
DisableWarningDirectiveTrivia
(
errorCodes
)
Return
CreatePragmaDirectiveTrivia
(
pragmaDirective
,
diagnostic
,
formatNode
,
needsLeadingEndOfLine
,
needsTrailingEndOfLine
)
Return
CreatePragmaDirectiveTrivia
Async
(
pragmaDirective
,
diagnostic
,
formatNode
,
needsLeadingEndOfLine
,
needsTrailingEndOfLine
)
End
Function
Private
Shared
Function
GetErrorCodes
(
diagnostic
As
Diagnostic
)
As
SeparatedSyntaxList
(
Of
IdentifierNameSyntax
)
...
...
@@ -34,8 +34,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.Suppression
Return
New
SeparatedSyntaxList
(
Of
IdentifierNameSyntax
)().
Add
(
SyntaxFactory
.
IdentifierName
(
text
))
End
Function
Private
Function
CreatePragmaDirectiveTrivia
(
enableOrDisablePragmaDirective
As
StructuredTriviaSyntax
,
diagnostic
As
Diagnostic
,
formatNode
As
Func
(
Of
SyntaxNode
,
SyntaxNode
),
needsLeadingEndOfLine
As
Boolean
,
needsTrailingEndOfLine
As
Boolean
)
As
SyntaxTriviaList
enableOrDisablePragmaDirective
=
CType
(
formatNode
(
enableOrDisablePragmaDirectiv
e
),
StructuredTriviaSyntax
)
Private
Async
Function
CreatePragmaDirectiveTriviaAsync
(
enableOrDisablePragmaDirective
As
StructuredTriviaSyntax
,
diagnostic
As
Diagnostic
,
formatNode
As
Func
(
Of
SyntaxNode
,
Task
(
Of
SyntaxNode
)),
needsLeadingEndOfLine
As
Boolean
,
needsTrailingEndOfLine
As
Boolean
)
As
Task
(
Of
SyntaxTriviaList
)
enableOrDisablePragmaDirective
=
CType
(
Await
formatNode
(
enableOrDisablePragmaDirective
).
ConfigureAwait
(
Fals
e
),
StructuredTriviaSyntax
)
Dim
pragmaDirectiveTrivia
=
SyntaxFactory
.
Trivia
(
enableOrDisablePragmaDirective
)
Dim
endOfLineTrivia
=
SyntaxFactory
.
ElasticCarriageReturnLineFeed
Dim
triviaList
=
SyntaxFactory
.
TriviaList
(
pragmaDirectiveTrivia
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录