Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
57719e28
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,发现更多精彩内容 >>
提交
57719e28
编写于
4月 20, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean up more code.
上级
6752867c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
59 addition
and
50 deletion
+59
-50
src/EditorFeatures/Core/Implementation/Suggestions/SuggestedActionsSource.cs
...Core/Implementation/Suggestions/SuggestedActionsSource.cs
+59
-50
未找到文件。
src/EditorFeatures/Core/Implementation/Suggestions/SuggestedActionsSource.cs
浏览文件 @
57719e28
...
...
@@ -42,6 +42,8 @@ private class SuggestedActionsSource : ForegroundThreadAffinitizedObject, ISugge
private
Workspace
_workspace
;
private
int
_lastSolutionVersionReported
;
public
event
EventHandler
<
EventArgs
>
SuggestedActionsChanged
;
public
SuggestedActionsSource
(
SuggestedActionsSourceProvider
owner
,
ITextView
textView
,
ITextBuffer
textBuffer
)
{
_owner
=
owner
;
...
...
@@ -64,7 +66,37 @@ public SuggestedActionsSource(SuggestedActionsSourceProvider owner, ITextView te
_registration
.
WorkspaceChanged
+=
OnWorkspaceChanged
;
}
public
event
EventHandler
<
EventArgs
>
SuggestedActionsChanged
;
public
void
Dispose
()
{
if
(
_owner
!=
null
)
{
var
updateSource
=
(
IDiagnosticUpdateSource
)
_owner
.
_diagnosticService
;
updateSource
.
DiagnosticsUpdated
-=
OnDiagnosticsUpdated
;
}
if
(
_workspace
!=
null
)
{
_workspace
.
DocumentActiveContextChanged
-=
OnActiveContextChanged
;
}
if
(
_registration
!=
null
)
{
_registration
.
WorkspaceChanged
-=
OnWorkspaceChanged
;
}
if
(
_textView
!=
null
)
{
_textView
.
Closed
-=
OnTextViewClosed
;
}
_owner
=
null
;
_workspace
=
null
;
_registration
=
null
;
_textView
=
null
;
_subjectBuffer
=
null
;
}
private
bool
IsDisposed
=>
_subjectBuffer
==
null
;
public
bool
TryGetTelemetryId
(
out
Guid
telemetryId
)
{
...
...
@@ -111,6 +143,11 @@ public bool TryGetTelemetryId(out Guid telemetryId)
{
AssertIsForeground
();
if
(
IsDisposed
)
{
return
null
;
}
using
(
Logger
.
LogBlock
(
FunctionId
.
SuggestedActions_GetSuggestedActions
,
cancellationToken
))
{
var
document
=
GetMatchingDocumentAsync
(
range
.
Snapshot
,
cancellationToken
).
WaitAndGetResult
(
cancellationToken
);
...
...
@@ -529,7 +566,7 @@ private static SuggestedActionSetPriority GetSuggestedActionSetPriority(CodeActi
requestedActionCategories
.
Contains
(
PredefinedSuggestedActionCategoryNames
.
Refactoring
))
{
// Get the selection while on the UI thread.
var
selection
=
TryGetCodeRefactoringSelection
(
_subjectBuffer
,
_textView
,
range
);
var
selection
=
TryGetCodeRefactoringSelection
(
range
);
if
(!
selection
.
HasValue
)
{
// this is here to fail test and see why it is failed.
...
...
@@ -590,36 +627,38 @@ private static SuggestedActionSetPriority GetSuggestedActionSetPriority(CodeActi
public
async
Task
<
bool
>
HasSuggestedActionsAsync
(
ISuggestedActionCategorySet
requestedActionCategories
,
SnapshotSpan
range
,
CancellationToken
cancellationToken
)
{
// Explicitly hold onto below fields in locals and use these locals throughout this code path to avoid crashes
// if these fields happen to be cleared by Dispose() below. This is required since this code path involves
// code that can run asynchronously from background thread.
var
view
=
_textView
;
var
buffer
=
_subjectBuffer
;
var
provider
=
_owner
;
if
(
view
==
null
||
buffer
==
null
||
provider
==
null
)
if
(
IsDisposed
)
{
// We've already been disposed. No point in continuing.
return
false
;
}
using
(
var
asyncToken
=
provid
er
.
OperationListener
.
BeginAsyncOperation
(
"HasSuggestedActionsAsync"
))
using
(
var
asyncToken
=
_own
er
.
OperationListener
.
BeginAsyncOperation
(
"HasSuggestedActionsAsync"
))
{
// Acquire the user's selection up front, before we do any async work, so that we can
// directly grab it when we're on the UI thread. That way we don't have any reentrancy
// blocking concerns if VS wants to block on this call (for example, if the user
// explicitly invokes the 'show smart tag' command).
//
// This work must happen on the UI thread as it needs to access the _textView's mutable
// state.
TextSpan
?
selection
=
null
;
if
(
IsForeground
())
{
// This operation needs to happen on UI thread because it needs to access textView.Selection.
selection
=
TryGetCodeRefactoringSelection
(
buffer
,
view
,
range
);
selection
=
TryGetCodeRefactoringSelection
(
range
);
}
else
{
await
InvokeBelowInputPriority
(()
=>
{
// This operation needs to happen on UI thread because it needs to access textView.Selection.
selection
=
TryGetCodeRefactoringSelection
(
buffer
,
view
,
range
);
if
(
IsDisposed
)
{
return
;
}
selection
=
TryGetCodeRefactoringSelection
(
range
);
}).
ConfigureAwait
(
false
);
}
...
...
@@ -700,11 +739,14 @@ public async Task<bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet req
return
false
;
}
private
static
TextSpan
?
TryGetCodeRefactoringSelection
(
ITextBuffer
buffer
,
ITextView
view
,
SnapshotSpan
range
)
private
TextSpan
?
TryGetCodeRefactoringSelection
(
SnapshotSpan
range
)
{
var
selectedSpans
=
view
.
Selection
.
SelectedSpans
.
SelectMany
(
ss
=>
view
.
BufferGraph
.
MapDownToBuffer
(
ss
,
SpanTrackingMode
.
EdgeExclusive
,
buffer
))
.
Where
(
ss
=>
!
view
.
IsReadOnlyOnSurfaceBuffer
(
ss
))
this
.
AssertIsForeground
();
Debug
.
Assert
(!
this
.
IsDisposed
);
var
selectedSpans
=
_textView
.
Selection
.
SelectedSpans
.
SelectMany
(
ss
=>
_textView
.
BufferGraph
.
MapDownToBuffer
(
ss
,
SpanTrackingMode
.
EdgeExclusive
,
_subjectBuffer
))
.
Where
(
ss
=>
!
_textView
.
IsReadOnlyOnSurfaceBuffer
(
ss
))
.
ToList
();
// We only support refactorings when there is a single selection in the document.
...
...
@@ -833,39 +875,6 @@ private void OnSuggestedActionsChanged(Workspace currentWorkspace, DocumentId cu
Volatile
.
Write
(
ref
_lastSolutionVersionReported
,
solutionVersion
);
}
public
void
Dispose
()
{
if
(
_owner
!=
null
)
{
var
updateSource
=
(
IDiagnosticUpdateSource
)
_owner
.
_diagnosticService
;
updateSource
.
DiagnosticsUpdated
-=
OnDiagnosticsUpdated
;
_owner
=
null
;
}
if
(
_workspace
!=
null
)
{
_workspace
.
DocumentActiveContextChanged
-=
OnActiveContextChanged
;
_workspace
=
null
;
}
if
(
_registration
!=
null
)
{
_registration
.
WorkspaceChanged
-=
OnWorkspaceChanged
;
_registration
=
null
;
}
if
(
_textView
!=
null
)
{
_textView
.
Closed
-=
OnTextViewClosed
;
_textView
=
null
;
}
if
(
_subjectBuffer
!=
null
)
{
_subjectBuffer
=
null
;
}
}
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录