Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
161e37f8
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,发现更多精彩内容 >>
提交
161e37f8
编写于
8月 05, 2016
作者:
R
Ravi Chande
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Give the TypeInferenceService the ability to communicate additional info about the inferred type.
上级
01915211
变更
6
展开全部
显示空白变更内容
内联
并排
Showing
6 changed file
with
449 addition
and
392 deletion
+449
-392
src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SuggestionModeCompletionProviderTests.cs
...pletionProviders/SuggestionModeCompletionProviderTests.cs
+14
-0
src/Features/CSharp/Portable/Completion/SuggestionMode/CSharpSuggestionModeCompletionProvider.cs
.../SuggestionMode/CSharpSuggestionModeCompletionProvider.cs
+6
-5
src/Workspaces/CSharp/Portable/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs
...nguageServices/CSharpTypeInferenceService.TypeInferrer.cs
+227
-225
src/Workspaces/Core/Portable/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.cs
...ices/TypeInferenceService/AbstractTypeInferenceService.cs
+24
-13
src/Workspaces/Core/Portable/LanguageServices/TypeInferenceService/ITypeInferenceService.cs
...ageServices/TypeInferenceService/ITypeInferenceService.cs
+23
-0
src/Workspaces/VisualBasic/Portable/LanguageServices/VisualBasicTypeInferenceService.TypeInferrer.vb
...eServices/VisualBasicTypeInferenceService.TypeInferrer.vb
+155
-149
未找到文件。
src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SuggestionModeCompletionProviderTests.cs
浏览文件 @
161e37f8
...
...
@@ -644,6 +644,20 @@ class C {
await
VerifyBuilderAsync
(
markup
);
}
[
WorkItem
(
12818
,
"https://github.com/dotnet/roslyn/issues/12818"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Completion
)]
public
async
Task
DoNotUnwrapRegularArray
()
{
var
markup
=
@"
using System;
class C {
C(Action<int>[] a) {
new C($$
}
}"
;
await
VerifyNotBuilderAsync
(
markup
);
}
private
async
Task
VerifyNotBuilderAsync
(
string
markup
)
{
await
VerifyWorkerAsync
(
markup
,
isBuilder
:
false
);
...
...
src/Features/CSharp/Portable/Completion/SuggestionMode/CSharpSuggestionModeCompletionProvider.cs
浏览文件 @
161e37f8
...
...
@@ -157,19 +157,20 @@ private bool IsLambdaExpression(SemanticModel semanticModel, int position, Synta
// If we're an argument to a function with multiple overloads,
// open the builder if any overload takes a delegate at our argument position
var
inferredTypes
=
typeInferrer
.
InferTypes
(
semanticModel
,
position
,
cancellationToken
:
cancellationToken
);
var
inferredTypes
=
typeInferrer
.
GetTypeInferenceInfo
(
semanticModel
,
position
,
cancellationToken
:
cancellationToken
);
return
inferredTypes
.
Any
(
type
=>
GetDelegateType
(
type
,
semanticModel
.
Compilation
).
IsDelegateType
());
}
private
ITypeSymbol
GetDelegateType
(
ITypeSymbol
type
,
Compilation
compilation
)
private
ITypeSymbol
GetDelegateType
(
TypeInferenceInfo
type
,
Compilation
compilation
)
{
if
(
type
.
IsArrayType
())
ITypeSymbol
typeSymbol
=
type
.
InferredType
;
if
(
type
.
IsParams
&&
type
.
InferredType
.
IsArrayType
())
{
type
=
((
IArrayTypeSymbol
)
t
ype
).
ElementType
;
type
Symbol
=
((
IArrayTypeSymbol
)
type
.
InferredT
ype
).
ElementType
;
}
return
type
.
GetDelegateType
(
compilation
);
return
type
Symbol
.
GetDelegateType
(
compilation
);
}
}
}
src/Workspaces/CSharp/Portable/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs
浏览文件 @
161e37f8
此差异已折叠。
点击以展开。
src/Workspaces/Core/Portable/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.cs
浏览文件 @
161e37f8
...
...
@@ -13,36 +13,37 @@ internal abstract class AbstractTypeInferenceService<TExpressionSyntax> : ITypeI
{
protected
abstract
class
AbstractTypeInferrer
{
protected
readonly
CancellationToken
CancellationToken
;
protected
readonly
SemanticModel
SemanticModel
;
protected
readonly
Func
<
ITypeSymbol
,
bool
>
IsUsableTypeFunc
;
protected
readonly
Func
<
TypeInferenceInfo
,
bool
>
IsUsableTypeFunc
;
private
readonly
HashSet
<
TExpressionSyntax
>
_seenExpressionInferType
=
new
HashSet
<
TExpressionSyntax
>();
private
readonly
HashSet
<
TExpressionSyntax
>
_seenExpressionGetType
=
new
HashSet
<
TExpressionSyntax
>();
private
static
readonly
Func
<
ITypeSymbol
,
bool
>
s_isNotNull
=
t
=>
t
!=
null
;
private
static
readonly
Func
<
TypeInferenceInfo
,
bool
>
s_isNotNull
=
t
=>
t
.
InferredType
!=
null
;
protected
AbstractTypeInferrer
(
SemanticModel
semanticModel
,
CancellationToken
cancellationToken
)
{
this
.
SemanticModel
=
semanticModel
;
this
.
CancellationToken
=
cancellationToken
;
this
.
IsUsableTypeFunc
=
t
=>
t
!=
null
&&
!
IsUnusableType
(
t
);
this
.
IsUsableTypeFunc
=
t
=>
t
.
InferredType
!=
null
&&
!
IsUnusableType
(
t
.
InferredType
);
}
protected
abstract
IEnumerable
<
ITypeSymbol
>
InferTypesWorker_DoNotCallDirectly
(
int
position
);
protected
abstract
IEnumerable
<
ITypeSymbol
>
InferTypesWorker_DoNotCallDirectly
(
TExpressionSyntax
expression
);
protected
abstract
IEnumerable
<
ITypeSymbol
>
GetTypes_DoNotCallDirectly
(
TExpressionSyntax
expression
,
bool
objectAsDefault
);
protected
abstract
IEnumerable
<
TypeInferenceInfo
>
InferTypesWorker_DoNotCallDirectly
(
int
position
);
protected
abstract
IEnumerable
<
TypeInferenceInfo
>
InferTypesWorker_DoNotCallDirectly
(
TExpressionSyntax
expression
);
protected
abstract
IEnumerable
<
TypeInferenceInfo
>
GetTypes_DoNotCallDirectly
(
TExpressionSyntax
expression
,
bool
objectAsDefault
);
protected
abstract
bool
IsUnusableType
(
ITypeSymbol
arg
);
protected
Compilation
Compilation
=>
SemanticModel
.
Compilation
;
public
IEnumerable
<
ITypeSymbol
>
InferTypes
(
int
position
)
public
IEnumerable
<
TypeInferenceInfo
>
InferTypes
(
int
position
)
{
var
types
=
InferTypesWorker_DoNotCallDirectly
(
position
);
return
Filter
(
types
);
}
public
IEnumerable
<
ITypeSymbol
>
InferTypes
(
TExpressionSyntax
expression
,
bool
filterUnusable
=
true
)
public
IEnumerable
<
TypeInferenceInfo
>
InferTypes
(
TExpressionSyntax
expression
,
bool
filterUnusable
=
true
)
{
if
(
expression
!=
null
)
{
...
...
@@ -53,20 +54,20 @@ public IEnumerable<ITypeSymbol> InferTypes(TExpressionSyntax expression, bool fi
}
}
return
SpecializedCollections
.
EmptyEnumerable
<
ITypeSymbol
>();
return
SpecializedCollections
.
EmptyEnumerable
<
TypeInferenceInfo
>();
}
protected
IEnumerable
<
ITypeSymbol
>
GetTypes
(
TExpressionSyntax
expression
,
bool
objectAsDefault
=
false
)
protected
IEnumerable
<
TypeInferenceInfo
>
GetTypes
(
TExpressionSyntax
expression
,
bool
objectAsDefault
=
false
)
{
if
(
_seenExpressionGetType
.
Add
(
expression
))
{
return
GetTypes_DoNotCallDirectly
(
expression
,
objectAsDefault
);
}
return
SpecializedCollections
.
EmptyEnumerable
<
ITypeSymbol
>();
return
SpecializedCollections
.
EmptyEnumerable
<
TypeInferenceInfo
>();
}
private
IEnumerable
<
ITypeSymbol
>
Filter
(
IEnumerable
<
ITypeSymbol
>
types
,
bool
filterUnusable
=
true
)
private
IEnumerable
<
TypeInferenceInfo
>
Filter
(
IEnumerable
<
TypeInferenceInfo
>
types
,
bool
filterUnusable
=
true
)
{
return
types
.
Where
(
filterUnusable
?
IsUsableTypeFunc
:
s_isNotNull
)
.
Distinct
()
...
...
@@ -95,10 +96,20 @@ protected IEnumerable<ITypeSymbol> ExpandParamsParameter(IParameterSymbol parame
public
IEnumerable
<
ITypeSymbol
>
InferTypes
(
SemanticModel
semanticModel
,
int
position
,
CancellationToken
cancellationToken
)
{
return
CreateTypeInferrer
(
semanticModel
,
cancellationToken
).
InferTypes
(
position
);
return
CreateTypeInferrer
(
semanticModel
,
cancellationToken
).
InferTypes
(
position
)
.
Select
(
t
=>
t
.
InferredType
)
;
}
public
IEnumerable
<
ITypeSymbol
>
InferTypes
(
SemanticModel
semanticModel
,
SyntaxNode
expression
,
CancellationToken
cancellationToken
)
{
return
CreateTypeInferrer
(
semanticModel
,
cancellationToken
).
InferTypes
(
expression
as
TExpressionSyntax
).
Select
(
t
=>
t
.
InferredType
);
}
public
IEnumerable
<
TypeInferenceInfo
>
GetTypeInferenceInfo
(
SemanticModel
semanticModel
,
int
position
,
CancellationToken
cancellationToken
)
{
return
CreateTypeInferrer
(
semanticModel
,
cancellationToken
).
InferTypes
(
position
);
}
public
IEnumerable
<
TypeInferenceInfo
>
GetTypeInferenceInfo
(
SemanticModel
semanticModel
,
SyntaxNode
expression
,
CancellationToken
cancellationToken
)
{
return
CreateTypeInferrer
(
semanticModel
,
cancellationToken
).
InferTypes
(
expression
as
TExpressionSyntax
);
}
...
...
src/Workspaces/Core/Portable/LanguageServices/TypeInferenceService/ITypeInferenceService.cs
浏览文件 @
161e37f8
...
...
@@ -24,5 +24,28 @@ internal interface ITypeInferenceService : ILanguageService
{
IEnumerable
<
ITypeSymbol
>
InferTypes
(
SemanticModel
semanticModel
,
SyntaxNode
expression
,
CancellationToken
cancellationToken
);
IEnumerable
<
ITypeSymbol
>
InferTypes
(
SemanticModel
semanticModel
,
int
position
,
CancellationToken
cancellationToken
);
IEnumerable
<
TypeInferenceInfo
>
GetTypeInferenceInfo
(
SemanticModel
semanticModel
,
int
position
,
CancellationToken
cancellationToken
);
IEnumerable
<
TypeInferenceInfo
>
GetTypeInferenceInfo
(
SemanticModel
semanticModel
,
SyntaxNode
expression
,
CancellationToken
cancellationToken
);
}
internal
struct
TypeInferenceInfo
{
private
bool
isParams
;
public
TypeInferenceInfo
(
ITypeSymbol
type
)
:
this
()
{
InferredType
=
type
;
}
public
TypeInferenceInfo
(
ITypeSymbol
type
,
bool
isParams
)
:
this
()
{
InferredType
=
type
;
IsParams
=
isParams
;
}
public
ITypeSymbol
InferredType
{
get
;
}
public
bool
IsParams
{
get
;
}
}
}
src/Workspaces/VisualBasic/Portable/LanguageServices/VisualBasicTypeInferenceService.TypeInferrer.vb
浏览文件 @
161e37f8
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录