Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
754f3b74
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,发现更多精彩内容 >>
提交
754f3b74
编写于
10月 13, 2016
作者:
H
Heejae Chang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adding more cancellation
上级
f701e036
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
15 addition
and
27 deletion
+15
-27
src/Features/Core/Portable/CodeLens/CodeLensReferencesService.cs
...tures/Core/Portable/CodeLens/CodeLensReferencesService.cs
+15
-27
未找到文件。
src/Features/Core/Portable/CodeLens/CodeLensReferencesService.cs
浏览文件 @
754f3b74
...
...
@@ -21,7 +21,7 @@ internal sealed class CodeLensReferencesService : ICodeLensReferencesService
private
static
async
Task
<
T
>
FindAsync
<
T
>(
Solution
solution
,
DocumentId
documentId
,
SyntaxNode
syntaxNode
,
Func
<
CodeLensFindReferencesProgress
,
Task
<
T
>>
onResults
,
Func
<
CodeLensFindReferencesProgress
,
Task
<
T
>>
onCapped
,
int
searchCap
,
CancellationToken
cancellationToken
)
where
T
:
class
int
searchCap
,
CancellationToken
cancellationToken
)
where
T
:
class
{
var
document
=
solution
.
GetDocument
(
documentId
);
if
(
document
==
null
)
...
...
@@ -93,7 +93,7 @@ private static async Task<ReferenceLocationDescriptor> GetDescriptorOfEnclosingS
var
position
=
location
.
SourceSpan
.
Start
;
var
token
=
(
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
)).
FindToken
(
position
,
true
);
var
node
=
GetEnclosingCodeElementNode
(
document
,
token
,
langServices
);
var
node
=
GetEnclosingCodeElementNode
(
document
,
token
,
langServices
,
cancellationToken
);
var
longName
=
langServices
.
GetDisplayName
(
semanticModel
,
node
);
// get the full line of source text on the line that contains this position
...
...
@@ -101,7 +101,7 @@ private static async Task<ReferenceLocationDescriptor> GetDescriptorOfEnclosingS
// get the actual span of text for the line containing reference
var
textLine
=
text
.
Lines
.
GetLineFromPosition
(
position
);
// turn the span from document relative to line relative
var
spanStart
=
token
.
Span
.
Start
-
textLine
.
Span
.
Start
;
var
line
=
textLine
.
ToString
();
...
...
@@ -135,13 +135,15 @@ private static async Task<ReferenceLocationDescriptor> GetDescriptorOfEnclosingS
afterLine2
.
TrimEnd
());
}
private
static
SyntaxNode
GetEnclosingCodeElementNode
(
Document
document
,
SyntaxToken
token
,
ICodeLensDisplayInfoService
langServices
)
private
static
SyntaxNode
GetEnclosingCodeElementNode
(
Document
document
,
SyntaxToken
token
,
ICodeLensDisplayInfoService
langServices
,
CancellationToken
cancellationToken
)
{
var
syntaxFactsService
=
document
.
GetLanguageService
<
ISyntaxFactsService
>();
var
node
=
token
.
Parent
;
while
(
node
!=
null
)
{
cancellationToken
.
ThrowIfCancellationRequested
();
if
(
syntaxFactsService
.
IsDocumentationComment
(
node
))
{
var
structuredTriviaSyntax
=
(
IStructuredTriviaSyntax
)
node
;
...
...
@@ -177,24 +179,20 @@ public async Task<IEnumerable<ReferenceLocationDescriptor>> FindReferenceLocatio
.
Select
(
location
=>
GetDescriptorOfEnclosingSymbolAsync
(
solution
,
location
,
cancellationToken
))
.
ToArray
();
await
Task
.
WhenAll
(
referenceTasks
).
ConfigureAwait
(
false
);
var
result
=
ArrayBuilder
<
ReferenceLocationDescriptor
>.
GetInstance
();
foreach
(
var
task
in
referenceTasks
)
{
result
.
Add
(
await
task
.
ConfigureAwait
(
false
));
}
var
result
=
await
Task
.
WhenAll
(
referenceTasks
).
ConfigureAwait
(
false
);
return
(
IEnumerable
<
ReferenceLocationDescriptor
>)
result
.
ToImmutableAndFree
()
;
return
(
IEnumerable
<
ReferenceLocationDescriptor
>)
result
;
},
onCapped
:
null
,
searchCap
:
0
,
cancellationToken
:
cancellationToken
).
ConfigureAwait
(
false
);
}
private
static
ISymbol
GetEnclosingMethod
(
SemanticModel
semanticModel
,
Location
location
)
private
static
ISymbol
GetEnclosingMethod
(
SemanticModel
semanticModel
,
Location
location
,
CancellationToken
cancellationToken
)
{
var
enclosingSymbol
=
semanticModel
.
GetEnclosingSymbol
(
location
.
SourceSpan
.
Start
);
for
(
var
current
=
enclosingSymbol
;
current
!=
null
;
current
=
current
.
ContainingSymbol
)
{
cancellationToken
.
ThrowIfCancellationRequested
();
if
(
current
.
Kind
!=
SymbolKind
.
Method
)
{
continue
;
...
...
@@ -225,7 +223,7 @@ private static async Task<ReferenceMethodDescriptor> GetMethodDescriptorAsync(Lo
var
document
=
solution
.
GetDocument
(
doc
.
Id
);
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
fullName
=
GetEnclosingMethod
(
semanticModel
,
commonLocation
)?.
ToDisplayString
(
MethodDisplayFormat
);
var
fullName
=
GetEnclosingMethod
(
semanticModel
,
commonLocation
,
cancellationToken
)?.
ToDisplayString
(
MethodDisplayFormat
);
return
!
string
.
IsNullOrEmpty
(
fullName
)
?
new
ReferenceMethodDescriptor
(
fullName
,
document
.
FilePath
)
:
null
;
}
...
...
@@ -240,19 +238,9 @@ public Task<IEnumerable<ReferenceMethodDescriptor>> FindReferenceMethodsAsync(So
.
Select
(
location
=>
GetMethodDescriptorAsync
(
location
,
solution
,
cancellationToken
))
.
ToArray
();
await
Task
.
WhenAll
(
descriptorTasks
).
ConfigureAwait
(
false
);
var
result
=
ArrayBuilder
<
ReferenceMethodDescriptor
>.
GetInstance
();
foreach
(
var
task
in
descriptorTasks
)
{
var
descriptor
=
await
task
.
ConfigureAwait
(
false
);
if
(
result
!=
null
)
{
result
.
Add
(
descriptor
);
}
}
var
result
=
await
Task
.
WhenAll
(
descriptorTasks
).
ConfigureAwait
(
false
);
return
(
IEnumerable
<
ReferenceMethodDescriptor
>)
result
.
ToImmutableAndFree
()
;
return
(
IEnumerable
<
ReferenceMethodDescriptor
>)
result
;
},
onCapped
:
null
,
searchCap
:
0
,
cancellationToken
:
cancellationToken
);
}
...
...
@@ -269,7 +257,7 @@ public Task<IEnumerable<ReferenceMethodDescriptor>> FindReferenceMethodsAsync(So
var
document
=
solution
.
GetDocument
(
doc
.
Id
);
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
return
GetEnclosingMethod
(
semanticModel
,
commonLocation
)?.
ToDisplayString
(
MethodDisplayFormat
);
return
GetEnclosingMethod
(
semanticModel
,
commonLocation
,
cancellationToken
)?.
ToDisplayString
(
MethodDisplayFormat
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录