Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
a0f4c9a2
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,发现更多精彩内容 >>
提交
a0f4c9a2
编写于
9月 18, 2016
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extract out common FixAll code. It will be used for other diagnostic analyzers we have.
上级
142d9116
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
95 addition
and
58 deletion
+95
-58
src/Features/CSharp/Portable/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.FixAllProvider.cs
...ateWithConditionalAccessCodeFixProvider.FixAllProvider.cs
+5
-28
src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/BatchFixAllProvider.cs
...rtable/CodeFixes/FixAllOccurrences/BatchFixAllProvider.cs
+1
-30
src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/DocumentBasedFixAllProvider.cs
...odeFixes/FixAllOccurrences/DocumentBasedFixAllProvider.cs
+52
-0
src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/FixAllProvider.cs
...re/Portable/CodeFixes/FixAllOccurrences/FixAllProvider.cs
+36
-0
src/Workspaces/Core/Portable/Workspaces.csproj
src/Workspaces/Core/Portable/Workspaces.csproj
+1
-0
未找到文件。
src/Features/CSharp/Portable/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.FixAllProvider.cs
浏览文件 @
a0f4c9a2
...
...
@@ -9,6 +9,7 @@
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CodeActions
;
using
Microsoft.CodeAnalysis.CodeFixes
;
using
Microsoft.CodeAnalysis.CodeFixes.FixAllOccurrences
;
using
Microsoft.CodeAnalysis.CSharp.Extensions
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Diagnostics
;
...
...
@@ -31,7 +32,7 @@ internal partial class InvokeDelegateWithConditionalAccessCodeFixProvider : Code
/// By taking control ourselves, we can simply make all the tree edits and not have to
/// try to back-infer textual changes which then may or may not merge properly.
/// </summary>
private
class
InvokeDelegateWithConditionalAccessFixAllProvider
:
Batch
FixAllProvider
private
class
InvokeDelegateWithConditionalAccessFixAllProvider
:
DocumentBased
FixAllProvider
{
private
readonly
InvokeDelegateWithConditionalAccessCodeFixProvider
_provider
;
...
...
@@ -40,32 +41,8 @@ public InvokeDelegateWithConditionalAccessFixAllProvider(InvokeDelegateWithCondi
_provider
=
provider
;
}
internal
override
async
Task
<
CodeAction
>
GetFixAsync
(
ImmutableDictionary
<
Document
,
ImmutableArray
<
Diagnostic
>>
documentsAndDiagnosticsToFixMap
,
FixAllState
fixAllState
,
CancellationToken
cancellationToken
)
{
// Process all documents in parallel.
var
updatedDocumentTasks
=
documentsAndDiagnosticsToFixMap
.
Select
(
kvp
=>
FixAsync
(
fixAllState
,
kvp
.
Key
,
kvp
.
Value
,
cancellationToken
));
await
Task
.
WhenAll
(
updatedDocumentTasks
).
ConfigureAwait
(
false
);
var
currentSolution
=
fixAllState
.
Solution
;
foreach
(
var
task
in
updatedDocumentTasks
)
{
var
updatedDocument
=
await
task
.
ConfigureAwait
(
false
);
currentSolution
=
currentSolution
.
WithDocumentSyntaxRoot
(
updatedDocument
.
Id
,
await
updatedDocument
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
));
}
var
title
=
GetFixAllTitle
(
fixAllState
);
return
new
CodeAction
.
SolutionChangeAction
(
title
,
_
=>
Task
.
FromResult
(
currentSolution
));
}
private
Task
<
Document
>
FixAsync
(
FixAllState
fixAllState
,
Document
document
,
ImmutableArray
<
Diagnostic
>
diagnostics
,
CancellationToken
cancellationToken
)
protected
override
Task
<
Document
>
FixDocumentAsync
(
Document
document
,
ImmutableArray
<
Diagnostic
>
diagnostics
,
CancellationToken
cancellationToken
)
{
// Filter out the diagnostics we created for the faded out code. We don't want
// to try to fix those as well as the normal diagnostics we created.
...
...
@@ -78,4 +55,4 @@ public InvokeDelegateWithConditionalAccessFixAllProvider(InvokeDelegateWithCondi
}
}
}
}
}
\ No newline at end of file
src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/BatchFixAllProvider.cs
浏览文件 @
a0f4c9a2
...
...
@@ -209,36 +209,7 @@ public override async Task<CodeAction> GetFixAsync(FixAllContext fixAllContext)
public
virtual
string
GetFixAllTitle
(
FixAllState
fixAllState
)
{
var
diagnosticIds
=
fixAllState
.
DiagnosticIds
;
string
diagnosticId
;
if
(
diagnosticIds
.
Count
()
==
1
)
{
diagnosticId
=
diagnosticIds
.
Single
();
}
else
{
diagnosticId
=
string
.
Join
(
","
,
diagnosticIds
.
ToArray
());
}
switch
(
fixAllState
.
Scope
)
{
case
FixAllScope
.
Custom
:
return
string
.
Format
(
WorkspacesResources
.
Fix_all_0
,
diagnosticId
);
case
FixAllScope
.
Document
:
var
document
=
fixAllState
.
Document
;
return
string
.
Format
(
WorkspacesResources
.
Fix_all_0_in_1
,
diagnosticId
,
document
.
Name
);
case
FixAllScope
.
Project
:
var
project
=
fixAllState
.
Project
;
return
string
.
Format
(
WorkspacesResources
.
Fix_all_0_in_1
,
diagnosticId
,
project
.
Name
);
case
FixAllScope
.
Solution
:
return
string
.
Format
(
WorkspacesResources
.
Fix_all_0_in_Solution
,
diagnosticId
);
default
:
throw
ExceptionUtilities
.
Unreachable
;
}
return
FixAllProvider
.
GetFixAllTitle
(
fixAllState
);
}
public
virtual
async
Task
<
Solution
>
TryMergeFixesAsync
(
...
...
src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/DocumentBasedFixAllProvider.cs
0 → 100644
浏览文件 @
a0f4c9a2
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System.Collections.Immutable
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CodeActions
;
namespace
Microsoft.CodeAnalysis.CodeFixes.FixAllOccurrences
{
/// <summary>
/// A simple implementation of <see cref="FixAllProvider"/> that takes care of collecting
/// all the diagnostics and fixes all documents in parallel. The only functionality a
/// subclass needs to provide is how each document will apply all the fixes to all the
/// diagnostics in that document.
/// </summary>
internal
abstract
class
DocumentBasedFixAllProvider
:
FixAllProvider
{
public
sealed
override
async
Task
<
CodeAction
>
GetFixAsync
(
FixAllContext
fixAllContext
)
{
var
documentsAndDiagnosticsToFixMap
=
await
fixAllContext
.
GetDocumentDiagnosticsToFixAsync
().
ConfigureAwait
(
false
);
return
await
GetFixAsync
(
documentsAndDiagnosticsToFixMap
,
fixAllContext
.
State
,
fixAllContext
.
CancellationToken
).
ConfigureAwait
(
false
);
}
internal
sealed
override
async
Task
<
CodeAction
>
GetFixAsync
(
ImmutableDictionary
<
Document
,
ImmutableArray
<
Diagnostic
>>
documentsAndDiagnosticsToFixMap
,
FixAllState
fixAllState
,
CancellationToken
cancellationToken
)
{
// Process all documents in parallel.
var
updatedDocumentTasks
=
documentsAndDiagnosticsToFixMap
.
Select
(
kvp
=>
FixDocumentAsync
(
kvp
.
Key
,
kvp
.
Value
,
cancellationToken
));
await
Task
.
WhenAll
(
updatedDocumentTasks
).
ConfigureAwait
(
false
);
var
currentSolution
=
fixAllState
.
Solution
;
foreach
(
var
task
in
updatedDocumentTasks
)
{
var
updatedDocument
=
await
task
.
ConfigureAwait
(
false
);
currentSolution
=
currentSolution
.
WithDocumentSyntaxRoot
(
updatedDocument
.
Id
,
await
updatedDocument
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
));
}
var
title
=
GetFixAllTitle
(
fixAllState
);
return
new
CodeAction
.
SolutionChangeAction
(
title
,
_
=>
Task
.
FromResult
(
currentSolution
));
}
protected
abstract
Task
<
Document
>
FixDocumentAsync
(
Document
document
,
ImmutableArray
<
Diagnostic
>
diagnostics
,
CancellationToken
cancellationToken
);
}
}
src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/FixAllProvider.cs
浏览文件 @
a0f4c9a2
...
...
@@ -2,9 +2,11 @@
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CodeActions
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.CodeFixes
{
...
...
@@ -54,5 +56,39 @@ public virtual IEnumerable<string> GetSupportedFixAllDiagnosticIds(CodeFixProvid
{
return
Task
.
FromResult
<
CodeAction
>(
null
);
}
internal
static
string
GetFixAllTitle
(
FixAllState
fixAllState
)
{
var
diagnosticIds
=
fixAllState
.
DiagnosticIds
;
string
diagnosticId
;
if
(
diagnosticIds
.
Count
()
==
1
)
{
diagnosticId
=
diagnosticIds
.
Single
();
}
else
{
diagnosticId
=
string
.
Join
(
","
,
diagnosticIds
.
ToArray
());
}
switch
(
fixAllState
.
Scope
)
{
case
FixAllScope
.
Custom
:
return
string
.
Format
(
WorkspacesResources
.
Fix_all_0
,
diagnosticId
);
case
FixAllScope
.
Document
:
var
document
=
fixAllState
.
Document
;
return
string
.
Format
(
WorkspacesResources
.
Fix_all_0_in_1
,
diagnosticId
,
document
.
Name
);
case
FixAllScope
.
Project
:
var
project
=
fixAllState
.
Project
;
return
string
.
Format
(
WorkspacesResources
.
Fix_all_0_in_1
,
diagnosticId
,
project
.
Name
);
case
FixAllScope
.
Solution
:
return
string
.
Format
(
WorkspacesResources
.
Fix_all_0_in_Solution
,
diagnosticId
);
default
:
throw
ExceptionUtilities
.
Unreachable
;
}
}
}
}
\ No newline at end of file
src/Workspaces/Core/Portable/Workspaces.csproj
浏览文件 @
a0f4c9a2
...
...
@@ -329,6 +329,7 @@
<Compile
Include=
"CodeCleanup\Providers\SimplificationCodeCleanupProvider.cs"
/>
<Compile
Include=
"CodeFixes\CodeFixContext.cs"
/>
<Compile
Include=
"CodeFixes\FixAllOccurrences\BatchSimplificationFixAllProvider.cs"
/>
<Compile
Include=
"CodeFixes\FixAllOccurrences\DocumentBasedFixAllProvider.cs"
/>
<Compile
Include=
"CodeFixes\FixAllOccurrences\FixAllState.FixAllDiagnosticProvider.cs"
/>
<Compile
Include=
"CodeFixes\FixAllOccurrences\FixAllProviderInfo.cs"
/>
<Compile
Include=
"CodeFixes\FixAllOccurrences\FixAllState.FixMultipleDiagnosticProvider.cs"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录