Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
2cdfd456
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,发现更多精彩内容 >>
提交
2cdfd456
编写于
4月 21, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for cref-type-parameters.
上级
e90cf291
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
65 addition
and
35 deletion
+65
-35
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.BodyLevelSymbolKey.cs
...s/Core/Portable/SymbolKey/SymbolKey.BodyLevelSymbolKey.cs
+6
-23
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.SymbolKeyReader.cs
...aces/Core/Portable/SymbolKey/SymbolKey.SymbolKeyReader.cs
+19
-1
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.TypeParameterSymbolKey.cs
...re/Portable/SymbolKey/SymbolKey.TypeParameterSymbolKey.cs
+31
-11
src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.SymbolToProjectId.cs
...ble/Workspace/Solution/SolutionState.SymbolToProjectId.cs
+9
-0
未找到文件。
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.BodyLevelSymbolKey.cs
浏览文件 @
2cdfd456
...
...
@@ -4,7 +4,7 @@
using
System.Collections.Generic
;
using
System.Threading
;
using
Microsoft.CodeAnalysis.
Text
;
using
Microsoft.CodeAnalysis.
Shared.Extensions
;
namespace
Microsoft.CodeAnalysis
{
...
...
@@ -34,13 +34,11 @@ public static void Create(ISymbol symbol, SymbolKeyWriter visitor)
// locals in VB can't be found using GetDeclaredSymbol. For those, we store the actual local span and
// use GetSymbolInfo to find it.
var
ordinal
=
GetOrdinal
();
var
span
=
symbol
.
Locations
[
0
].
SourceSpan
;
visitor
.
WriteString
(
localName
);
visitor
.
WriteSymbolKey
(
containingSymbol
);
visitor
.
WriteInteger
(
ordinal
);
visitor
.
WriteInteger
(
span
.
Start
);
visitor
.
WriteInteger
(
span
.
Length
);
visitor
.
WriteLocation
(
symbol
.
Locations
[
0
]);
visitor
.
WriteInteger
((
int
)
kind
);
return
;
...
...
@@ -64,8 +62,7 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
var
localName
=
reader
.
ReadString
();
var
containingSymbolResolution
=
reader
.
ReadSymbolKey
();
var
ordinal
=
reader
.
ReadInteger
();
var
spanStart
=
reader
.
ReadInteger
();
var
spanLength
=
reader
.
ReadInteger
();
var
location
=
reader
.
ReadLocation
();
var
kind
=
(
SymbolKind
)
reader
.
ReadInteger
();
var
containingSymbol
=
containingSymbolResolution
.
Symbol
;
...
...
@@ -81,23 +78,9 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
}
else
{
var
span
=
new
TextSpan
(
spanStart
,
spanLength
);
foreach
(
var
containerRef
in
containingSymbol
.
DeclaringSyntaxReferences
)
{
var
containerNode
=
containerRef
.
GetSyntax
(
cancellationToken
);
if
(
containerNode
.
Parent
.
Span
.
Contains
(
span
))
{
var
syntaxTree
=
containerRef
.
SyntaxTree
;
var
node
=
syntaxTree
.
GetRoot
(
cancellationToken
).
FindNode
(
span
,
getInnermostNodeForTie
:
true
);
var
semanticModel
=
reader
.
Compilation
.
GetSemanticModel
(
syntaxTree
);
var
info
=
semanticModel
.
GetSymbolInfo
(
node
,
cancellationToken
);
if
(
info
.
Symbol
!=
null
)
return
new
SymbolKeyResolution
(
info
.
Symbol
);
if
(
info
.
CandidateSymbols
.
Length
>
0
)
return
new
SymbolKeyResolution
(
info
.
CandidateSymbols
,
info
.
CandidateReason
);
}
}
var
resolution
=
reader
.
ResolveLocation
(
location
);
if
(
resolution
!=
null
)
return
resolution
.
Value
;
}
}
...
...
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.SymbolKeyReader.cs
浏览文件 @
2cdfd456
...
...
@@ -9,6 +9,7 @@
using
System.Text
;
using
System.Threading
;
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Shared.Utilities
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
...
...
@@ -445,7 +446,7 @@ private SymbolKeyResolution ReadWorker(SymbolKeyType type)
/// will either be the same as the original amount written, or <c>default</c> will be
/// returned. It will never be less or more. <c>default</c> will be returned if any
/// elements could not be resolved to the requested <typeparamref name="TSymbol"/> type
/// in the provided <see cref="Compilation"/>.
/// in the provided <see cref="
SymbolKeyReader.
Compilation"/>.
///
/// Callers should <see cref="IDisposable.Dispose"/> the instance returned. No check is
/// necessary if <c>default</c> was returned before calling <see cref="IDisposable.Dispose"/>
...
...
@@ -545,6 +546,23 @@ public Location ReadLocation()
return
Location
.
None
;
}
public
SymbolKeyResolution
?
ResolveLocation
(
Location
location
)
{
if
(
location
.
SourceTree
!=
null
)
{
var
node
=
location
.
FindNode
(
findInsideTrivia
:
true
,
getInnermostNodeForTie
:
true
,
CancellationToken
);
var
semanticModel
=
Compilation
.
GetSemanticModel
(
location
.
SourceTree
);
var
info
=
semanticModel
.
GetSymbolInfo
(
node
,
CancellationToken
);
if
(
info
.
Symbol
!=
null
)
return
new
SymbolKeyResolution
(
info
.
Symbol
);
if
(
info
.
CandidateSymbols
.
Length
>
0
)
return
new
SymbolKeyResolution
(
info
.
CandidateSymbols
,
info
.
CandidateReason
);
}
return
null
;
}
private
IModuleSymbol
GetModule
(
IEnumerable
<
IModuleSymbol
>
modules
,
string
moduleName
)
{
foreach
(
var
module
in
modules
)
...
...
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.TypeParameterSymbolKey.cs
浏览文件 @
2cdfd456
...
...
@@ -12,28 +12,48 @@ private static class TypeParameterSymbolKey
{
public
static
void
Create
(
ITypeParameterSymbol
symbol
,
SymbolKeyWriter
visitor
)
{
visitor
.
WriteString
(
symbol
.
MetadataName
);
visitor
.
WriteSymbolKey
(
symbol
.
ContainingSymbol
);
if
(
symbol
.
TypeParameterKind
==
TypeParameterKind
.
Cref
)
{
visitor
.
WriteBoolean
(
true
);
visitor
.
WriteLocation
(
symbol
.
Locations
[
0
]);
}
else
{
visitor
.
WriteBoolean
(
false
);
visitor
.
WriteString
(
symbol
.
MetadataName
);
visitor
.
WriteSymbolKey
(
symbol
.
ContainingSymbol
);
}
}
public
static
SymbolKeyResolution
Resolve
(
SymbolKeyReader
reader
)
{
var
metadataName
=
reader
.
ReadString
();
var
containingSymbolResolution
=
reader
.
ReadSymbolKey
();
var
isCref
=
reader
.
ReadBoolean
();
using
var
result
=
PooledArrayBuilder
<
ITypeParameterSymbol
>.
GetInstance
();
foreach
(
var
containingSymbol
in
containingSymbolResolution
)
if
(
isCref
)
{
foreach
(
var
typeParam
in
containingSymbol
.
GetTypeParameters
())
var
location
=
reader
.
ReadLocation
();
var
resolution
=
reader
.
ResolveLocation
(
location
);
return
resolution
.
GetValueOrDefault
();
}
else
{
var
metadataName
=
reader
.
ReadString
();
var
containingSymbolResolution
=
reader
.
ReadSymbolKey
();
using
var
result
=
PooledArrayBuilder
<
ITypeParameterSymbol
>.
GetInstance
();
foreach
(
var
containingSymbol
in
containingSymbolResolution
)
{
if
(
typeParam
.
MetadataName
==
metadataName
)
foreach
(
var
typeParam
in
containingSymbol
.
GetTypeParameters
()
)
{
result
.
AddIfNotNull
(
typeParam
);
if
(
typeParam
.
MetadataName
==
metadataName
)
{
result
.
AddIfNotNull
(
typeParam
);
}
}
}
}
return
CreateResolution
(
result
);
return
CreateResolution
(
result
);
}
}
}
}
...
...
src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.SymbolToProjectId.cs
浏览文件 @
2cdfd456
...
...
@@ -87,6 +87,15 @@ internal partial class SolutionState
}
}
}
else
if
(
symbol
.
IsKind
(
SymbolKind
.
TypeParameter
,
out
ITypeParameterSymbol
?
typeParameter
)
&&
typeParameter
.
TypeParameterKind
==
TypeParameterKind
.
Cref
)
{
// Cref type parameters don't belong to any containing symbol. But we can map them to a doc/project
// using the declaring syntax of the type parameter itself.
var
tree
=
typeParameter
.
Locations
[
0
].
SourceTree
;
var
doc
=
this
.
GetDocumentState
(
tree
,
projectId
:
null
);
return
doc
?.
Id
.
ProjectId
;
}
return
null
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录