Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
4646331d
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,体验更适合开发者的 AI 搜索 >>
提交
4646331d
编写于
10月 05, 2020
作者:
S
Sam Harwell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid Task allocations in common document extensions
上级
6344c7ae
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
25 addition
and
17 deletion
+25
-17
src/CodeStyle/Core/CodeFixes/LanguageServices/SemanticModelWorkspaceService/SemanticModelWorkspaceServiceFactory.SemanticModelWorkspaceService.cs
...lWorkspaceServiceFactory.SemanticModelWorkspaceService.cs
+1
-1
src/EditorFeatures/TestUtilities/ChangeSignature/AddedParameterOrExistingIndex.cs
...tilities/ChangeSignature/AddedParameterOrExistingIndex.cs
+1
-1
src/VisualStudio/Core/Def/Implementation/AbstractEditorFactory.cs
...alStudio/Core/Def/Implementation/AbstractEditorFactory.cs
+1
-1
src/VisualStudio/Core/Def/Implementation/ChangeSignature/AddParameterDialogViewModel.cs
...ementation/ChangeSignature/AddParameterDialogViewModel.cs
+1
-1
src/Workspaces/Core/Portable/ExternalAccess/Pythia/Api/PythiaDocumentExtensions.cs
...ble/ExternalAccess/Pythia/Api/PythiaDocumentExtensions.cs
+1
-1
src/Workspaces/Core/Portable/SemanticModelReuse/SemanticModelWorkspaceServiceFactory.SemanticModelWorkspaceService.cs
...lWorkspaceServiceFactory.SemanticModelWorkspaceService.cs
+1
-1
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/DocumentExtensions.cs
...xtensions/Workspace/Core/Extensions/DocumentExtensions.cs
+18
-10
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceServices/SemanticModelReuse/ISemanticModelReuseWorkspaceService.cs
...SemanticModelReuse/ISemanticModelReuseWorkspaceService.cs
+1
-1
未找到文件。
src/CodeStyle/Core/CodeFixes/LanguageServices/SemanticModelWorkspaceService/SemanticModelWorkspaceServiceFactory.SemanticModelWorkspaceService.cs
浏览文件 @
4646331d
...
...
@@ -17,7 +17,7 @@ public SemanticModelReuseWorkspaceService(Workspace _)
{
}
public
Task
<
SemanticModel
>
ReuseExistingSpeculativeModelAsync
(
Document
document
,
SyntaxNode
node
,
CancellationToken
cancellationToken
)
public
Value
Task
<
SemanticModel
>
ReuseExistingSpeculativeModelAsync
(
Document
document
,
SyntaxNode
node
,
CancellationToken
cancellationToken
)
{
// TODO: port the GetSemanticModelForNodeAsync implementation from Workspaces layer,
// which currently relies on a bunch of internal APIs.
...
...
src/EditorFeatures/TestUtilities/ChangeSignature/AddedParameterOrExistingIndex.cs
浏览文件 @
4646331d
...
...
@@ -61,7 +61,7 @@ public override string ToString()
internal
AddedParameter
GetAddedParameter
(
Document
document
)
{
var
semanticModel
=
document
.
GetRequiredSemanticModelAsync
(
CancellationToken
.
None
).
Result
;
var
semanticModel
=
document
.
GetRequiredSemanticModelAsync
(
CancellationToken
.
None
).
AsTask
().
Result
;
var
type
=
document
.
Project
.
Language
switch
{
...
...
src/VisualStudio/Core/Def/Implementation/AbstractEditorFactory.cs
浏览文件 @
4646331d
...
...
@@ -321,7 +321,7 @@ private void FormatDocumentCreatedFromTemplate(IVsHierarchy hierarchy, uint item
// Organize using directives
addedDocument
=
ThreadHelper
.
JoinableTaskFactory
.
Run
(()
=>
OrganizeUsingsCreatedFromTemplateAsync
(
addedDocument
,
cancellationToken
));
rootToFormat
=
ThreadHelper
.
JoinableTaskFactory
.
Run
(()
=>
addedDocument
.
GetRequiredSyntaxRootAsync
(
cancellationToken
));
rootToFormat
=
ThreadHelper
.
JoinableTaskFactory
.
Run
(()
=>
addedDocument
.
GetRequiredSyntaxRootAsync
(
cancellationToken
)
.
AsTask
()
);
// Format document
var
unformattedText
=
addedDocument
.
GetTextSynchronously
(
cancellationToken
);
...
...
src/VisualStudio/Core/Def/Implementation/ChangeSignature/AddParameterDialogViewModel.cs
浏览文件 @
4646331d
...
...
@@ -27,7 +27,7 @@ internal class AddParameterDialogViewModel : AbstractNotifyPropertyChanged
public
AddParameterDialogViewModel
(
Document
document
,
int
positionForTypeBinding
)
{
_notificationService
=
document
.
Project
.
Solution
.
Workspace
.
Services
.
GetService
<
INotificationService
>();
_semanticModel
=
document
.
GetRequiredSemanticModelAsync
(
CancellationToken
.
None
).
WaitAndGetResult_CanCallOnBackground
(
CancellationToken
.
None
);
_semanticModel
=
document
.
GetRequiredSemanticModelAsync
(
CancellationToken
.
None
).
AsTask
().
WaitAndGetResult_CanCallOnBackground
(
CancellationToken
.
None
);
TypeIsEmptyImage
=
Visibility
.
Visible
;
TypeBindsImage
=
Visibility
.
Collapsed
;
...
...
src/Workspaces/Core/Portable/ExternalAccess/Pythia/Api/PythiaDocumentExtensions.cs
浏览文件 @
4646331d
...
...
@@ -11,6 +11,6 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.Pythia.Api
internal
static
class
PythiaDocumentExtensions
{
public
static
Task
<
SemanticModel
>
GetSemanticModelForNodeAsync
(
this
Document
document
,
SyntaxNode
?
node
,
CancellationToken
cancellationToken
)
=>
DocumentExtensions
.
ReuseExistingSpeculativeModelAsync
(
document
,
node
,
cancellationToken
);
=>
DocumentExtensions
.
ReuseExistingSpeculativeModelAsync
(
document
,
node
,
cancellationToken
)
.
AsTask
()
;
}
}
src/Workspaces/Core/Portable/SemanticModelReuse/SemanticModelWorkspaceServiceFactory.SemanticModelWorkspaceService.cs
浏览文件 @
4646331d
...
...
@@ -90,7 +90,7 @@ public SemanticModelReuseWorkspaceService(Workspace workspace)
};
}
public
async
Task
<
SemanticModel
>
ReuseExistingSpeculativeModelAsync
(
Document
document
,
SyntaxNode
node
,
CancellationToken
cancellationToken
)
public
async
Value
Task
<
SemanticModel
>
ReuseExistingSpeculativeModelAsync
(
Document
document
,
SyntaxNode
node
,
CancellationToken
cancellationToken
)
{
var
reuseService
=
document
.
GetRequiredLanguageService
<
ISemanticModelReuseLanguageService
>();
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/DocumentExtensions.cs
浏览文件 @
4646331d
...
...
@@ -9,7 +9,6 @@
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.GeneratedCodeRecognition
;
using
Microsoft.CodeAnalysis.Host
;
using
Microsoft.CodeAnalysis.LanguageServices
;
using
Microsoft.CodeAnalysis.SemanticModelReuse
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
...
...
@@ -30,15 +29,21 @@ internal static partial class DocumentExtensions
public
static
TLanguageService
GetRequiredLanguageService
<
TLanguageService
>(
this
Document
document
)
where
TLanguageService
:
class
,
ILanguageService
=>
document
.
Project
.
GetRequiredLanguageService
<
TLanguageService
>();
public
static
async
Task
<
SemanticModel
>
GetRequiredSemanticModelAsync
(
this
Document
document
,
CancellationToken
cancellationToken
)
public
static
async
Value
Task
<
SemanticModel
>
GetRequiredSemanticModelAsync
(
this
Document
document
,
CancellationToken
cancellationToken
)
{
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
if
(
document
.
TryGetSemanticModel
(
out
var
semanticModel
))
return
semanticModel
;
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
return
semanticModel
??
throw
new
InvalidOperationException
(
string
.
Format
(
WorkspaceExtensionsResources
.
SyntaxTree_is_required_to_accomplish_the_task_but_is_not_supported_by_document_0
,
document
.
Name
));
}
public
static
async
Task
<
SyntaxTree
>
GetRequiredSyntaxTreeAsync
(
this
Document
document
,
CancellationToken
cancellationToken
)
public
static
async
Value
Task
<
SyntaxTree
>
GetRequiredSyntaxTreeAsync
(
this
Document
document
,
CancellationToken
cancellationToken
)
{
var
syntaxTree
=
await
document
.
GetSyntaxTreeAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
if
(
document
.
TryGetSyntaxTree
(
out
var
syntaxTree
))
return
syntaxTree
;
syntaxTree
=
await
document
.
GetSyntaxTreeAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
return
syntaxTree
??
throw
new
InvalidOperationException
(
string
.
Format
(
WorkspaceExtensionsResources
.
SyntaxTree_is_required_to_accomplish_the_task_but_is_not_supported_by_document_0
,
document
.
Name
));
}
...
...
@@ -50,9 +55,12 @@ public static SyntaxTree GetRequiredSyntaxTreeSynchronously(this Document docume
}
#endif
public
static
async
Task
<
SyntaxNode
>
GetRequiredSyntaxRootAsync
(
this
Document
document
,
CancellationToken
cancellationToken
)
public
static
async
Value
Task
<
SyntaxNode
>
GetRequiredSyntaxRootAsync
(
this
Document
document
,
CancellationToken
cancellationToken
)
{
var
root
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
if
(
document
.
TryGetSyntaxRoot
(
out
var
root
))
return
root
;
root
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
return
root
??
throw
new
InvalidOperationException
(
string
.
Format
(
WorkspaceExtensionsResources
.
SyntaxTree_is_required_to_accomplish_the_task_but_is_not_supported_by_document_0
,
document
.
Name
));
}
...
...
@@ -76,7 +84,7 @@ public static bool IsOpen(this TextDocument document)
/// <para/>
/// As a speculative semantic model may be returned, location based information provided by it may be innacurate.
/// </summary>
public
static
Task
<
SemanticModel
>
ReuseExistingSpeculativeModelAsync
(
this
Document
document
,
int
position
,
CancellationToken
cancellationToken
)
public
static
Value
Task
<
SemanticModel
>
ReuseExistingSpeculativeModelAsync
(
this
Document
document
,
int
position
,
CancellationToken
cancellationToken
)
=>
ReuseExistingSpeculativeModelAsync
(
document
,
new
TextSpan
(
position
,
0
),
cancellationToken
);
/// <summary>
...
...
@@ -93,7 +101,7 @@ public static Task<SemanticModel> ReuseExistingSpeculativeModelAsync(this Docume
/// <para/>
/// As a speculative semantic model may be returned, location based information provided by it may be innacurate.
/// </summary>
public
static
async
Task
<
SemanticModel
>
ReuseExistingSpeculativeModelAsync
(
this
Document
document
,
TextSpan
span
,
CancellationToken
cancellationToken
)
public
static
async
Value
Task
<
SemanticModel
>
ReuseExistingSpeculativeModelAsync
(
this
Document
document
,
TextSpan
span
,
CancellationToken
cancellationToken
)
{
Contract
.
ThrowIfFalse
(
document
.
SupportsSemanticModel
);
...
...
@@ -118,7 +126,7 @@ public static async Task<SemanticModel> ReuseExistingSpeculativeModelAsync(this
/// <para/>
/// As a speculative semantic model may be returned, location based information provided by it may be innacurate.
/// </summary>
public
static
Task
<
SemanticModel
>
ReuseExistingSpeculativeModelAsync
(
this
Document
document
,
SyntaxNode
?
node
,
CancellationToken
cancellationToken
)
public
static
Value
Task
<
SemanticModel
>
ReuseExistingSpeculativeModelAsync
(
this
Document
document
,
SyntaxNode
?
node
,
CancellationToken
cancellationToken
)
{
if
(
node
==
null
)
return
document
.
GetRequiredSemanticModelAsync
(
cancellationToken
);
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceServices/SemanticModelReuse/ISemanticModelReuseWorkspaceService.cs
浏览文件 @
4646331d
...
...
@@ -18,6 +18,6 @@ internal interface ISemanticModelReuseWorkspaceService : IWorkspaceService
/// <summary>
/// Don't call this directly. use <see cref="DocumentExtensions.ReuseExistingSpeculativeModelAsync(Document, SyntaxNode, CancellationToken)"/> (or an overload).
/// </summary>
Task
<
SemanticModel
>
ReuseExistingSpeculativeModelAsync
(
Document
document
,
SyntaxNode
node
,
CancellationToken
cancellationToken
);
Value
Task
<
SemanticModel
>
ReuseExistingSpeculativeModelAsync
(
Document
document
,
SyntaxNode
node
,
CancellationToken
cancellationToken
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录