Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c4932a97
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 搜索 >>
未验证
提交
c4932a97
编写于
10月 19, 2020
作者:
M
msftbot[bot]
提交者:
GitHub
10月 19, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #48763 from CyrusNajmabadi/inlineHintDeclExpr
Support inline hints for declaration expressions.
上级
693e68db
7c1b3e82
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
118 addition
and
10 deletion
+118
-10
src/EditorFeatures/Test2/InlineHints/AbstractInlineHintsTests.vb
...torFeatures/Test2/InlineHints/AbstractInlineHintsTests.vb
+5
-5
src/EditorFeatures/Test2/InlineHints/CSharpInlineTypeHintsTests.vb
...rFeatures/Test2/InlineHints/CSharpInlineTypeHintsTests.vb
+104
-0
src/Features/CSharp/Portable/InlineHints/CSharpInlineTypeHintsService.cs
...harp/Portable/InlineHints/CSharpInlineTypeHintsService.cs
+9
-5
未找到文件。
src/EditorFeatures/Test2/InlineHints/AbstractInlineHintsTests.vb
浏览文件 @
c4932a97
...
...
@@ -45,14 +45,14 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.InlineHints
AssertEx
.
Equal
(
expectedTags
,
producedTags
)
End
Sub
Protected
Async
Function
VerifyTypeHints
(
test
As
XElement
,
Optional
optionIsEnabled
As
Boolean
=
True
)
As
Task
Protected
Async
Function
VerifyTypeHints
(
test
As
XElement
,
Optional
optionIsEnabled
As
Boolean
=
True
,
Optional
ephemeral
As
Boolean
=
False
)
As
Task
Using
workspace
=
TestWorkspace
.
Create
(
test
)
WpfTestRunner
.
RequireWpfFact
(
$
"{NameOf(AbstractInlineHintsTests)}.{NameOf(Me.VerifyTypeHints)} creates asynchronous taggers"
)
workspace
.
TryApplyChanges
(
workspace
.
CurrentSolution
.
WithOptions
(
workspace
.
Options
.
WithChangedOption
(
InlineHintsOptions
.
EnabledForTypes
,
workspace
.
CurrentSolution
.
Projects
().
First
().
Language
,
optionIsEnabled
)))
Dim
language
=
workspace
.
CurrentSolution
.
Projects
().
First
().
Language
workspace
.
TryApplyChanges
(
workspace
.
CurrentSolution
.
WithOptions
(
workspace
.
Options
.
WithChangedOption
(
InlineHintsOptions
.
EnabledForTypes
,
language
,
optionIsEnabled
AndAlso
Not
ephemeral
).
WithChangedOption
(
InlineHintsOptions
.
DisplayAllOverride
,
ephemeral
)))
Dim
hostDocument
=
workspace
.
Documents
.
Single
()
Dim
snapshot
=
hostDocument
.
GetTextBuffer
().
CurrentSnapshot
...
...
src/EditorFeatures/Test2/InlineHints/CSharpInlineTypeHintsTests.vb
浏览文件 @
c4932a97
...
...
@@ -46,6 +46,26 @@ class A
Await
VerifyTypeHints
(
input
)
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
InlineHints
)
>
Public
Async
Function
TestOnLocalVariableWithVarType_Ephemeral
()
As
Task
Dim
input
=
<
Workspace
>
<
Project
Language
=
"C#"
CommonReferences
=
"true"
>
<
Document
>
class
A
{
void
Main
()
{
{
|
int
:
var
|
}
i
=
0
;
}
}
</
Document
>
</
Project
>
</
Workspace
>
Await
VerifyTypeHints
(
input
,
ephemeral
:
=
True
)
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
InlineHints
)
>
Public
Async
Function
TestOnDeconstruction
()
As
Task
Dim
input
=
...
...
@@ -86,6 +106,26 @@ class A
Await
VerifyTypeHints
(
input
)
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
InlineHints
)
>
Public
Async
Function
TestWithForeachVar_Ephemeral
()
As
Task
Dim
input
=
<
Workspace
>
<
Project
Language
=
"C#"
CommonReferences
=
"true"
>
<
Document
>
class
A
{
void
Main
(
string
[]
args
)
{
foreach
({
|
string
:
var
|
}
j
in
args
)
{}
}
}
</
Document
>
</
Project
>
</
Workspace
>
Await
VerifyTypeHints
(
input
,
ephemeral
:
=
True
)
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
InlineHints
)
>
Public
Async
Function
TestNotWithForeachType
()
As
Task
Dim
input
=
...
...
@@ -126,6 +166,26 @@ class A
Await
VerifyTypeHints
(
input
)
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
InlineHints
)
>
Public
Async
Function
TestWithPatternVar_Ephemeral
()
As
Task
Dim
input
=
<
Workspace
>
<
Project
Language
=
"C#"
CommonReferences
=
"true"
>
<
Document
>
class
A
{
void
Main
(
string
[]
args
)
{
if
(
args
is
{
Length
:
{
|
int
:
var
|
}
goo
})
{
}
}
}
</
Document
>
</
Project
>
</
Workspace
>
Await
VerifyTypeHints
(
input
,
ephemeral
:
=
True
)
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
InlineHints
)
>
Public
Async
Function
TestNotWithPatternType
()
As
Task
Dim
input
=
...
...
@@ -208,5 +268,49 @@ class A
Await
VerifyTypeHints
(
input
)
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
InlineHints
)
>
Public
Async
Function
TestWithDeclarationExpression
()
As
Task
Dim
input
=
<
Workspace
>
<
Project
Language
=
"C#"
CommonReferences
=
"true"
>
<
Document
>
class
A
{
void
Main
(
string
[]
args
)
{
if
(
int
.
TryParse
(
""
,
out
var
{
|
int
:
|
}
x
))
{
}
}
}
</
Document
>
</
Project
>
</
Workspace
>
Await
VerifyTypeHints
(
input
)
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
InlineHints
)
>
Public
Async
Function
TestWithDeclarationExpression_Ephemeral
()
As
Task
Dim
input
=
<
Workspace
>
<
Project
Language
=
"C#"
CommonReferences
=
"true"
>
<
Document
>
class
A
{
void
Main
(
string
[]
args
)
{
if
(
int
.
TryParse
(
""
,
out
{
|
int
:
var
|
}
x
))
{
}
}
}
</
Document
>
</
Project
>
</
Workspace
>
Await
VerifyTypeHints
(
input
,
ephemeral
:
=
True
)
End
Function
End
Class
End
Namespace
src/Features/CSharp/Portable/InlineHints/CSharpInlineTypeHintsService.cs
浏览文件 @
c4932a97
...
...
@@ -33,8 +33,7 @@ public CSharpInlineTypeHintsService()
{
if
(
forImplicitVariableTypes
||
displayAllOverride
)
{
if
(
node
is
VariableDeclarationSyntax
variableDeclaration
&&
variableDeclaration
.
Type
.
IsVar
&&
if
(
node
is
VariableDeclarationSyntax
{
Type
:
{
IsVar
:
true
}
}
variableDeclaration
&&
variableDeclaration
.
Variables
.
Count
==
1
&&
!
variableDeclaration
.
Variables
[
0
].
Identifier
.
IsMissing
)
{
...
...
@@ -42,7 +41,13 @@ public CSharpInlineTypeHintsService()
if
(
IsValidType
(
type
))
return
(
type
,
GetSpan
(
displayAllOverride
,
forImplicitVariableTypes
,
variableDeclaration
.
Type
,
variableDeclaration
.
Variables
[
0
].
Identifier
));
}
else
if
(
node
is
SingleVariableDesignationSyntax
{
Parent
:
not
DeclarationPatternSyntax
}
variableDesignation
)
if
(
node
is
DeclarationExpressionSyntax
{
Type
:
{
IsVar
:
true
}
}
declarationExpression
)
{
var
type
=
semanticModel
.
GetTypeInfo
(
declarationExpression
.
Type
,
cancellationToken
).
Type
;
if
(
IsValidType
(
type
))
return
(
type
,
GetSpan
(
displayAllOverride
,
forImplicitVariableTypes
,
declarationExpression
.
Type
,
declarationExpression
.
Designation
));
}
else
if
(
node
is
SingleVariableDesignationSyntax
{
Parent
:
not
DeclarationPatternSyntax
and
not
DeclarationExpressionSyntax
}
variableDesignation
)
{
var
local
=
semanticModel
.
GetDeclaredSymbol
(
variableDesignation
,
cancellationToken
)
as
ILocalSymbol
;
var
type
=
local
?.
Type
;
...
...
@@ -53,8 +58,7 @@ public CSharpInlineTypeHintsService()
:
(
type
,
new
TextSpan
(
variableDesignation
.
Identifier
.
SpanStart
,
0
));
}
}
else
if
(
node
is
ForEachStatementSyntax
forEachStatement
&&
forEachStatement
.
Type
.
IsVar
)
else
if
(
node
is
ForEachStatementSyntax
{
Type
:
{
IsVar
:
true
}
}
forEachStatement
)
{
var
info
=
semanticModel
.
GetForEachStatementInfo
(
forEachStatement
);
var
type
=
info
.
ElementType
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录