Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
5025f6b0
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,发现更多精彩内容 >>
提交
5025f6b0
编写于
7月 25, 2016
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'symbolNavigation' into asyncFindRefs2
上级
9131fe45
a540462b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
52 addition
and
30 deletion
+52
-30
src/Features/Core/Portable/FindReferences/DefinitionLocation.SymbolDefinitionLocation.cs
...References/DefinitionLocation.SymbolDefinitionLocation.cs
+29
-13
src/Features/Core/Portable/FindReferences/DefinitionLocation.cs
...atures/Core/Portable/FindReferences/DefinitionLocation.cs
+2
-2
src/Features/Core/Portable/FindReferences/IDefinitionsAndReferencesFactory.cs
...rtable/FindReferences/IDefinitionsAndReferencesFactory.cs
+4
-10
src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentProjectsFinder.cs
...ble/FindSymbols/FindReferences/DependentProjectsFinder.cs
+17
-5
未找到文件。
src/Features/Core/Portable/FindReferences/DefinitionLocation.SymbolDefinitionLocation.cs
浏览文件 @
5025f6b0
...
...
@@ -2,7 +2,9 @@
using
System
;
using
System.Collections.Immutable
;
using
System.Linq
;
using
System.Threading
;
using
Microsoft.CodeAnalysis.FindSymbols
;
using
Microsoft.CodeAnalysis.Navigation
;
using
Roslyn.Utilities
;
...
...
@@ -20,15 +22,15 @@ internal partial class DefinitionLocation
private
sealed
class
SymbolDefinitionLocation
:
DefinitionLocation
{
private
readonly
Workspace
_workspace
;
private
readonly
ProjectId
_referencingProjectId
;
private
readonly
SymbolKey
_symbolKey
;
private
readonly
string
_symbolAssemblyName
;
private
readonly
ImmutableArray
<
TaggedText
>
_originationParts
;
public
SymbolDefinitionLocation
(
ISymbol
definition
,
Project
project
)
public
SymbolDefinitionLocation
(
Solution
solution
,
ISymbol
definition
)
{
_workspace
=
project
.
Solution
.
Workspace
;
_referencingProjectId
=
project
.
Id
;
_workspace
=
solution
.
Workspace
;
_symbolKey
=
definition
.
GetSymbolKey
();
_symbolAssemblyName
=
definition
.
ContainingAssembly
?.
Name
;
_originationParts
=
GetOriginationParts
(
definition
);
}
...
...
@@ -47,9 +49,15 @@ public override bool TryNavigateTo()
private
bool
TryNavigateTo
(
Func
<
ISymbol
,
Project
,
ISymbolNavigationService
,
bool
>
action
)
{
var
symbol
=
ResolveSymbolInCurrentSolution
();
var
referencingProject
=
_workspace
.
CurrentSolution
.
GetProject
(
_referencingProjectId
);
if
(
symbol
==
null
||
referencingProject
==
null
)
var
projectAndSymbol
=
ResolveSymbolInCurrentSolution
();
if
(
projectAndSymbol
==
null
)
{
return
false
;
}
var
project
=
projectAndSymbol
.
Value
.
Item1
;
var
symbol
=
projectAndSymbol
.
Value
.
Item2
;
if
(
symbol
==
null
||
project
==
null
)
{
return
false
;
}
...
...
@@ -60,15 +68,23 @@ private bool TryNavigateTo(Func<ISymbol, Project, ISymbolNavigationService, bool
}
var
navigationService
=
_workspace
.
Services
.
GetService
<
ISymbolNavigationService
>();
return
action
(
symbol
,
referencingP
roject
,
navigationService
);
return
action
(
symbol
,
p
roject
,
navigationService
);
}
private
ISymbol
ResolveSymbolInCurrentSolution
()
private
ValueTuple
<
Project
,
ISymbol
>?
ResolveSymbolInCurrentSolution
()
{
var
compilation
=
_workspace
.
CurrentSolution
.
GetProject
(
_referencingProjectId
)
.
GetCompilationAsync
(
CancellationToken
.
None
)
.
WaitAndGetResult
(
CancellationToken
.
None
);
return
_symbolKey
.
Resolve
(
compilation
).
Symbol
;
var
project
=
_workspace
.
CurrentSolution
.
Projects
.
FirstOrDefault
(
p
=>
p
.
HasReferenceToAssembly
(
_symbolAssemblyName
));
if
(
project
==
null
)
{
return
null
;
}
var
compilation
=
project
.
GetCompilationAsync
(
CancellationToken
.
None
)
.
WaitAndGetResult
(
CancellationToken
.
None
);
return
ValueTuple
.
Create
(
project
,
_symbolKey
.
Resolve
(
compilation
).
Symbol
);
}
}
}
...
...
src/Features/Core/Portable/FindReferences/DefinitionLocation.cs
浏览文件 @
5025f6b0
...
...
@@ -34,9 +34,9 @@ public static DefinitionLocation CreateDocumentLocation(DocumentLocation locatio
return
new
DocumentDefinitionLocation
(
location
);
}
public
static
DefinitionLocation
CreateSymbolLocation
(
ISymbol
symbol
,
Project
referencingProject
)
public
static
DefinitionLocation
CreateSymbolLocation
(
Solution
solution
,
ISymbol
symbol
)
{
return
new
SymbolDefinitionLocation
(
s
ymbol
,
referencingProject
);
return
new
SymbolDefinitionLocation
(
s
olution
,
symbol
);
}
public
static
DefinitionLocation
CreateNonNavigatingLocation
(
...
...
src/Features/Core/Portable/FindReferences/IDefinitionsAndReferencesFactory.cs
浏览文件 @
5025f6b0
...
...
@@ -132,7 +132,7 @@ private static int GetPrecedence(ReferencedSymbol referencedSymbol)
{
var
definition
=
referencedSymbol
.
Definition
;
var
definitionLocations
=
Convert
Locations
(
solution
,
referencedSymbol
);
var
definitionLocations
=
Convert
DefinitionLocations
(
solution
,
definition
);
var
displayParts
=
definition
.
ToDisplayParts
(
s_definitionDisplayFormat
).
ToTaggedText
();
return
new
DefinitionItem
(
...
...
@@ -142,10 +142,9 @@ private static int GetPrecedence(ReferencedSymbol referencedSymbol)
definition
.
ShouldShowWithNoReferenceLocations
());
}
private
static
ImmutableArray
<
DefinitionLocation
>
ConvertLocations
(
Solution
solution
,
ReferencedSymbol
referencedSymbol
)
private
static
ImmutableArray
<
DefinitionLocation
>
Convert
Definition
Locations
(
Solution
solution
,
ISymbol
definition
)
{
var
definition
=
referencedSymbol
.
Definition
;
var
result
=
ImmutableArray
.
CreateBuilder
<
DefinitionLocation
>();
// If it's a namespace, don't create any normal lcoation. Namespaces
...
...
@@ -157,12 +156,7 @@ private static int GetPrecedence(ReferencedSymbol referencedSymbol)
{
if
(
location
.
IsInMetadata
)
{
var
firstSourceReferenceLocation
=
referencedSymbol
.
Locations
.
FirstOrNullable
();
if
(
firstSourceReferenceLocation
!=
null
)
{
result
.
Add
(
DefinitionLocation
.
CreateSymbolLocation
(
definition
,
firstSourceReferenceLocation
.
Value
.
Document
.
Project
));
}
result
.
Add
(
DefinitionLocation
.
CreateSymbolLocation
(
solution
,
definition
));
}
else
if
(
location
.
IsInSource
)
{
...
...
src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentProjectsFinder.cs
浏览文件 @
5025f6b0
...
...
@@ -399,6 +399,16 @@ private static bool HasReferenceTo(IAssemblySymbol containingAssembly, Project s
return
project
.
ProjectReferences
.
Any
(
p
=>
p
.
ProjectId
==
sourceProject
.
Id
);
}
return
project
.
HasReferenceToAssembly
(
containingAssembly
);
}
public
static
bool
HasReferenceToAssembly
(
this
Project
project
,
IAssemblySymbol
assemblySymbol
)
{
return
project
.
HasReferenceToAssembly
(
assemblySymbol
.
Name
);
}
public
static
bool
HasReferenceToAssembly
(
this
Project
project
,
string
assemblyName
)
{
// If the project we're looking at doesn't even support compilations, then there's no
// way for it to have an IAssemblySymbol. And without that, there is no way for it
// to have any sort of 'ReferenceTo' the provided 'containingAssembly' symbol.
...
...
@@ -408,18 +418,20 @@ private static bool HasReferenceTo(IAssemblySymbol containingAssembly, Project s
}
// WORKAROUND:
// perf check metadata reference using newly created empty compilation with only metadata references.
// perf check metadata reference using newly created empty compilation with only metadata references.
//
// TODO(cyrusn): Why don't we call project.TryGetCompilation first?
// wouldn't we want to use that compilation if it's available?
var
compilation
=
project
.
LanguageServices
.
CompilationFactory
.
CreateCompilation
(
project
.
AssemblyName
,
project
.
CompilationOptions
);
project
.
AssemblyName
,
project
.
CompilationOptions
);
compilation
=
compilation
.
AddReferences
(
project
.
MetadataReferences
);
return
project
.
MetadataReferences
.
Any
(
m
=>
{
var
symbol
=
compilation
.
GetAssemblyOrModuleSymbol
(
m
)
as
IAssemblySymbol
;
return
symbol
!=
null
&&
symbol
.
Name
==
containingAssembly
.
Name
;
return
symbol
!=
null
&&
symbol
.
Name
==
assembly
Name
;
});
}
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录