Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
5c4d5c29
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,发现更多精彩内容 >>
提交
5c4d5c29
编写于
4月 02, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move extension method
上级
ff3d2a75
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
44 addition
and
40 deletion
+44
-40
src/Workspaces/Core/Portable/FindSymbols/Extensions.cs
src/Workspaces/Core/Portable/FindSymbols/Extensions.cs
+0
-29
src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferenceCache.cs
...Portable/FindSymbols/FindReferences/FindReferenceCache.cs
+13
-7
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs
...Symbols/FindReferences/Finders/AbstractReferenceFinder.cs
+25
-1
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ConstructorInitializerSymbolReferenceFinder.cs
...es/Finders/ConstructorInitializerSymbolReferenceFinder.cs
+2
-1
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamespaceSymbolReferenceFinder.cs
.../FindReferences/Finders/NamespaceSymbolReferenceFinder.cs
+4
-2
未找到文件。
src/Workspaces/Core/Portable/FindSymbols/Extensions.cs
浏览文件 @
5c4d5c29
...
...
@@ -28,35 +28,6 @@ public static async Task<IEnumerable<SyntaxToken>> GetConstructorInitializerToke
return
FindReferenceCache
.
GetConstructorInitializerTokens
(
syntaxFacts
,
model
,
root
,
cancellationToken
);
}
internal
static
async
Task
<
ImmutableArray
<
SyntaxToken
>>
GetIdentifierOrGlobalNamespaceTokensWithTextAsync
(
this
Document
document
,
SemanticModel
model
,
string
identifier
,
CancellationToken
cancellationToken
)
{
// It's very costly to walk an entire tree. So if the tree is simple and doesn't contain
// any unicode escapes in it, then we do simple string matching to find the tokens.
var
info
=
await
SyntaxTreeIndex
.
GetIndexAsync
(
document
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(!
info
.
ProbablyContainsIdentifier
(
identifier
))
{
return
ImmutableArray
<
SyntaxToken
>.
Empty
;
}
var
syntaxFacts
=
document
.
GetLanguageService
<
ISyntaxFactsService
>();
if
(
syntaxFacts
==
null
)
{
return
ImmutableArray
<
SyntaxToken
>.
Empty
;
}
var
root
=
await
model
.
SyntaxTree
.
GetRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
version
=
await
document
.
GetSyntaxVersionAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
SourceText
text
=
null
;
if
(!
info
.
ProbablyContainsEscapedIdentifier
(
identifier
))
{
text
=
await
document
.
GetTextAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
}
return
FindReferenceCache
.
GetIdentifierOrGlobalNamespaceTokensWithText
(
syntaxFacts
,
document
,
version
,
model
,
root
,
text
,
identifier
,
cancellationToken
);
}
internal
static
bool
TextMatch
(
this
ISyntaxFactsService
syntaxFacts
,
string
text1
,
string
text2
)
=>
syntaxFacts
.
StringComparer
.
Equals
(
text1
,
text2
);
}
...
...
src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferenceCache.cs
浏览文件 @
5c4d5c29
...
...
@@ -62,8 +62,14 @@ public static SymbolInfo GetSymbolInfo(SemanticModel model, SyntaxNode node, Can
}
public
static
ImmutableArray
<
SyntaxToken
>
GetIdentifierOrGlobalNamespaceTokensWithText
(
ISyntaxFactsService
syntaxFacts
,
Document
document
,
VersionStamp
version
,
SemanticModel
model
,
SyntaxNode
root
,
SourceText
sourceText
,
string
text
,
CancellationToken
cancellationToken
)
ISyntaxFactsService
syntaxFacts
,
Document
document
,
VersionStamp
version
,
SemanticModel
model
,
SyntaxNode
root
,
SourceText
sourceText
,
string
text
,
CancellationToken
cancellationToken
)
{
var
normalized
=
syntaxFacts
.
IsCaseSensitive
?
text
:
text
.
ToLowerInvariant
();
...
...
@@ -82,17 +88,17 @@ public static SymbolInfo GetSymbolInfo(SemanticModel model, SyntaxNode node, Can
ISyntaxFactsService
syntaxFacts
,
Document
document
,
VersionStamp
version
,
SyntaxNode
root
,
SourceText
sourceText
,
string
text
,
CancellationToken
cancellationToken
)
{
bool
candidate
(
SyntaxToken
t
)
=>
syntaxFacts
.
IsGlobalNamespaceKeyword
(
t
)
||
(
syntaxFacts
.
IsIdentifier
(
t
)
&&
syntaxFacts
.
TextMatch
(
t
.
ValueText
,
text
));
// identifier is not escaped
if
(
sourceText
!=
null
)
{
return
GetTokensFromText
(
syntaxFacts
,
document
,
version
,
root
,
sourceText
,
text
,
c
andidate
,
cancellationToken
);
return
GetTokensFromText
(
syntaxFacts
,
document
,
version
,
root
,
sourceText
,
text
,
IsC
andidate
,
cancellationToken
);
}
// identifier is escaped
return
root
.
DescendantTokens
(
descendIntoTrivia
:
true
).
Where
(
candidate
).
ToImmutableArray
();
return
root
.
DescendantTokens
(
descendIntoTrivia
:
true
).
Where
(
IsCandidate
).
ToImmutableArray
();
bool
IsCandidate
(
SyntaxToken
t
)
=>
syntaxFacts
.
IsGlobalNamespaceKeyword
(
t
)
||
(
syntaxFacts
.
IsIdentifier
(
t
)
&&
syntaxFacts
.
TextMatch
(
t
.
ValueText
,
text
));
}
private
static
ImmutableArray
<
SyntaxToken
>
GetTokensFromText
(
...
...
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs
浏览文件 @
5c4d5c29
...
...
@@ -14,6 +14,7 @@
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Shared.Utilities
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.FindSymbols.Finders
...
...
@@ -167,7 +168,7 @@ protected static bool IdentifiersMatch(ISyntaxFactsService syntaxFacts, string n
Func
<
SyntaxToken
,
SemanticModel
,
(
bool
matched
,
CandidateReason
reason
)>
symbolsMatch
,
CancellationToken
cancellationToken
)
{
var
tokens
=
await
document
.
GetIdentifierOrGlobalNamespaceTokensWithTextAsync
(
semanticModel
,
identifier
,
cancellationToken
).
ConfigureAwait
(
false
);
var
tokens
=
await
GetIdentifierOrGlobalNamespaceTokensWithTextAsync
(
document
,
semanticModel
,
identifier
,
cancellationToken
).
ConfigureAwait
(
false
);
var
syntaxFacts
=
document
.
GetLanguageService
<
ISyntaxFactsService
>();
...
...
@@ -180,6 +181,29 @@ protected static bool IdentifiersMatch(ISyntaxFactsService syntaxFacts, string n
cancellationToken
);
}
protected
static
async
Task
<
ImmutableArray
<
SyntaxToken
>>
GetIdentifierOrGlobalNamespaceTokensWithTextAsync
(
Document
document
,
SemanticModel
semanticModel
,
string
identifier
,
CancellationToken
cancellationToken
)
{
// It's very costly to walk an entire tree. So if the tree is simple and doesn't contain
// any unicode escapes in it, then we do simple string matching to find the tokens.
var
info
=
await
SyntaxTreeIndex
.
GetIndexAsync
(
document
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(!
info
.
ProbablyContainsIdentifier
(
identifier
))
return
ImmutableArray
<
SyntaxToken
>.
Empty
;
var
syntaxFacts
=
document
.
GetLanguageService
<
ISyntaxFactsService
>();
if
(
syntaxFacts
==
null
)
return
ImmutableArray
<
SyntaxToken
>.
Empty
;
var
root
=
await
semanticModel
.
SyntaxTree
.
GetRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
version
=
await
document
.
GetSyntaxVersionAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
SourceText
text
=
null
;
if
(!
info
.
ProbablyContainsEscapedIdentifier
(
identifier
))
text
=
await
document
.
GetTextAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
return
FindReferenceCache
.
GetIdentifierOrGlobalNamespaceTokensWithText
(
syntaxFacts
,
document
,
version
,
semanticModel
,
root
,
text
,
identifier
,
cancellationToken
);
}
protected
static
Func
<
SyntaxToken
,
SemanticModel
,
(
bool
matched
,
CandidateReason
reason
)>
GetStandardSymbolsMatchFunction
(
ISymbol
symbol
,
Func
<
SyntaxToken
,
SyntaxNode
>
findParentNode
,
Solution
solution
,
CancellationToken
cancellationToken
)
{
...
...
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ConstructorInitializerSymbolReferenceFinder.cs
浏览文件 @
5c4d5c29
...
...
@@ -62,7 +62,8 @@ protected override bool CanFind(IMethodSymbol symbol)
var
tokens
=
await
document
.
GetConstructorInitializerTokensAsync
(
semanticModel
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
semanticModel
.
Language
==
LanguageNames
.
VisualBasic
)
{
tokens
=
tokens
.
Concat
(
await
document
.
GetIdentifierOrGlobalNamespaceTokensWithTextAsync
(
semanticModel
,
"New"
,
cancellationToken
).
ConfigureAwait
(
false
)).
Distinct
();
tokens
=
tokens
.
Concat
(
await
GetIdentifierOrGlobalNamespaceTokensWithTextAsync
(
document
,
semanticModel
,
"New"
,
cancellationToken
).
ConfigureAwait
(
false
)).
Distinct
();
}
return
FindReferencesInTokens
(
...
...
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamespaceSymbolReferenceFinder.cs
浏览文件 @
5c4d5c29
...
...
@@ -44,11 +44,13 @@ private static string GetNamespaceIdentifierName(INamespaceSymbol symbol)
var
identifierName
=
GetNamespaceIdentifierName
(
symbol
);
var
syntaxFactsService
=
document
.
GetLanguageService
<
ISyntaxFactsService
>();
var
tokens
=
await
GetIdentifierOrGlobalNamespaceTokensWithTextAsync
(
document
,
semanticModel
,
identifierName
,
cancellationToken
).
ConfigureAwait
(
false
);
var
nonAliasReferences
=
FindReferencesInTokens
(
symbol
,
document
,
semanticModel
,
await
document
.
GetIdentifierOrGlobalNamespaceTokensWithTextAsync
(
semanticModel
,
identifierName
,
cancellationToken
).
ConfigureAwait
(
false
)
,
(
SyntaxToken
t
)
=>
syntaxFactsService
.
TextMatch
(
t
.
ValueText
,
identifierName
),
tokens
,
t
=>
syntaxFactsService
.
TextMatch
(
t
.
ValueText
,
identifierName
),
cancellationToken
);
var
aliasReferences
=
await
FindAliasReferencesAsync
(
nonAliasReferences
,
symbol
,
document
,
semanticModel
,
cancellationToken
).
ConfigureAwait
(
false
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录