Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
5dc0a900
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,发现更多精彩内容 >>
未验证
提交
5dc0a900
编写于
4月 03, 2020
作者:
G
Gen Lu
提交者:
GitHub
4月 03, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #43043 from genlu/stackallocCompletion
show stackalloc completion in expression context
上级
2d3b98b7
08469d64
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
60 deletion
+58
-60
src/EditorFeatures/CSharpTest2/Recommendations/StackAllocKeywordRecommenderTests.cs
...est2/Recommendations/StackAllocKeywordRecommenderTests.cs
+53
-14
src/Features/CSharp/Portable/Completion/KeywordRecommenders/StackAllocKeywordRecommender.cs
...etion/KeywordRecommenders/StackAllocKeywordRecommender.cs
+5
-46
未找到文件。
src/EditorFeatures/CSharpTest2/Recommendations/StackAllocKeywordRecommenderTests.cs
浏览文件 @
5dc0a900
...
...
@@ -12,32 +12,32 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Recommendations
public
class
StackAllocKeywordRecommenderTests
:
KeywordRecommenderTests
{
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
KeywordRecommending
)]
public
async
Task
Test
Not
AtRoot_Interactive
()
public
async
Task
TestAtRoot_Interactive
()
{
await
Verify
Absence
Async
(
SourceCodeKind
.
Script
,
await
Verify
Keyword
Async
(
SourceCodeKind
.
Script
,
@"$$"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
KeywordRecommending
)]
public
async
Task
Test
Not
AfterClass_Interactive
()
public
async
Task
TestAfterClass_Interactive
()
{
await
Verify
Absence
Async
(
SourceCodeKind
.
Script
,
await
Verify
Keyword
Async
(
SourceCodeKind
.
Script
,
@"class C { }
$$"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
KeywordRecommending
)]
public
async
Task
Test
Not
AfterGlobalStatement_Interactive
()
public
async
Task
TestAfterGlobalStatement_Interactive
()
{
await
Verify
Absence
Async
(
SourceCodeKind
.
Script
,
await
Verify
Keyword
Async
(
SourceCodeKind
.
Script
,
@"System.Console.WriteLine();
$$"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
KeywordRecommending
)]
public
async
Task
Test
Not
AfterGlobalVariableDeclaration_Interactive
()
public
async
Task
TestAfterGlobalVariableDeclaration_Interactive
()
{
await
Verify
Absence
Async
(
SourceCodeKind
.
Script
,
await
Verify
Keyword
Async
(
SourceCodeKind
.
Script
,
@"int i = 0;
$$"
);
}
...
...
@@ -50,9 +50,11 @@ public async Task TestNotInUsingAlias()
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
KeywordRecommending
)]
public
async
Task
Test
Not
InEmptyStatement
()
public
async
Task
TestInEmptyStatement
()
{
await
VerifyAbsenceAsync
(
AddInsideMethod
(
// e.g. this is a valid statement
// stackalloc[] { 1, 2, 3 }.IndexOf(1);
await
VerifyKeywordAsync
(
AddInsideMethod
(
@"$$"
));
}
...
...
@@ -92,11 +94,14 @@ public async Task TestInUnsafeEmptySpace_AfterPointer()
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
KeywordRecommending
)]
public
async
Task
Test
Not
InField
()
public
async
Task
TestInField
()
{
await
VerifyAbsenceAsync
(
@"unsafe class C {
int* v = $$"
);
// While assigning stackalloc'd value to a field is invalid,
// using one in the initializer is OK. e.g.
// int _f = stackalloc[] { 1, 2, 3 }.IndexOf(1);
await
VerifyKeywordAsync
(
@"class C {
int v = $$"
);
}
[
WorkItem
(
544504
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544504"
)]
...
...
@@ -268,5 +273,39 @@ public async Task TestNotInLHSOfAssignment()
await
VerifyAbsenceAsync
(
AddInsideMethod
(
@"
x $$ ="
));
}
[
WorkItem
(
41736
,
"https://github.com/dotnet/roslyn/issues/41736"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
KeywordRecommending
)]
public
async
Task
TestInArgument
()
{
await
VerifyKeywordAsync
(
@"
class Program
{
static void Method(System.Span<byte> span)
{
Method($$);
}
}"
);
await
VerifyKeywordAsync
(
@"
class Program
{
static void Method(int x, System.Span<byte> span)
{
Method(1, $$);
}
}"
);
}
[
WorkItem
(
41736
,
"https://github.com/dotnet/roslyn/issues/41736"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
KeywordRecommending
)]
public
async
Task
TestNotInConstFieldInitializer
()
{
await
VerifyAbsenceAsync
(
@"
class Program
{
private const int _f = $$
}"
);
}
}
}
src/Features/CSharp/Portable/Completion/KeywordRecommenders/StackAllocKeywordRecommender.cs
浏览文件 @
5dc0a900
...
...
@@ -17,52 +17,11 @@ public StackAllocKeywordRecommender()
protected
override
bool
IsValidContext
(
int
position
,
CSharpSyntaxContext
context
,
CancellationToken
cancellationToken
)
{
var
node
=
context
.
TargetToken
.
Parent
;
// At start of a file
if
(
node
==
null
)
{
return
false
;
}
// After a cast or parenthesized expression: (Span<int>)stackalloc
if
(
context
.
TargetToken
.
IsAfterPossibleCast
())
{
node
=
node
.
Parent
;
}
// Inside a conditional expression: value ? stackalloc : stackalloc
while
(
node
.
IsKind
(
SyntaxKind
.
ConditionalExpression
)
&&
(
context
.
TargetToken
.
IsKind
(
SyntaxKind
.
QuestionToken
,
SyntaxKind
.
ColonToken
)
||
context
.
TargetToken
.
IsAfterPossibleCast
()))
{
node
=
node
.
Parent
;
}
// assignment: x = stackalloc
if
(
node
.
IsKind
(
SyntaxKind
.
SimpleAssignmentExpression
))
{
return
node
.
Parent
.
IsKind
(
SyntaxKind
.
ExpressionStatement
);
}
// declaration: var x = stackalloc
if
(
node
.
IsKind
(
SyntaxKind
.
EqualsValueClause
))
{
node
=
node
.
Parent
;
if
(
node
.
IsKind
(
SyntaxKind
.
VariableDeclarator
))
{
node
=
node
.
Parent
;
if
(
node
.
IsKind
(
SyntaxKind
.
VariableDeclaration
))
{
node
=
node
.
Parent
;
return
node
.
IsKind
(
SyntaxKind
.
LocalDeclarationStatement
,
SyntaxKind
.
ForStatement
);
}
}
}
return
false
;
// Beginning with C# 8.0, stackalloc expression can be used inside other expressions
// whenever a Span<T> or ReadOnlySpan<T> variable is allowed.
return
(
context
.
IsAnyExpressionContext
&&
!
context
.
IsConstantExpressionContext
)
||
context
.
IsStatementContext
||
context
.
IsGlobalStatementContext
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录