Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
2ac8d62a
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,发现更多精彩内容 >>
提交
2ac8d62a
编写于
11月 15, 2016
作者:
C
CyrusNajmabadi
提交者:
GitHub
11月 15, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15276 from CyrusNajmabadi/moreFixAll
Move 'Add Braces' to the new FixAll' system.
上级
684550c4
ed9e4f0d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
83 addition
and
20 deletion
+83
-20
src/EditorFeatures/CSharpTest/AddBraces/AddBracesFixAllTests.cs
...itorFeatures/CSharpTest/AddBraces/AddBracesFixAllTests.cs
+55
-0
src/EditorFeatures/CSharpTest/AddBraces/AddBracesTests.cs
src/EditorFeatures/CSharpTest/AddBraces/AddBracesTests.cs
+2
-1
src/Features/CSharp/Portable/AddBraces/CSharpAddBracesCodeFixProvider.cs
...harp/Portable/AddBraces/CSharpAddBracesCodeFixProvider.cs
+24
-18
src/Features/Core/Portable/PopulateSwitch/PopulateSwitchCodeFixProvider.cs
.../Portable/PopulateSwitch/PopulateSwitchCodeFixProvider.cs
+2
-1
未找到文件。
src/EditorFeatures/CSharpTest/AddBraces/AddBracesFixAllTests.cs
浏览文件 @
2ac8d62a
...
...
@@ -6,6 +6,61 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.AddBraces
{
public
partial
class
AddBracesTests
{
[
Fact
]
[
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsAddBraces
)]
[
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsFixAllOccurrences
)]
public
async
Task
TestFixAllInDocument1
()
{
var
input
=
@"
class Program1
{
static void Main()
{
{|FixAllInDocument:if|} (true) if (true) return;
}
}
"
;
var
expected
=
@"
class Program1
{
static void Main()
{
if (true) { if (true) { return; } }
}
}
"
;
await
TestAsync
(
input
,
expected
);
}
[
Fact
]
[
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsAddBraces
)]
[
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsFixAllOccurrences
)]
public
async
Task
TestFixAllInDocument2
()
{
var
input
=
@"
class Program1
{
static void Main()
{
if (true) {|FixAllInDocument:if|} (true) return;
}
}
"
;
var
expected
=
@"
class Program1
{
static void Main()
{
if (true) { if (true) { return; } }
}
}
"
;
await
TestAsync
(
input
,
expected
);
}
[
Fact
]
[
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsAddBraces
)]
[
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsFixAllOccurrences
)]
...
...
src/EditorFeatures/CSharpTest/AddBraces/AddBracesTests.cs
浏览文件 @
2ac8d62a
...
...
@@ -13,7 +13,8 @@ public partial class AddBracesTests : AbstractCSharpDiagnosticProviderBasedUserD
{
internal
override
Tuple
<
DiagnosticAnalyzer
,
CodeFixProvider
>
CreateDiagnosticProviderAndFixer
(
Workspace
workspace
)
{
return
new
Tuple
<
DiagnosticAnalyzer
,
CodeFixProvider
>(
new
CSharpAddBracesDiagnosticAnalyzer
(),
return
new
Tuple
<
DiagnosticAnalyzer
,
CodeFixProvider
>(
new
CSharpAddBracesDiagnosticAnalyzer
(),
new
CSharpAddBracesCodeFixProvider
());
}
...
...
src/Features/CSharp/Portable/AddBraces/CSharpAddBracesCodeFixProvider.cs
浏览文件 @
2ac8d62a
...
...
@@ -8,38 +8,44 @@
using
Microsoft.CodeAnalysis.CodeFixes
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Editing
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.CSharp.Diagnostics.AddBraces
{
[
ExportCodeFixProvider
(
LanguageNames
.
CSharp
,
Name
=
PredefinedCodeFixProviderNames
.
AddBraces
),
Shared
]
[
ExtensionOrder
(
After
=
PredefinedCodeFixProviderNames
.
AddAwait
)]
internal
class
CSharpAddBracesCodeFixProvider
:
CodeFixProvider
internal
class
CSharpAddBracesCodeFixProvider
:
SyntaxEditorBased
CodeFixProvider
{
public
override
ImmutableArray
<
string
>
FixableDiagnosticIds
=>
ImmutableArray
.
Create
(
IDEDiagnosticIds
.
AddBracesDiagnosticId
);
public
override
FixAllProvider
GetFixAllProvider
()
=>
WellKnownFixAllProviders
.
BatchFixer
;
public
override
ImmutableArray
<
string
>
FixableDiagnosticIds
=>
ImmutableArray
.
Create
(
IDEDiagnosticIds
.
AddBracesDiagnosticId
);
public
sealed
override
Task
RegisterCodeFixesAsync
(
CodeFixContext
context
)
{
context
.
RegisterCodeFix
(
new
MyCodeAction
(
FeaturesResources
.
Add_braces
,
c
=>
AddBracesAsync
(
context
,
c
)),
new
MyCodeAction
(
c
=>
FixAsync
(
context
.
Document
,
context
.
Diagnostics
.
First
(),
c
)),
context
.
Diagnostics
);
return
SpecializedTasks
.
EmptyTask
;
}
protected
async
Task
<
Document
>
AddBracesAsync
(
CodeFixContext
context
,
CancellationToken
cancellationToken
)
protected
override
Task
FixAllAsync
(
Document
document
,
ImmutableArray
<
Diagnostic
>
diagnostics
,
SyntaxEditor
editor
,
CancellationToken
cancellationToken
)
{
var
root
=
await
context
.
Document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
)
;
var
diagnostic
=
context
.
Diagnostics
.
First
();
var
diagnosticSpan
=
diagnostic
.
Location
.
SourceSpan
;
var
statement
=
root
.
FindNode
(
diagnostic
Span
);
var
root
=
editor
.
OriginalRoot
;
foreach
(
var
diagnostic
in
diagnostics
)
{
var
statement
=
root
.
FindNode
(
diagnostic
.
Location
.
Source
Span
);
var
newRoot
=
root
.
ReplaceNode
(
statement
,
GetReplacementNode
(
statement
));
return
context
.
Document
.
WithSyntaxRoot
(
newRoot
);
// Use the callback version of ReplaceNode so that we see the effects
// of other replace calls. i.e. we may have statements nested in statements,
// we need to make sure that any inner edits are seen when we make the outer
// replacement.
editor
.
ReplaceNode
(
statement
,
(
s
,
g
)
=>
GetReplacementNode
(
s
));
}
return
SpecializedTasks
.
EmptyTask
;
}
private
SyntaxNode
GetReplacementNode
(
SyntaxNode
statement
)
...
...
@@ -83,13 +89,13 @@ private SyntaxNode GetReplacementNode(SyntaxNode statement)
return
default
(
SyntaxNode
);
}
private
SyntaxNode
GetNewBlock
(
SyntaxNode
statement
,
StatementSyntax
statementBody
)
=>
statement
.
ReplaceNode
(
statementBody
,
SyntaxFactory
.
Block
(
statementBody
));
private
SyntaxNode
GetNewBlock
(
SyntaxNode
statement
,
StatementSyntax
statementBody
)
=>
statement
.
ReplaceNode
(
statementBody
,
SyntaxFactory
.
Block
(
statementBody
));
private
class
MyCodeAction
:
CodeAction
.
DocumentChangeAction
{
public
MyCodeAction
(
string
title
,
Func
<
CancellationToken
,
Task
<
Document
>>
createChangedDocument
)
:
base
(
title
,
createChangedDocument
)
public
MyCodeAction
(
Func
<
CancellationToken
,
Task
<
Document
>>
createChangedDocument
)
:
base
(
FeaturesResources
.
Add_braces
,
createChangedDocument
,
FeaturesResources
.
Add_braces
)
{
}
}
...
...
src/Features/Core/Portable/PopulateSwitch/PopulateSwitchCodeFixProvider.cs
浏览文件 @
2ac8d62a
...
...
@@ -27,7 +27,8 @@ namespace Microsoft.CodeAnalysis.PopulateSwitch
[
ExtensionOrder
(
After
=
PredefinedCodeFixProviderNames
.
ImplementInterface
)]
internal
class
PopulateSwitchCodeFixProvider
:
CodeFixProvider
{
public
override
ImmutableArray
<
string
>
FixableDiagnosticIds
=>
ImmutableArray
.
Create
(
IDEDiagnosticIds
.
PopulateSwitchDiagnosticId
);
public
override
ImmutableArray
<
string
>
FixableDiagnosticIds
=>
ImmutableArray
.
Create
(
IDEDiagnosticIds
.
PopulateSwitchDiagnosticId
);
public
override
FixAllProvider
GetFixAllProvider
()
=>
WellKnownFixAllProviders
.
BatchFixer
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录