Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
1228c957
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,发现更多精彩内容 >>
未验证
提交
1228c957
编写于
9月 23, 2019
作者:
G
Gen Lu
提交者:
GitHub
9月 23, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #38799 from genlu/AddTelemetry
Add telemetry for target type completion
上级
4ca99f98
337078a2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
10 deletion
+52
-10
src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs
...Core/Portable/Completion/Log/CompletionProvidersLogger.cs
+5
-0
src/Features/Core/Portable/Completion/Providers/AbstractRecommendationServiceBasedCompletionProvider.cs
...s/AbstractRecommendationServiceBasedCompletionProvider.cs
+2
-0
src/Features/Core/Portable/Completion/Providers/AbstractSymbolCompletionProvider.cs
.../Completion/Providers/AbstractSymbolCompletionProvider.cs
+45
-10
未找到文件。
src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs
浏览文件 @
1228c957
...
...
@@ -21,6 +21,8 @@ internal enum ActionInfo
TypeImportCompletionItemCount
,
TypeImportCompletionReferenceCount
,
TypeImportCompletionTimeoutCount
,
TargetTypeCompletionTicks
}
internal
static
void
LogTypeImportCompletionTicksDataPoint
(
int
count
)
=>
...
...
@@ -35,6 +37,9 @@ internal enum ActionInfo
internal
static
void
LogTypeImportCompletionTimeout
()
=>
s_logAggregator
.
IncreaseCount
((
int
)
ActionInfo
.
TypeImportCompletionTimeoutCount
);
internal
static
void
LogTargetTypeCompletionTicksDataPoint
(
int
count
)
=>
s_statisticLogAggregator
.
AddDataPoint
((
int
)
ActionInfo
.
TargetTypeCompletionTicks
,
count
);
internal
static
void
ReportTelemetry
()
{
Logger
.
Log
(
FunctionId
.
Intellisense_CompletionProviders_Data
,
KeyValueLogMessage
.
Create
(
m
=>
...
...
src/Features/Core/Portable/Completion/Providers/AbstractRecommendationServiceBasedCompletionProvider.cs
浏览文件 @
1228c957
...
...
@@ -17,6 +17,8 @@ namespace Microsoft.CodeAnalysis.Completion.Providers
{
internal
abstract
class
AbstractRecommendationServiceBasedCompletionProvider
:
AbstractSymbolCompletionProvider
{
protected
override
bool
ShouldCollectTelemetryForTargetTypeCompletion
=>
true
;
protected
override
Task
<
ImmutableArray
<
ISymbol
>>
GetSymbolsWorker
(
SyntaxContext
context
,
int
position
,
OptionSet
options
,
CancellationToken
cancellationToken
)
{
var
recommender
=
context
.
GetLanguageService
<
IRecommendationService
>();
...
...
src/Features/Core/Portable/Completion/Providers/AbstractSymbolCompletionProvider.cs
浏览文件 @
1228c957
...
...
@@ -7,6 +7,7 @@
using
System.Runtime.CompilerServices
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Completion.Log
;
using
Microsoft.CodeAnalysis.ErrorReporting
;
using
Microsoft.CodeAnalysis.Experiments
;
using
Microsoft.CodeAnalysis.Internal.Log
;
...
...
@@ -126,7 +127,8 @@ private bool IsTypeImplicitlyConvertible(Compilation compilation, ITypeSymbol so
Dictionary
<
ISymbol
,
List
<
ProjectId
>>
invalidProjectMap
,
List
<
ProjectId
>
totalProjects
,
bool
preselect
,
ImmutableArray
<
ITypeSymbol
>
inferredTypes
)
Lazy
<
ImmutableArray
<
ITypeSymbol
>>
inferredTypes
,
TelemetryCounter
telemetryCounter
)
{
var
symbolGroups
=
from
symbol
in
symbols
let
texts
=
GetDisplayAndSuffixAndInsertionText
(
symbol
,
contextLookup
(
symbol
))
...
...
@@ -145,7 +147,8 @@ private bool IsTypeImplicitlyConvertible(Compilation compilation, ITypeSymbol so
if
(
IsTargetTypeCompletionFilterExperimentEnabled
(
arbitraryFirstContext
.
Workspace
))
{
var
inferredTypesWithoutNullability
=
inferredTypes
.
SelectAsArray
(
t
=>
t
.
WithoutNullability
());
var
tick
=
Environment
.
TickCount
;
var
inferredTypesWithoutNullability
=
inferredTypes
.
Value
.
SelectAsArray
(
t
=>
t
.
WithoutNullability
());
foreach
(
var
symbol
in
symbolGroup
)
{
...
...
@@ -156,6 +159,8 @@ private bool IsTypeImplicitlyConvertible(Compilation compilation, ITypeSymbol so
break
;
}
}
telemetryCounter
.
AddTick
(
Environment
.
TickCount
-
tick
);
}
itemListBuilder
.
Add
(
item
);
...
...
@@ -262,13 +267,19 @@ public override async Task ProvideCompletionsAsync(CompletionContext context)
context
.
IsExclusive
=
IsExclusive
();
using
(
Logger
.
LogBlock
(
FunctionId
.
Completion_SymbolCompletionProvider_GetItemsWorker
,
cancellationToken
))
using
(
var
telemetryCounter
=
new
TelemetryCounter
(
ShouldCollectTelemetryForTargetTypeCompletion
&&
IsTargetTypeCompletionFilterExperimentEnabled
(
document
.
Project
.
Solution
.
Workspace
)))
{
var
syntaxContext
=
await
GetOrCreateContext
(
document
,
position
,
cancellationToken
).
ConfigureAwait
(
false
);
var
inferredTypes
=
new
Lazy
<
ImmutableArray
<
ITypeSymbol
>>(()
=>
{
var
typeInferenceService
=
document
.
GetLanguageService
<
ITypeInferenceService
>();
return
typeInferenceService
.
InferTypes
(
syntaxContext
.
SemanticModel
,
position
,
cancellationToken
);
});
var
regularItems
=
await
GetItemsWorkerAsync
(
syntaxContext
,
document
,
position
,
options
,
preselect
:
false
,
cancellationToken
:
cancellationToken
).
ConfigureAwait
(
false
);
var
regularItems
=
await
GetItemsWorkerAsync
(
syntaxContext
,
document
,
position
,
inferredTypes
,
options
,
preselect
:
false
,
telemetryCounter
,
cancellationToken
).
ConfigureAwait
(
false
);
context
.
AddItems
(
regularItems
);
var
preselectedItems
=
await
GetItemsWorkerAsync
(
syntaxContext
,
document
,
position
,
options
,
preselect
:
true
,
cancellationToken
:
cancellationToken
).
ConfigureAwait
(
false
);
var
preselectedItems
=
await
GetItemsWorkerAsync
(
syntaxContext
,
document
,
position
,
inferredTypes
,
options
,
preselect
:
true
,
telemetryCounter
,
cancellationToken
).
ConfigureAwait
(
false
);
context
.
AddItems
(
preselectedItems
);
}
}
...
...
@@ -279,19 +290,16 @@ public override async Task ProvideCompletionsAsync(CompletionContext context)
}
private
async
Task
<
IEnumerable
<
CompletionItem
>>
GetItemsWorkerAsync
(
SyntaxContext
context
,
Document
document
,
int
position
,
OptionSet
options
,
bool
preselect
,
CancellationToken
cancellationToken
)
SyntaxContext
context
,
Document
document
,
int
position
,
Lazy
<
ImmutableArray
<
ITypeSymbol
>>
inferredTypes
,
OptionSet
options
,
bool
preselect
,
TelemetryCounter
telemetryCounter
,
CancellationToken
cancellationToken
)
{
var
relatedDocumentIds
=
GetRelatedDocumentIds
(
document
,
position
);
options
=
GetUpdatedRecommendationOptions
(
options
,
document
.
Project
.
Language
);
var
typeInferenceService
=
document
.
GetLanguageService
<
ITypeInferenceService
>();
var
inferredTypes
=
typeInferenceService
.
InferTypes
(
context
.
SemanticModel
,
position
,
cancellationToken
);
if
(
relatedDocumentIds
.
IsEmpty
)
{
var
itemsForCurrentDocument
=
await
GetSymbolsWorker
(
position
,
preselect
,
context
,
options
,
cancellationToken
).
ConfigureAwait
(
false
);
return
CreateItems
(
itemsForCurrentDocument
,
_
=>
context
,
invalidProjectMap
:
null
,
totalProjects
:
null
,
preselect
,
inferredTypes
);
return
CreateItems
(
itemsForCurrentDocument
,
_
=>
context
,
invalidProjectMap
:
null
,
totalProjects
:
null
,
preselect
,
inferredTypes
,
telemetryCounter
);
}
var
contextAndSymbolLists
=
await
GetPerContextSymbols
(
document
,
position
,
options
,
new
[]
{
document
.
Id
}.
Concat
(
relatedDocumentIds
),
preselect
,
cancellationToken
).
ConfigureAwait
(
false
);
...
...
@@ -299,7 +307,7 @@ public override async Task ProvideCompletionsAsync(CompletionContext context)
var
missingSymbolsMap
=
FindSymbolsMissingInLinkedContexts
(
symbolToContextMap
,
contextAndSymbolLists
);
var
totalProjects
=
contextAndSymbolLists
.
Select
(
t
=>
t
.
documentId
.
ProjectId
).
ToList
();
return
CreateItems
(
symbolToContextMap
.
Keys
,
symbol
=>
symbolToContextMap
[
symbol
],
missingSymbolsMap
,
totalProjects
,
preselect
,
inferredTypes
);
return
CreateItems
(
symbolToContextMap
.
Keys
,
symbol
=>
symbolToContextMap
[
symbol
],
missingSymbolsMap
,
totalProjects
,
preselect
,
inferredTypes
,
telemetryCounter
);
}
private
static
ImmutableArray
<
DocumentId
>
GetRelatedDocumentIds
(
Document
document
,
int
position
)
...
...
@@ -462,5 +470,32 @@ protected virtual string GetInsertionText(CompletionItem item, char ch)
{
return
SymbolCompletionItem
.
GetInsertionText
(
item
);
}
// This is used to decide which provider we'd collect target type completion telemetry from.
protected
virtual
bool
ShouldCollectTelemetryForTargetTypeCompletion
=>
false
;
private
class
TelemetryCounter
:
IDisposable
{
private
readonly
bool
_shouldReport
;
private
int
_tick
;
public
TelemetryCounter
(
bool
shouldReport
)
{
_shouldReport
=
shouldReport
;
}
public
void
AddTick
(
int
tick
)
{
_tick
+=
tick
;
}
public
void
Dispose
()
{
if
(
_shouldReport
)
{
CompletionProvidersLogger
.
LogTargetTypeCompletionTicksDataPoint
(
_tick
);
}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录