Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
f51b5490
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,发现更多精彩内容 >>
未验证
提交
f51b5490
编写于
3月 01, 2019
作者:
D
dotnet-automerge-bot
提交者:
GitHub
3月 01, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #33814 from dotnet/merges/dev16.0-to-dev16.0-vs-deps
Merge dev16.0 to dev16.0-vs-deps
上级
2773f5e8
4de954e2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
65 addition
and
29 deletion
+65
-29
src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs
...orFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs
+46
-27
src/EditorFeatures/Core/Wrapping/AbstractCodeActionComputer.cs
...ditorFeatures/Core/Wrapping/AbstractCodeActionComputer.cs
+6
-1
src/EditorFeatures/Core/Wrapping/WrapItemsAction.cs
src/EditorFeatures/Core/Wrapping/WrapItemsAction.cs
+8
-0
src/Workspaces/Core/Portable/CodeActions/CodeAction.cs
src/Workspaces/Core/Portable/CodeActions/CodeAction.cs
+5
-1
未找到文件。
src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs
浏览文件 @
f51b5490
...
...
@@ -176,18 +176,16 @@ public bool TryGetTelemetryId(out Guid telemetryId)
var
fixes
=
GetCodeFixes
(
supportsFeatureService
,
requestedActionCategories
,
workspace
,
document
,
range
,
cancellationToken
);
var
refactorings
=
GetRefactorings
(
supportsFeatureService
,
requestedActionCategories
,
workspace
,
document
,
selectionOpt
,
cancellationToken
);
// If there's a selection, it's likely the user is trying to perform some operation
// directly on that operation (like 'extract method'). Prioritize refactorings over
// fixes in that case. Otherwise, it's likely that the user is just on some error
// and wants to fix it (in which case, prioritize fixes).
var
result
=
selectionOpt
?.
Length
>
0
?
refactorings
.
Concat
(
fixes
)
:
fixes
.
Concat
(
refactorings
);
// Get the initial set of action sets, with refactorings and fixes appropriately
// ordered against each other.
var
result
=
GetInitiallyOrderedActionSets
(
selectionOpt
,
fixes
,
refactorings
);
if
(
result
.
IsEmpty
)
{
return
null
;
}
// Now that we have the entire set of action sets, inline, sort and filter
// them appropriately against each other.
var
allActionSets
=
InlineActionSetsIfDesirable
(
result
);
var
orderedActionSets
=
OrderActionSets
(
allActionSets
);
var
filteredSets
=
FilterActionSetsByTitle
(
orderedActionSets
);
...
...
@@ -196,6 +194,37 @@ public bool TryGetTelemetryId(out Guid telemetryId)
}
}
private
ImmutableArray
<
SuggestedActionSet
>
GetInitiallyOrderedActionSets
(
TextSpan
?
selectionOpt
,
ImmutableArray
<
SuggestedActionSet
>
fixes
,
ImmutableArray
<
SuggestedActionSet
>
refactorings
)
{
// First, order refactorings based on the order the providers actually gave for their actions.
// This way, a low pri refactoring always shows after a medium pri refactoring, no matter what
// we do below.
refactorings
=
OrderActionSets
(
refactorings
);
// If there's a selection, it's likely the user is trying to perform some operation
// directly on that operation (like 'extract method'). Prioritize refactorings over
// fixes in that case. Otherwise, it's likely that the user is just on some error
// and wants to fix it (in which case, prioritize fixes).
if
(
selectionOpt
?.
Length
>
0
)
{
// There was a selection. Treat refactorings as more important than
// fixes. Note: we still will sort after this. So any high pri fixes
// will come to the front. Any low-pri refactorings will go to the end.
return
refactorings
.
Concat
(
fixes
);
}
else
{
// No selection. Treat all refactorings as low priority, and place
// after fixes. Even a low pri fixes will be above what was *originally*
// a medium pri refactoring.
refactorings
=
refactorings
.
SelectAsArray
(
r
=>
new
SuggestedActionSet
(
r
.
CategoryName
,
r
.
Actions
,
r
.
Title
,
SuggestedActionSetPriority
.
Low
,
r
.
ApplicableToSpan
));
return
fixes
.
Concat
(
refactorings
);
}
}
private
ImmutableArray
<
SuggestedActionSet
>
OrderActionSets
(
ImmutableArray
<
SuggestedActionSet
>
actionSets
)
{
...
...
@@ -452,7 +481,7 @@ private CodeRefactoring FilterOnUIThread(CodeRefactoring refactoring, Workspace
nestedAction
,
getFixAllSuggestedActionSet
(
nestedAction
)));
var
set
=
new
SuggestedActionSet
(
categoryName
:
null
,
actions
:
nestedActions
,
priority
:
SuggestedActionSetPriority
.
Medium
,
actions
:
nestedActions
,
priority
:
GetSuggestedActionSetPriority
(
fix
.
Action
.
Priority
)
,
applicableToSpan
:
fix
.
PrimaryDiagnostic
.
Location
.
SourceSpan
.
ToSpan
());
suggestedAction
=
new
SuggestedActionWithNestedActions
(
...
...
@@ -626,21 +655,8 @@ private static SuggestedActionSetPriority GetSuggestedActionSetPriority(CodeActi
var
filteredRefactorings
=
FilterOnUIThread
(
refactorings
,
workspace
);
// Refactorings are given the span the user currently has selected. That
// way they can be accurately sorted against other refactorings/fixes that
// are of the same priority. i.e. refactorings are LowPriority by default.
// But we still want them to come first over a low-pri code fix that is
// further away. A good example of this is "Add null parameter check" which
// should be higher in the list when the caret is on a parameter, vs the
// code-fix for "use expression body" which is given the entire span of a
// method.
var
priority
=
selection
.
Length
>
0
?
SuggestedActionSetPriority
.
Medium
:
SuggestedActionSetPriority
.
Low
;
return
filteredRefactorings
.
SelectAsArray
(
r
=>
OrganizeRefactorings
(
workspace
,
r
,
priority
,
selection
.
ToSpan
()));
r
=>
OrganizeRefactorings
(
workspace
,
r
,
selection
.
ToSpan
()));
}
return
ImmutableArray
<
SuggestedActionSet
>.
Empty
;
...
...
@@ -655,8 +671,7 @@ private static SuggestedActionSetPriority GetSuggestedActionSetPriority(CodeActi
/// and should show up after fixes but before suppression fixes in the light bulb menu.
/// </remarks>
private
SuggestedActionSet
OrganizeRefactorings
(
Workspace
workspace
,
CodeRefactoring
refactoring
,
SuggestedActionSetPriority
priority
,
Span
applicableSpan
)
Workspace
workspace
,
CodeRefactoring
refactoring
,
Span
applicableSpan
)
{
var
refactoringSuggestedActions
=
ArrayBuilder
<
SuggestedAction
>.
GetInstance
();
...
...
@@ -670,7 +685,7 @@ private static SuggestedActionSetPriority GetSuggestedActionSetPriority(CodeActi
_owner
,
workspace
,
_subjectBuffer
,
refactoring
.
Provider
,
na
));
var
set
=
new
SuggestedActionSet
(
categoryName
:
null
,
actions
:
nestedActions
,
priority
:
SuggestedActionSetPriority
.
Medium
,
applicableToSpan
:
applicableSpan
);
actions
:
nestedActions
,
priority
:
GetSuggestedActionSetPriority
(
action
.
Priority
)
,
applicableToSpan
:
applicableSpan
);
refactoringSuggestedActions
.
Add
(
new
SuggestedActionWithNestedActions
(
ThreadingContext
,
...
...
@@ -685,10 +700,14 @@ private static SuggestedActionSetPriority GetSuggestedActionSetPriority(CodeActi
}
}
var
actions
=
refactoringSuggestedActions
.
ToImmutableAndFree
();
// An action set gets the the same priority as the highest priority
// action within in.
return
new
SuggestedActionSet
(
PredefinedSuggestedActionCategoryNames
.
Refactoring
,
refactoringSuggestedActions
.
ToImmutableAndFree
()
,
priority
:
priority
,
actions
:
actions
,
priority
:
GetSuggestedActionSetPriority
(
actions
.
Max
(
a
=>
a
.
Priority
))
,
applicableToSpan
:
applicableSpan
);
}
...
...
src/EditorFeatures/Core/Wrapping/AbstractCodeActionComputer.cs
浏览文件 @
f51b5490
...
...
@@ -273,8 +273,13 @@ public async Task<ImmutableArray<CodeAction>> GetTopLevelCodeActionsAsync()
// Otherwise, sort items and add to the resultant list
var
sorted
=
WrapItemsAction
.
SortActionsByMostRecentlyUsed
(
ImmutableArray
<
CodeAction
>.
CastUp
(
wrappingActions
));
// Make our code action low priority. This option will be offered *a lot*, and
// much of the time will not be something the user particularly wants to do.
// It should be offered after all other normal refactorings.
result
.
Add
(
new
CodeActionWithNestedActions
(
wrappingActions
[
0
].
ParentTitle
,
sorted
,
group
.
IsInlinable
));
wrappingActions
[
0
].
ParentTitle
,
sorted
,
group
.
IsInlinable
,
CodeActionPriority
.
Low
));
}
// Finally, sort the topmost list we're building and return that. This ensures that
...
...
src/EditorFeatures/Core/Wrapping/WrapItemsAction.cs
浏览文件 @
f51b5490
...
...
@@ -29,6 +29,14 @@ internal class WrapItemsAction : DocumentChangeAction
public
string
SortTitle
{
get
;
}
// Make our code action low priority. This option will be offered *a lot*, and
// much of the time will not be something the user particularly wants to do.
// It should be offered after all other normal refactorings.
//
// This value is only relevant if this code action is the only one in its group,
// and it ends up getting inlined as a top-level-action that is offered.
internal
override
CodeActionPriority
Priority
=>
CodeActionPriority
.
Low
;
public
WrapItemsAction
(
string
title
,
string
parentTitle
,
Func
<
CancellationToken
,
Task
<
Document
>>
createChangedDocument
)
:
base
(
title
,
createChangedDocument
)
{
...
...
src/Workspaces/Core/Portable/CodeActions/CodeAction.cs
浏览文件 @
f51b5490
...
...
@@ -359,14 +359,18 @@ protected override Task<Document> GetChangedDocumentAsync(CancellationToken canc
internal
class
CodeActionWithNestedActions
:
SimpleCodeAction
{
public
CodeActionWithNestedActions
(
string
title
,
ImmutableArray
<
CodeAction
>
nestedActions
,
bool
isInlinable
)
string
title
,
ImmutableArray
<
CodeAction
>
nestedActions
,
bool
isInlinable
,
CodeActionPriority
priority
=
CodeActionPriority
.
Medium
)
:
base
(
title
,
ComputeEquivalenceKey
(
nestedActions
))
{
Debug
.
Assert
(
nestedActions
.
Length
>
0
);
NestedCodeActions
=
nestedActions
;
IsInlinable
=
isInlinable
;
Priority
=
priority
;
}
internal
override
CodeActionPriority
Priority
{
get
;
}
internal
sealed
override
bool
IsInlinable
{
get
;
}
internal
sealed
override
ImmutableArray
<
CodeAction
>
NestedCodeActions
{
get
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录