Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
R
roslyn
管理
动态
成员
标记
计划
议题
议题看板
里程碑
Wiki
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
构建
流水线
作业
流水线计划
产物
部署
发布
软件包库
容器镜像库
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
模型实验
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
Show more breadcrumbs
麦壳饼
roslyn
提交
c2da07d9
未验证
提交
c2da07d9
编辑于
5年前
作者:
Gen Lu
提交者:
GitHub
5年前
浏览文件
操作
下载
差异文件
Merge pull request #35434 from genlu/FixCompletionCache
Avoid caching VS completion item
上级
142fc19c
d40320ca
No related branches found
No related tags found
无相关合并请求
变更
1
隐藏空白变更内容
行内
左右并排
显示
1 个更改的文件
src/EditorFeatures/Core/Implementation/IntelliSense/AsyncCompletion/CompletionSource.cs
+45
-6
45 个添加, 6 个删除
...entation/IntelliSense/AsyncCompletion/CompletionSource.cs
有
45 个添加
和
6 个删除
src/EditorFeatures/Core/Implementation/IntelliSense/AsyncCompletion/CompletionSource.cs
+
45
−
6
浏览文件 @
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 @@ private VSCompletionItem Convert(
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
;
...
...
This diff is collapsed.
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录