Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
db896485
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,发现更多精彩内容 >>
未验证
提交
db896485
编写于
7月 30, 2019
作者:
J
Jason Malinowski
提交者:
GitHub
7月 30, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #37312 from jasonmalinowski/fix-makemethodasync
Fix make method async/sync and some related code fixes
上级
3b61b5ed
f62a891d
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
132 addition
and
16 deletion
+132
-16
src/EditorFeatures/CSharpTest/Diagnostics/Iterator/ChangeToIEnumerableTests.cs
...harpTest/Diagnostics/Iterator/ChangeToIEnumerableTests.cs
+33
-0
src/EditorFeatures/CSharpTest/Diagnostics/MakeMethodAsynchronous/MakeMethodAsynchronousTests.cs
...ics/MakeMethodAsynchronous/MakeMethodAsynchronousTests.cs
+82
-0
src/Features/CSharp/Portable/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs
...table/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs
+3
-3
src/Features/CSharp/Portable/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs
...ixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs
+2
-2
src/Features/CSharp/Portable/MakeMethodAsynchronous/CSharpMakeMethodAsynchronousCodeFixProvider.cs
...ynchronous/CSharpMakeMethodAsynchronousCodeFixProvider.cs
+3
-3
src/Features/CSharp/Portable/MakeMethodSynchronous/CSharpMakeMethodSynchronousCodeFixProvider.cs
...Synchronous/CSharpMakeMethodSynchronousCodeFixProvider.cs
+2
-2
src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs
...table/ExtractInterface/AbstractExtractInterfaceService.cs
+2
-1
src/Features/VisualBasic/Portable/CodeFixes/Iterator/VisualBasicConvertToIteratorCodeFixProvider.vb
...s/Iterator/VisualBasicConvertToIteratorCodeFixProvider.vb
+1
-1
src/Workspaces/Core/Portable/Recommendations/AbstractRecommendationServiceRunner.cs
...le/Recommendations/AbstractRecommendationServiceRunner.cs
+1
-1
src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs
...aces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs
+2
-2
src/Workspaces/Core/Portable/Utilities/NullableHelpers/NullableExtensions.cs
.../Portable/Utilities/NullableHelpers/NullableExtensions.cs
+1
-1
未找到文件。
src/EditorFeatures/CSharpTest/Diagnostics/Iterator/ChangeToIEnumerableTests.cs
浏览文件 @
db896485
...
...
@@ -102,6 +102,39 @@ static IEnumerable<int> M()
await
TestInRegularAndScriptAsync
(
initial
,
expected
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsChangeToIEnumerable
)]
public
async
Task
TestChangeToIEnumerableWithListReturningMethodWithNullableArgument
()
{
var
initial
=
@"#nullable enable
using System;
using System.Collections.Generic;
class Program
{
static IList<string?> [|M|]()
{
yield return """";
}
}"
;
var
expected
=
@"#nullable enable
using System;
using System.Collections.Generic;
class Program
{
static IEnumerable<string?> M()
{
yield return """";
}
}"
;
await
TestInRegularAndScriptAsync
(
initial
,
expected
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsChangeToIEnumerable
)]
public
async
Task
TestChangeToIEnumerableGenericIEnumerableMethod
()
{
...
...
src/EditorFeatures/CSharpTest/Diagnostics/MakeMethodAsynchronous/MakeMethodAsynchronousTests.cs
浏览文件 @
db896485
...
...
@@ -1274,5 +1274,87 @@ void M()
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMakeMethodAsynchronous
)]
public
async
Task
MethodWithNullableReturn
()
{
await
TestInRegularAndScriptAsync
(
@"using System.Threading.Tasks;
class C
{
string? M()
{
[|await Task.Delay(1);|]
return null;
}
}"
,
@"using System.Threading.Tasks;
class C
{
async Task<string?> MAsync()
{
await Task.Delay(1);
return null;
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMakeMethodAsynchronous
)]
public
async
Task
EnumerableMethodWithNullableType
()
{
var
initial
=
@"using System.Threading.Tasks;
using System.Collections.Generic;
class Program
{
IEnumerable<string?> Test()
{
yield return string.Empty;
[|await Task.Delay(1);|]
}
}"
+
IAsyncEnumerable
;
var
expected
=
@"using System.Threading.Tasks;
using System.Collections.Generic;
class Program
{
async IAsyncEnumerable<string?> TestAsync()
{
yield return string.Empty;
await Task.Delay(1);
}
}"
+
IAsyncEnumerable
;
await
TestInRegularAndScriptAsync
(
initial
,
expected
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMakeMethodAsynchronous
)]
public
async
Task
EnumeratorMethodWithNullableType
()
{
var
initial
=
@"using System.Threading.Tasks;
using System.Collections.Generic;
class Program
{
IEnumerator<string?> Test()
{
yield return string.Empty;
[|await Task.Delay(1);|]
}
}"
+
IAsyncEnumerable
;
var
expected
=
@"using System.Threading.Tasks;
using System.Collections.Generic;
class Program
{
async IAsyncEnumerator<string?> TestAsync()
{
yield return string.Empty;
await Task.Delay(1);
}
}"
+
IAsyncEnumerable
;
await
TestInRegularAndScriptAsync
(
initial
,
expected
);
}
}
}
src/Features/CSharp/Portable/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs
浏览文件 @
db896485
...
...
@@ -115,8 +115,8 @@ private bool IsCorrectTypeForYieldReturn(ITypeSymbol typeArgument, ITypeSymbol r
return
false
;
}
ienumerableGenericSymbol
=
ienumerableGenericSymbol
.
Construct
(
typeArgument
);
ienumeratorGenericSymbol
=
ienumeratorGenericSymbol
.
Construct
(
typeArgument
);
ienumerableGenericSymbol
=
ienumerableGenericSymbol
.
Construct
WithNullability
(
typeArgument
);
ienumeratorGenericSymbol
=
ienumeratorGenericSymbol
.
Construct
WithNullability
(
typeArgument
);
if
(!
CanConvertTypes
(
typeArgument
,
returnExpressionType
,
model
))
{
...
...
@@ -137,7 +137,7 @@ private bool IsCorrectTypeForYieldReturn(ITypeSymbol typeArgument, ITypeSymbol r
private
bool
CanConvertTypes
(
ITypeSymbol
typeArgument
,
ITypeSymbol
returnExpressionType
,
SemanticModel
model
)
{
// return false if there is no conversion for the top level type
if
(!
model
.
Compilation
.
ClassifyConversion
(
typeArgument
,
returnExpressionType
).
Exists
)
if
(!
model
.
Compilation
.
ClassifyConversion
(
typeArgument
.
WithoutNullability
(),
returnExpressionType
.
WithoutNullability
()
).
Exists
)
{
return
false
;
}
...
...
src/Features/CSharp/Portable/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs
浏览文件 @
db896485
...
...
@@ -57,11 +57,11 @@ protected override async Task<CodeAction> GetCodeFixAsync(SyntaxNode root, Synta
if
(
arity
==
1
)
{
var
typeArg
=
type
.
GetTypeArguments
().
First
();
ienumerableGenericSymbol
=
ienumerableGenericSymbol
.
Construct
(
typeArg
);
ienumerableGenericSymbol
=
ienumerableGenericSymbol
.
Construct
WithNullability
(
typeArg
);
}
else
if
(
arity
==
0
&&
type
is
IArrayTypeSymbol
)
{
ienumerableGenericSymbol
=
ienumerableGenericSymbol
.
Construct
((
type
as
IArrayTypeSymbol
).
ElementType
);
ienumerableGenericSymbol
=
ienumerableGenericSymbol
.
Construct
WithNullability
((
type
as
IArrayTypeSymbol
).
ElementType
);
}
else
{
...
...
src/Features/CSharp/Portable/MakeMethodAsynchronous/CSharpMakeMethodAsynchronousCodeFixProvider.cs
浏览文件 @
db896485
...
...
@@ -102,13 +102,13 @@ protected override bool IsAsyncReturnType(ITypeSymbol type, KnownTypes knownType
{
newReturnType
=
knownTypes
.
_iAsyncEnumerableOfTTypeOpt
is
null
?
MakeGenericType
(
"IAsyncEnumerable"
,
methodSymbol
.
ReturnType
)
:
knownTypes
.
_iAsyncEnumerableOfTTypeOpt
.
Construct
(
methodSymbol
.
ReturnType
.
GetTypeArguments
()[
0
]).
GenerateTypeSyntax
();
:
knownTypes
.
_iAsyncEnumerableOfTTypeOpt
.
Construct
WithNullability
(
methodSymbol
.
ReturnType
.
GetTypeArguments
()[
0
]).
GenerateTypeSyntax
();
}
else
if
(
IsIEnumerator
(
returnType
,
knownTypes
)
&&
IsIterator
(
methodSymbol
))
{
newReturnType
=
knownTypes
.
_iAsyncEnumeratorOfTTypeOpt
is
null
?
MakeGenericType
(
"IAsyncEnumerator"
,
methodSymbol
.
ReturnType
)
:
knownTypes
.
_iAsyncEnumeratorOfTTypeOpt
.
Construct
(
methodSymbol
.
ReturnType
.
GetTypeArguments
()[
0
]).
GenerateTypeSyntax
();
:
knownTypes
.
_iAsyncEnumeratorOfTTypeOpt
.
Construct
WithNullability
(
methodSymbol
.
ReturnType
.
GetTypeArguments
()[
0
]).
GenerateTypeSyntax
();
}
else
if
(
IsIAsyncEnumerableOrEnumerator
(
returnType
,
knownTypes
))
{
...
...
@@ -118,7 +118,7 @@ protected override bool IsAsyncReturnType(ITypeSymbol type, KnownTypes knownType
{
// If it's not already Task-like, then wrap the existing return type
// in Task<>.
newReturnType
=
knownTypes
.
_taskOfTType
.
Construct
(
methodSymbol
.
ReturnType
).
GenerateTypeSyntax
();
newReturnType
=
knownTypes
.
_taskOfTType
.
Construct
WithNullability
(
methodSymbol
.
GetReturnTypeWithAnnotatedNullability
()
).
GenerateTypeSyntax
();
}
}
...
...
src/Features/CSharp/Portable/MakeMethodSynchronous/CSharpMakeMethodSynchronousCodeFixProvider.cs
浏览文件 @
db896485
...
...
@@ -72,12 +72,12 @@ private static TypeSyntax FixMethodReturnType(IMethodSymbol methodSymbol, TypeSy
else
if
(
returnType
.
OriginalDefinition
.
Equals
(
knownTypes
.
_iAsyncEnumerableOfTTypeOpt
))
{
// If the return type is IAsyncEnumerable<T>, then make the new return type IEnumerable<T>.
newReturnType
=
knownTypes
.
_iEnumerableOfTType
.
Construct
(
methodSymbol
.
ReturnType
.
GetTypeArguments
()[
0
]).
GenerateTypeSyntax
();
newReturnType
=
knownTypes
.
_iEnumerableOfTType
.
Construct
WithNullability
(
methodSymbol
.
ReturnType
.
GetTypeArguments
()[
0
]).
GenerateTypeSyntax
();
}
else
if
(
returnType
.
OriginalDefinition
.
Equals
(
knownTypes
.
_iAsyncEnumeratorOfTTypeOpt
))
{
// If the return type is IAsyncEnumerator<T>, then make the new return type IEnumerator<T>.
newReturnType
=
knownTypes
.
_iEnumeratorOfTType
.
Construct
(
methodSymbol
.
ReturnType
.
GetTypeArguments
()[
0
]).
GenerateTypeSyntax
();
newReturnType
=
knownTypes
.
_iEnumeratorOfTType
.
Construct
WithNullability
(
methodSymbol
.
ReturnType
.
GetTypeArguments
()[
0
]).
GenerateTypeSyntax
();
}
return
newReturnType
;
...
...
src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs
浏览文件 @
db896485
...
...
@@ -616,7 +616,8 @@ private bool DoesTypeReferenceTypeParameter(ITypeSymbol type, ITypeParameterSymb
return
false
;
}
if
(
type
==
typeParameter
||
// We want to ignore nullability when comparing as T and T? both are references to the type parameter
if
(
type
.
Equals
(
typeParameter
,
SymbolEqualityComparer
.
Default
)
||
type
.
GetTypeArguments
().
Any
(
t
=>
DoesTypeReferenceTypeParameter
(
t
,
typeParameter
,
checkedTypes
)))
{
return
true
;
...
...
src/Features/VisualBasic/Portable/CodeFixes/Iterator/VisualBasicConvertToIteratorCodeFixProvider.vb
浏览文件 @
db896485
...
...
@@ -67,7 +67,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.Iterator
Return
Nothing
End
If
ienumerableSymbol
=
ienumerableSymbol
.
Construct
(
method
.
ReturnType
.
GetTypeArguments
().
First
())
ienumerableSymbol
=
ienumerableSymbol
.
Construct
WithNullability
(
method
.
ReturnType
.
GetTypeArguments
().
First
())
If
Not
method
.
ReturnType
.
Equals
(
ienumerableSymbol
)
Then
Return
Nothing
...
...
src/Workspaces/Core/Portable/Recommendations/AbstractRecommendationServiceRunner.cs
浏览文件 @
db896485
...
...
@@ -222,7 +222,7 @@ protected static bool IsNonIntersectingNamespace(ISymbol recommendationSymbol, S
?
_context
.
SemanticModel
.
LookupStaticMembers
(
position
,
container
)
:
SuppressDefaultTupleElements
(
container
,
_context
.
SemanticModel
.
LookupSymbols
(
position
,
container
,
includeReducedExtensionMethods
:
true
));
_context
.
SemanticModel
.
LookupSymbols
(
position
,
container
.
WithoutNullability
()
,
includeReducedExtensionMethods
:
true
));
}
/// <summary>
...
...
src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs
浏览文件 @
db896485
...
...
@@ -464,8 +464,8 @@ public static ImmutableArray<ITypeSymbol> GetTypeArguments(this ISymbol symbol)
{
switch
(
symbol
)
{
case
IMethodSymbol
m
:
return
m
.
TypeArguments
;
case
INamedTypeSymbol
nt
:
return
nt
.
TypeArguments
;
case
IMethodSymbol
m
:
return
m
.
TypeArguments
.
ZipAsArray
(
m
.
TypeArgumentNullableAnnotations
,
(
t
,
n
)
=>
t
.
WithNullability
(
n
))
;
case
INamedTypeSymbol
nt
:
return
nt
.
TypeArguments
.
ZipAsArray
(
nt
.
TypeArgumentNullableAnnotations
,
(
t
,
n
)
=>
t
.
WithNullability
(
n
))
;
default
:
return
ImmutableArray
.
Create
<
ITypeSymbol
>();
}
}
...
...
src/Workspaces/Core/Portable/Utilities/NullableHelpers/NullableExtensions.cs
浏览文件 @
db896485
...
...
@@ -66,7 +66,7 @@ public static NullableAnnotation GetNullability(this ITypeSymbol typeSymbol)
}
}
public
static
T
WithoutNullability
<
T
>(
this
T
typeSymbol
)
where
T
:
ITypeSymbol
public
static
T
WithoutNullability
<
T
>(
this
T
typeSymbol
)
where
T
:
I
NamespaceOr
TypeSymbol
{
if
(
typeSymbol
is
TypeSymbolWithNullableAnnotation
typeSymbolWithNullability
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录