Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c2da07d9
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,发现更多精彩内容 >>
未验证
提交
c2da07d9
编写于
5月 02, 2019
作者:
G
Gen Lu
提交者:
GitHub
5月 02, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #35434 from genlu/FixCompletionCache
Avoid caching VS completion item
上级
142fc19c
d40320ca
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
45 addition
and
6 deletion
+45
-6
src/EditorFeatures/Core/Implementation/IntelliSense/AsyncCompletion/CompletionSource.cs
...entation/IntelliSense/AsyncCompletion/CompletionSource.cs
+45
-6
未找到文件。
src/EditorFeatures/Core/Implementation/IntelliSense/AsyncCompletion/CompletionSource.cs
浏览文件 @
c2da07d9
...
...
@@ -48,8 +48,9 @@ internal class CompletionSource : ForegroundThreadAffinitizedObject, IAsyncCompl
private
static
readonly
EditorOptionKey
<
bool
>
NonBlockingCompletionEditorOption
=
new
EditorOptionKey
<
bool
>(
NonBlockingCompletion
);
private
static
readonly
ConditionalWeakTable
<
RoslynCompletionItem
,
VSCompletionItem
>
s_roslynItemToVsItem
=
new
ConditionalWeakTable
<
RoslynCompletionItem
,
VSCompletionItem
>();
// Use CWT to cache data needed to create VSCompletionItem, so the table would be cleared when Roslyn completion item cache is cleared.
private
static
readonly
ConditionalWeakTable
<
RoslynCompletionItem
,
VSCompletionItemData
>
s_roslynItemToVsItemData
=
new
ConditionalWeakTable
<
RoslynCompletionItem
,
VSCompletionItemData
>();
// Cache all the VS completion filters which essentially make them singletons.
// Because all items that should be filtered using the same filter button must
...
...
@@ -315,13 +316,50 @@ public async Task<object> GetDescriptionAsync(IAsyncCompletionSession session, V
}
}
/// <summary>
/// We'd like to cache VS Completion item dircetly to avoid allocation completely. However it holds references
/// to transient objects, which would cause memory leak (among other potential issues) if cached.
/// So as a compromise, we cache data that can be calculated from Roslyn completion item to avoid repeated
/// calculation cost for cached Roslyn completion items.
/// </summary>
private
class
VSCompletionItemData
{
public
VSCompletionItemData
(
string
displayText
,
ImageElement
icon
,
ImmutableArray
<
AsyncCompletionData
.
CompletionFilter
>
filters
,
ImmutableArray
<
ImageElement
>
attributeIcons
,
string
insertionText
)
{
DisplayText
=
displayText
;
Icon
=
icon
;
Filters
=
filters
;
AttributeIcons
=
attributeIcons
;
InsertionText
=
insertionText
;
}
public
string
DisplayText
{
get
;
}
public
ImageElement
Icon
{
get
;
}
public
ImmutableArray
<
AsyncCompletionData
.
CompletionFilter
>
Filters
{
get
;
}
public
ImmutableArray
<
ImageElement
>
AttributeIcons
{
get
;
}
public
string
InsertionText
{
get
;
}
}
private
VSCompletionItem
Convert
(
Document
document
,
RoslynCompletionItem
roslynItem
)
{
if
(
roslynItem
.
IsCached
&&
s_roslynItemToVsItem
.
TryGetValue
(
roslynItem
,
out
var
vsItem
))
if
(
roslynItem
.
IsCached
&&
s_roslynItemToVsItem
Data
.
TryGetValue
(
roslynItem
,
out
var
itemData
))
{
return
vsItem
;
return
new
VSCompletionItem
(
displayText
:
itemData
.
DisplayText
,
source
:
this
,
icon
:
itemData
.
Icon
,
filters
:
itemData
.
Filters
,
suffix
:
roslynItem
.
InlineDescription
,
// InlineDescription will be right-aligned in the selection popup
insertText
:
itemData
.
InsertionText
,
sortText
:
roslynItem
.
SortText
,
filterText
:
roslynItem
.
FilterText
,
attributeIcons
:
itemData
.
AttributeIcons
);
}
var
imageId
=
roslynItem
.
Tags
.
GetFirstGlyph
().
GetImageId
();
...
...
@@ -351,11 +389,12 @@ public async Task<object> GetDescriptionAsync(IAsyncCompletionSession session, V
item
.
Properties
.
AddProperty
(
RoslynItem
,
roslynItem
);
// It doesn't make sense to cache VS item for those Roslyn items created from scratch for each session,
// It doesn't make sense to cache VS item
data
for those Roslyn items created from scratch for each session,
// since CWT uses object identity for comparison.
if
(
roslynItem
.
IsCached
)
{
s_roslynItemToVsItem
.
Add
(
roslynItem
,
item
);
var
data
=
new
VSCompletionItemData
(
item
.
DisplayText
,
item
.
Icon
,
item
.
Filters
,
item
.
AttributeIcons
,
item
.
InsertText
);
s_roslynItemToVsItemData
.
Add
(
roslynItem
,
data
);
}
return
item
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录