Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c094c74f
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,发现更多精彩内容 >>
未验证
提交
c094c74f
编写于
4月 10, 2019
作者:
J
Jason Malinowski
提交者:
GitHub
4月 10, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #34861 from jasonmalinowski/cleanups-to-callers-of-get-semantic-info
Cleanups to callers of GetSemanticInfo
上级
b82b0ba1
52365c43
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
103 addition
and
251 deletion
+103
-251
src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs
...ures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs
+6
-0
src/EditorFeatures/Test2/Extensions/ISymbolExtensionsTests.vb
...EditorFeatures/Test2/Extensions/ISymbolExtensionsTests.vb
+2
-5
src/EditorFeatures/Test2/Workspaces/SymbolDescriptionServiceTests.vb
...eatures/Test2/Workspaces/SymbolDescriptionServiceTests.vb
+2
-171
src/EditorFeatures/VisualBasicTest/QuickInfo/SemanticQuickInfoSourceTests.vb
...VisualBasicTest/QuickInfo/SemanticQuickInfoSourceTests.vb
+22
-0
src/Workspaces/Core/Portable/Shared/Extensions/SemanticModelExtensions.cs
...ore/Portable/Shared/Extensions/SemanticModelExtensions.cs
+12
-75
src/Workspaces/Core/Portable/Shared/Extensions/TokenSemanticInfo.cs
...aces/Core/Portable/Shared/Extensions/TokenSemanticInfo.cs
+59
-0
未找到文件。
src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs
浏览文件 @
c094c74f
...
...
@@ -1251,6 +1251,12 @@ public async Task TestNullLiteral()
MainDescription
(
"class System.String"
));
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
QuickInfo
)]
public
async
Task
TestNullLiteralWithVar
()
{
await
TestInMethodAsync
(
@"var f = null$$"
);
}
[
WorkItem
(
26027
,
"https://github.com/dotnet/roslyn/issues/26027"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
QuickInfo
)]
public
async
Task
TestDefaultLiteral
()
...
...
src/EditorFeatures/Test2/Extensions/ISymbolExtensionsTests.vb
浏览文件 @
c094c74f
...
...
@@ -3,6 +3,7 @@
Imports
System.Threading
Imports
System.Threading.Tasks
Imports
Microsoft.CodeAnalysis
Imports
Microsoft.CodeAnalysis.FindSymbols
Namespace
Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
<
[
UseExportProvider
]
>
...
...
@@ -15,12 +16,8 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Dim
cursorPosition
=
cursorDocument
.
CursorPosition
.
Value
Dim
document
=
workspace
.
CurrentSolution
.
GetDocument
(
cursorDocument
.
Id
)
Dim
tree
=
Await
document
.
GetSyntaxTreeAsync
()
Dim
commonSyntaxToken
=
Await
tree
.
GetTouchingTokenAsync
(
cursorPosition
,
Nothing
)
Dim
semanticModel
=
Await
document
.
GetSemanticModelAsync
()
Dim
symbol
=
semanticModel
.
GetSemanticInfo
(
commonSyntaxToken
,
document
.
Project
.
Solution
.
Workspace
,
Nothing
).
GetAnySymbol
(
includeType
:
=
False
)
Dim
symbol
=
Await
SymbolFinder
.
FindSymbolAtPositionAsync
(
document
,
cursorPosition
)
Dim
namedTypeSymbol
=
semanticModel
.
GetEnclosingNamedType
(
cursorPosition
,
CancellationToken
.
None
)
Dim
actualVisible
=
symbol
.
IsAccessibleWithin
(
namedTypeSymbol
)
...
...
src/EditorFeatures/Test2/Workspaces/SymbolDescriptionServiceTests.vb
浏览文件 @
c094c74f
...
...
@@ -3,6 +3,7 @@
Imports
System.Threading
Imports
System.Threading.Tasks
Imports
Microsoft.CodeAnalysis
Imports
Microsoft.CodeAnalysis.FindSymbols
Imports
Microsoft.CodeAnalysis.Host
Imports
Microsoft.CodeAnalysis.LanguageServices
...
...
@@ -19,21 +20,8 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Dim
cursorBuffer
=
cursorDocument
.
TextBuffer
Dim
document
=
workspace
.
CurrentSolution
.
GetDocument
(
cursorDocument
.
Id
)
' using GetTouchingWord instead of FindToken allows us to test scenarios where cursor is at the end of token (E.g: Goo$$)
Dim
tree
=
Await
document
.
GetSyntaxTreeAsync
()
Dim
commonSyntaxToken
=
Await
tree
.
GetTouchingWordAsync
(
cursorPosition
,
languageServiceProvider
.
GetService
(
Of
ISyntaxFactsService
),
Nothing
)
' For String Literals GetTouchingWord returns Nothing, we still need this for Quick Info. Quick Info code does exactly the following.
' caveat: The comment above the previous line of code. Do not put the cursor at the end of the token.
If
commonSyntaxToken
=
Nothing
Then
commonSyntaxToken
=
(
Await
document
.
GetSyntaxRootAsync
()).
FindToken
(
cursorPosition
)
End
If
Dim
semanticModel
=
Await
document
.
GetSemanticModelAsync
()
Dim
symbol
=
semanticModel
.
GetSemanticInfo
(
commonSyntaxToken
,
document
.
Project
.
Solution
.
Workspace
,
CancellationToken
.
None
).
GetSymbols
(
includeType
:
=
True
).
AsImmutable
()
Dim
symbol
=
Await
SymbolFinder
.
FindSymbolAtPositionAsync
(
document
,
cursorPosition
)
Dim
symbolDescriptionService
=
languageServiceProvider
.
GetService
(
Of
ISymbolDisplayService
)()
...
...
@@ -108,44 +96,6 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Await
TestCSharpAsync
(
workspace
,
$
"({FeaturesResources.local_constant}) int x = 2"
)
End
Function
<
Fact
>
Public
Async
Function
TestCSharpNullLiteralVar
()
As
Task
Dim
workspace
=
<
Workspace
>
<
Project
Language
=
"C#"
CommonReferences
=
"true"
>
<
Document
>
class
Goo
{
void
Method
()
{
var
x
=
nu$
$
ll
}
}
</
Document
>
</
Project
>
</
Workspace
>
Await
TestCSharpAsync
(
workspace
,
""
)
End
Function
<
Fact
>
Public
Async
Function
TestCSharpNullLiteralString
()
As
Task
Dim
workspace
=
<
Workspace
>
<
Project
Language
=
"C#"
CommonReferences
=
"true"
>
<
Document
>
class
Goo
{
void
Method
()
{
string
x
=
nu$
$
ll
}
}
</
Document
>
</
Project
>
</
Workspace
>
Await
TestCSharpAsync
(
workspace
,
"class System.String"
)
End
Function
<
Fact
>
Public
Async
Function
TestCSharpStaticField
()
As
Task
Dim
workspace
=
...
...
@@ -649,125 +599,6 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Await
TestBasicAsync
(
workspace
,
$
"({FeaturesResources.local_variable}) x As String"
)
End
Function
<
Fact
>
Public
Async
Function
TestStringLiteral
()
As
Task
Dim
workspace
=
<
Workspace
>
<
Project
Language
=
"Visual Basic"
CommonReferences
=
"true"
>
<
Document
>
Class
Goo
Sub
Method
()
Dim
x
As
String
=
"Hel$$lo"
End
Sub
End
Class
</
Document
>
</
Project
>
</
Workspace
>
Await
TestBasicAsync
(
workspace
,
"Class System.String"
)
End
Function
<
Fact
>
Public
Async
Function
TestIntegerLiteral
()
As
Task
Dim
workspace
=
<
Workspace
>
<
Project
Language
=
"Visual Basic"
CommonReferences
=
"true"
>
<
Document
>
Class
Goo
Sub
Method
()
Dim
x
=
4
$$
2
End
Sub
End
Class
</
Document
>
</
Project
>
</
Workspace
>
Await
TestBasicAsync
(
workspace
,
"Structure System.Int32"
)
End
Function
<
Fact
>
Public
Async
Function
TestDateLiteral
()
As
Task
Dim
workspace
=
<
Workspace
>
<
Project
Language
=
"Visual Basic"
CommonReferences
=
"true"
>
<
Document
>
Class
Goo
Sub
Method
()
Dim
d
As
Date
d
=
#
8
/
23
/
1970
$$
3
:
45
:
39
AM
#
End
Sub
End
Class
</
Document
>
</
Project
>
</
Workspace
>
Await
TestBasicAsync
(
workspace
,
"Structure System.DateTime"
)
End
Function
<
Fact
>
Public
Async
Function
TestNothingLiteralDim
()
As
Task
Dim
workspace
=
<
Workspace
>
<
Project
Language
=
"Visual Basic"
CommonReferences
=
"true"
>
<
Document
>
Class
Goo
Sub
Method
()
Dim
x
=
Nothin
$$
g
End
Sub
End
Class
</
Document
>
</
Project
>
</
Workspace
>
Await
TestBasicAsync
(
workspace
,
"Class System.Object"
)
End
Function
<
Fact
>
Public
Async
Function
TestNothingLiteralDimAsString
()
As
Task
Dim
workspace
=
<
Workspace
>
<
Project
Language
=
"Visual Basic"
CommonReferences
=
"true"
>
<
Document
>
Class
Goo
Sub
Method
()
Dim
x
As
String
=
Nothin
$$
g
End
Sub
End
Class
</
Document
>
</
Project
>
</
Workspace
>
Await
TestBasicAsync
(
workspace
,
"Class System.String"
)
End
Function
<
Fact
>
Public
Async
Function
TestNothingLiteralFieldDimOptionStrict
()
As
Task
Dim
workspace
=
<
Workspace
>
<
Project
Language
=
"Visual Basic"
CommonReferences
=
"true"
>
<
Document
>
Option Strict On
Class
Goo
Dim
x
=
Nothin
$$
g
End
Class
</
Document
>
</
Project
>
</
Workspace
>
Await
TestBasicAsync
(
workspace
,
"Class System.Object"
)
End
Function
<
Fact
>
Public
Async
Function
TestTrueKeyword
()
As
Task
Dim
workspace
=
<
Workspace
>
<
Project
Language
=
"Visual Basic"
CommonReferences
=
"true"
>
<
Document
>
Class
Goo
Sub
Method
()
Dim
x
=
Tr
$$
ue
End
Sub
End
Class
</
Document
>
</
Project
>
</
Workspace
>
Await
TestBasicAsync
(
workspace
,
"Structure System.Boolean"
)
End
Function
<
WorkItem
(
538732
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538732"
)
>
<
Fact
>
Public
Async
Function
TestMethod
()
As
Task
...
...
src/EditorFeatures/VisualBasicTest/QuickInfo/SemanticQuickInfoSourceTests.vb
浏览文件 @
c094c74f
...
...
@@ -1751,6 +1751,12 @@ End Class]]></text>.NormalizedValue(),
MainDescription
(
"Structure System.Int32"
))
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
QuickInfo
)
>
Public
Async
Function
TestDateLiteral
()
As
Task
Await
TestInMethodAsync
(
"Dim f = #8/23/1970 $$3:45:39 AM#"
,
MainDescription
(
"Structure System.DateTime"
))
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
QuickInfo
)
>
Public
Async
Function
TestTrueKeyword
()
As
Task
Await
TestInMethodAsync
(
"Dim f = True$$"
,
...
...
@@ -1770,6 +1776,22 @@ End Class]]></text>.NormalizedValue(),
MainDescription
(
"Class System.String"
))
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
QuickInfo
)
>
Public
Async
Function
TestNothingLiteralWithNoType
()
As
Task
Await
TestInMethodAsync
(
"Dim f = Nothing$$"
,
MainDescription
(
"Class System.Object"
))
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
QuickInfo
)
>
Public
Async
Function
TestNothingLiteralFieldDimOptionStrict
()
As
Task
Await
TestAsync
(
"
Option Strict On
Class C
Dim f = Nothing$$
End Class"
,
MainDescription
(
"Class System.Object"
))
End
Function
''' <Remarks>
''' As a part of fix for 756226, quick info for VB Await keyword now displays the type inferred from the AwaitExpression. This is C# behavior.
''' In Dev12, quick info for VB Await keyword was the syntactic help "Await <expression>".
...
...
src/Workspaces/Core/Portable/Shared/Extensions/SemanticModelExtensions.cs
浏览文件 @
c094c74f
...
...
@@ -6,62 +6,11 @@
using
System.Threading
;
using
Microsoft.CodeAnalysis.LanguageServices
;
using
Microsoft.CodeAnalysis.Operations
;
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.Shared.Utilities
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Shared.Extensions
{
internal
struct
TokenSemanticInfo
{
public
static
readonly
TokenSemanticInfo
Empty
=
new
TokenSemanticInfo
(
null
,
null
,
ImmutableArray
<
ISymbol
>.
Empty
,
null
,
null
,
default
(
TextSpan
));
public
readonly
ISymbol
DeclaredSymbol
;
public
readonly
IAliasSymbol
AliasSymbol
;
public
readonly
ImmutableArray
<
ISymbol
>
ReferencedSymbols
;
public
readonly
ITypeSymbol
Type
;
public
readonly
ITypeSymbol
ConvertedType
;
public
readonly
TextSpan
Span
;
public
TokenSemanticInfo
(
ISymbol
declaredSymbol
,
IAliasSymbol
aliasSymbol
,
ImmutableArray
<
ISymbol
>
referencedSymbols
,
ITypeSymbol
type
,
ITypeSymbol
convertedType
,
TextSpan
span
)
{
DeclaredSymbol
=
declaredSymbol
;
AliasSymbol
=
aliasSymbol
;
ReferencedSymbols
=
referencedSymbols
;
Type
=
type
;
ConvertedType
=
convertedType
;
Span
=
span
;
}
public
ImmutableArray
<
ISymbol
>
GetSymbols
(
bool
includeType
)
{
var
result
=
ArrayBuilder
<
ISymbol
>.
GetInstance
();
result
.
AddIfNotNull
(
DeclaredSymbol
);
result
.
AddIfNotNull
(
AliasSymbol
);
result
.
AddRange
(
ReferencedSymbols
);
if
(
includeType
)
{
result
.
AddIfNotNull
(
Type
??
ConvertedType
);
}
return
result
.
ToImmutableAndFree
();
}
public
ISymbol
GetAnySymbol
(
bool
includeType
)
{
return
GetSymbols
(
includeType
).
FirstOrDefault
();
}
}
internal
static
class
SemanticModelExtensions
{
public
static
SemanticMap
GetSemanticMap
(
this
SemanticModel
semanticModel
,
SyntaxNode
node
,
CancellationToken
cancellationToken
)
...
...
@@ -124,26 +73,6 @@ public static INamespaceSymbol GetEnclosingNamespace(this SemanticModel semantic
return
typeInfo
.
Type
??
symbolInfo
.
GetAnySymbol
().
ConvertToType
(
semanticModel
.
Compilation
);
}
public
static
TokenSemanticInfo
GetSemanticInfo
(
this
SemanticModel
semanticModel
,
SyntaxToken
token
,
Workspace
workspace
,
CancellationToken
cancellationToken
)
{
var
languageServices
=
workspace
.
Services
.
GetLanguageServices
(
token
.
Language
);
var
syntaxFacts
=
languageServices
.
GetService
<
ISyntaxFactsService
>();
if
(!
syntaxFacts
.
IsBindableToken
(
token
))
{
return
TokenSemanticInfo
.
Empty
;
}
var
semanticFacts
=
languageServices
.
GetService
<
ISemanticFactsService
>();
return
GetSemanticInfo
(
semanticModel
,
semanticFacts
,
syntaxFacts
,
token
,
cancellationToken
);
}
private
static
ISymbol
MapSymbol
(
ISymbol
symbol
,
ITypeSymbol
type
)
{
if
(
symbol
.
IsConstructor
()
&&
symbol
.
ContainingType
.
IsAnonymousType
)
...
...
@@ -192,13 +121,21 @@ private static ISymbol MapSymbol(ISymbol symbol, ITypeSymbol type)
return
symbol
;
}
private
static
TokenSemanticInfo
GetSemanticInfo
(
SemanticModel
semanticModel
,
ISemanticFactsService
semanticFacts
,
ISyntaxFactsService
syntaxFacts
,
public
static
TokenSemanticInfo
GetSemanticInfo
(
this
SemanticModel
semanticModel
,
SyntaxToken
token
,
Workspace
workspace
,
CancellationToken
cancellationToken
)
{
var
languageServices
=
workspace
.
Services
.
GetLanguageServices
(
token
.
Language
);
var
syntaxFacts
=
languageServices
.
GetService
<
ISyntaxFactsService
>();
if
(!
syntaxFacts
.
IsBindableToken
(
token
))
{
return
TokenSemanticInfo
.
Empty
;
}
var
semanticFacts
=
languageServices
.
GetService
<
ISemanticFactsService
>();
IAliasSymbol
aliasSymbol
;
ITypeSymbol
type
;
ITypeSymbol
convertedType
;
...
...
src/Workspaces/Core/Portable/Shared/Extensions/TokenSemanticInfo.cs
0 → 100644
浏览文件 @
c094c74f
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System.Collections.Immutable
;
using
System.Linq
;
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Shared.Extensions
{
internal
struct
TokenSemanticInfo
{
public
static
readonly
TokenSemanticInfo
Empty
=
new
TokenSemanticInfo
(
null
,
null
,
ImmutableArray
<
ISymbol
>.
Empty
,
null
,
null
,
default
(
TextSpan
));
public
readonly
ISymbol
DeclaredSymbol
;
public
readonly
IAliasSymbol
AliasSymbol
;
public
readonly
ImmutableArray
<
ISymbol
>
ReferencedSymbols
;
public
readonly
ITypeSymbol
Type
;
public
readonly
ITypeSymbol
ConvertedType
;
public
readonly
TextSpan
Span
;
public
TokenSemanticInfo
(
ISymbol
declaredSymbol
,
IAliasSymbol
aliasSymbol
,
ImmutableArray
<
ISymbol
>
referencedSymbols
,
ITypeSymbol
type
,
ITypeSymbol
convertedType
,
TextSpan
span
)
{
DeclaredSymbol
=
declaredSymbol
;
AliasSymbol
=
aliasSymbol
;
ReferencedSymbols
=
referencedSymbols
;
Type
=
type
;
ConvertedType
=
convertedType
;
Span
=
span
;
}
public
ImmutableArray
<
ISymbol
>
GetSymbols
(
bool
includeType
)
{
var
result
=
ArrayBuilder
<
ISymbol
>.
GetInstance
();
result
.
AddIfNotNull
(
DeclaredSymbol
);
result
.
AddIfNotNull
(
AliasSymbol
);
result
.
AddRange
(
ReferencedSymbols
);
if
(
includeType
)
{
result
.
AddIfNotNull
(
Type
??
ConvertedType
);
}
return
result
.
ToImmutableAndFree
();
}
public
ISymbol
GetAnySymbol
(
bool
includeType
)
{
return
GetSymbols
(
includeType
).
FirstOrDefault
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录