Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
de1b70df
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,发现更多精彩内容 >>
提交
de1b70df
编写于
4月 18, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Release resources after a query is executed.
上级
1c77d9c0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
105 addition
and
74 deletion
+105
-74
src/Features/Core/Portable/AddImport/SearchScopes/SearchScope.cs
...tures/Core/Portable/AddImport/SearchScopes/SearchScope.cs
+23
-21
src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs
...bols/Declarations/DeclarationFinder_SourceDeclarations.cs
+42
-35
src/Workspaces/Core/Portable/FindSymbols/SearchQuery.cs
src/Workspaces/Core/Portable/FindSymbols/SearchQuery.cs
+10
-3
src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_AllDeclarations.cs
.../FindSymbols/SymbolFinder_Declarations_AllDeclarations.cs
+12
-6
src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_CustomQueries.cs
...le/FindSymbols/SymbolFinder_Declarations_CustomQueries.cs
+12
-6
src/Workspaces/Remote/ServiceHub/Services/CodeAnalysisService_SymbolFinder.cs
...e/ServiceHub/Services/CodeAnalysisService_SymbolFinder.cs
+6
-3
未找到文件。
src/Features/Core/Portable/AddImport/SearchScopes/SearchScope.cs
浏览文件 @
de1b70df
...
...
@@ -42,33 +42,35 @@ protected SearchScope(AbstractAddImportCodeFixProvider<TSimpleNameSyntax> provid
return
ImmutableArray
<
SymbolResult
<
ISymbol
>>.
Empty
;
}
var
query
=
this
.
Exact
?
SearchQuery
.
Create
(
name
,
ignoreCase
:
true
)
:
SearchQuery
.
CreateFuzzy
(
name
);
var
symbols
=
await
FindDeclarationsAsync
(
name
,
filter
,
query
).
ConfigureAwait
(
false
);
if
(
Exact
)
using
(
var
query
=
this
.
Exact
?
SearchQuery
.
Create
(
name
,
ignoreCase
:
true
)
:
SearchQuery
.
CreateFuzzy
(
name
))
{
// We did an exact, case insensitive, search. Case sensitive matches should
// be preferred though over insensitive ones.
return
symbols
.
SelectAsArray
(
s
=>
SymbolResult
.
Create
(
s
.
Name
,
nameNode
,
s
,
weight
:
s
.
Name
==
name
?
0
:
1
));
}
var
symbols
=
await
FindDeclarationsAsync
(
name
,
filter
,
query
).
ConfigureAwait
(
false
);
// TODO(cyrusn): It's a shame we have to compute this twice. However, there's no
// great way to store the original value we compute because it happens deep in the
// compiler bowels when we call FindDeclarations.
var
similarityChecker
=
WordSimilarityChecker
.
Allocate
(
name
,
substringsAreSimilar
:
false
);
if
(
Exact
)
{
// We did an exact, case insensitive, search. Case sensitive matches should
// be preferred though over insensitive ones.
return
symbols
.
SelectAsArray
(
s
=>
SymbolResult
.
Create
(
s
.
Name
,
nameNode
,
s
,
weight
:
s
.
Name
==
name
?
0
:
1
));
}
var
result
=
symbols
.
SelectAsArray
(
s
=>
{
var
areSimilar
=
similarityChecker
.
AreSimilar
(
s
.
Name
,
out
var
matchCost
);
// TODO(cyrusn): It's a shame we have to compute this twice. However, there's no
// great way to store the original value we compute because it happens deep in the
// compiler bowels when we call FindDeclarations.
var
similarityChecker
=
WordSimilarityChecker
.
Allocate
(
name
,
substringsAreSimilar
:
false
);
Debug
.
Assert
(
areSimilar
);
return
SymbolResult
.
Create
(
s
.
Name
,
nameNode
,
s
,
matchCost
);
}
);
var
result
=
symbols
.
SelectAsArray
(
s
=>
{
var
areSimilar
=
similarityChecker
.
AreSimilar
(
s
.
Name
,
out
var
matchCost
);
similarityChecker
.
Free
();
Debug
.
Assert
(
areSimilar
);
return
SymbolResult
.
Create
(
s
.
Name
,
nameNode
,
s
,
matchCost
);
});
return
result
;
similarityChecker
.
Free
();
return
result
;
}
}
}
}
...
...
src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs
浏览文件 @
de1b70df
...
...
@@ -183,26 +183,31 @@ internal static partial class DeclarationFinder
internal
static
async
Task
<
ImmutableArray
<
SymbolAndProjectId
>>
FindSourceDeclarationsWithNormalQueryInCurrentProcessAsync
(
Solution
solution
,
string
name
,
bool
ignoreCase
,
SymbolFilter
criteria
,
CancellationToken
cancellationToken
)
{
var
query
=
SearchQuery
.
Create
(
name
,
ignoreCase
);
var
result
=
ArrayBuilder
<
SymbolAndProjectId
>.
GetInstance
();
foreach
(
var
projectId
in
solution
.
ProjectIds
)
using
(
var
query
=
SearchQuery
.
Create
(
name
,
ignoreCase
))
{
var
project
=
solution
.
GetProject
(
projectId
);
await
AddCompilationDeclarationsWithNormalQueryAsync
(
project
,
query
,
criteria
,
result
,
cancellationToken
).
ConfigureAwait
(
false
);
}
var
result
=
ArrayBuilder
<
SymbolAndProjectId
>.
GetInstance
();
foreach
(
var
projectId
in
solution
.
ProjectIds
)
{
var
project
=
solution
.
GetProject
(
projectId
);
await
AddCompilationDeclarationsWithNormalQueryAsync
(
project
,
query
,
criteria
,
result
,
cancellationToken
).
ConfigureAwait
(
false
);
}
return
result
.
ToImmutableAndFree
();
return
result
.
ToImmutableAndFree
();
}
}
internal
static
async
Task
<
ImmutableArray
<
SymbolAndProjectId
>>
FindSourceDeclarationsWithNormalQueryInCurrentProcessAsync
(
Project
project
,
string
name
,
bool
ignoreCase
,
SymbolFilter
filter
,
CancellationToken
cancellationToken
)
{
var
list
=
ArrayBuilder
<
SymbolAndProjectId
>.
GetInstance
();
await
AddCompilationDeclarationsWithNormalQueryAsync
(
project
,
SearchQuery
.
Create
(
name
,
ignoreCase
),
filter
,
list
,
cancellationToken
).
ConfigureAwait
(
false
);
return
list
.
ToImmutableAndFree
();
using
(
var
query
=
SearchQuery
.
Create
(
name
,
ignoreCase
))
{
await
AddCompilationDeclarationsWithNormalQueryAsync
(
project
,
query
,
filter
,
list
,
cancellationToken
).
ConfigureAwait
(
false
);
return
list
.
ToImmutableAndFree
();
}
}
internal
static
async
Task
<
ImmutableArray
<
SymbolAndProjectId
>>
FindSourceDeclarationsWithPatternInCurrentProcessAsync
(
...
...
@@ -215,36 +220,38 @@ internal static partial class DeclarationFinder
// we only want to check the 'WL' portion. Then, after we get all the candidate symbols
// we'll check if the full name matches the full pattern.
var
patternMatcher
=
new
PatternMatcher
(
pattern
);
var
query
=
SearchQuery
.
CreateCustom
(
k
=>
!
patternMatcher
.
GetMatchesForLastSegmentOfPattern
(
k
).
IsDefaultOrEmpty
);
var
symbolAndProjectIds
=
await
SymbolFinder
.
FindSourceDeclarationsWithCustomQueryAsync
(
project
,
query
,
criteria
,
cancellationToken
).
ConfigureAwait
(
false
);
var
result
=
ArrayBuilder
<
SymbolAndProjectId
>.
GetInstance
();
// Now see if the symbols the compiler returned actually match the full pattern.
foreach
(
var
symbolAndProjectId
in
symbolAndProjectIds
)
using
(
var
query
=
SearchQuery
.
CreateCustom
(
k
=>
!
patternMatcher
.
GetMatchesForLastSegmentOfPattern
(
k
).
IsDefaultOrEmpty
))
{
var
symbol
=
symbolAndProjectId
.
Symbol
;
// As an optimization, don't bother getting the container for this symbol if this
// isn't a dotted pattern. Getting the container could cause lots of string
// allocations that we don't if we're never going to check it.
var
matches
=
!
patternMatcher
.
IsDottedPattern
?
new
PatternMatches
(
patternMatcher
.
GetMatches
(
GetSearchName
(
symbol
)))
:
patternMatcher
.
GetMatches
(
GetSearchName
(
symbol
),
GetContainer
(
symbol
));
var
symbolAndProjectIds
=
await
SymbolFinder
.
FindSourceDeclarationsWithCustomQueryAsync
(
project
,
query
,
criteria
,
cancellationToken
).
ConfigureAwait
(
false
);
var
result
=
ArrayBuilder
<
SymbolAndProjectId
>.
GetInstance
();
if
(
matches
.
IsEmpty
)
// Now see if the symbols the compiler returned actually match the full pattern.
foreach
(
var
symbolAndProjectId
in
symbolAndProjectIds
)
{
// Didn't actually match the full pattern, ignore it.
continue
;
var
symbol
=
symbolAndProjectId
.
Symbol
;
// As an optimization, don't bother getting the container for this symbol if this
// isn't a dotted pattern. Getting the container could cause lots of string
// allocations that we don't if we're never going to check it.
var
matches
=
!
patternMatcher
.
IsDottedPattern
?
new
PatternMatches
(
patternMatcher
.
GetMatches
(
GetSearchName
(
symbol
)))
:
patternMatcher
.
GetMatches
(
GetSearchName
(
symbol
),
GetContainer
(
symbol
));
if
(
matches
.
IsEmpty
)
{
// Didn't actually match the full pattern, ignore it.
continue
;
}
result
.
Add
(
symbolAndProjectId
);
}
re
sult
.
Add
(
symbolAndProjectId
);
re
turn
result
.
ToImmutableAndFree
(
);
}
return
result
.
ToImmutableAndFree
();
}
private
static
string
GetSearchName
(
ISymbol
symbol
)
...
...
src/Workspaces/Core/Portable/FindSymbols/SearchQuery.cs
浏览文件 @
de1b70df
...
...
@@ -5,7 +5,7 @@
namespace
Microsoft.CodeAnalysis.FindSymbols
{
internal
class
SearchQuery
internal
class
SearchQuery
:
IDisposable
{
/// <summary>The name being searched for. Is null in the case of custom predicate searching.. But
/// can be used for faster index based searching when it is available.</summary>
...
...
@@ -18,6 +18,8 @@ internal class SearchQuery
///<summary>The predicate to fall back on if faster index searching is not possible.</summary>
private
readonly
Func
<
string
,
bool
>
_predicate
;
private
readonly
WordSimilarityChecker
_wordSimilarityChecker
;
private
SearchQuery
(
string
name
,
SearchKind
kind
)
{
Name
=
name
??
throw
new
ArgumentNullException
(
nameof
(
name
));
...
...
@@ -36,8 +38,8 @@ private SearchQuery(string name, SearchKind kind)
// its 'AreSimilar' method. That way we only create the WordSimilarityChecker
// once and it can cache all the information it needs while it does the AreSimilar
// check against all the possible candidates.
var
editDistance
=
WordSimilarityChecker
.
Allocate
(
name
,
substringsAreSimilar
:
false
);
_predicate
=
editDistance
.
AreSimilar
;
_wordSimilarityChecker
=
WordSimilarityChecker
.
Allocate
(
name
,
substringsAreSimilar
:
false
);
_predicate
=
_wordSimilarityChecker
.
AreSimilar
;
break
;
default
:
throw
ExceptionUtilities
.
UnexpectedValue
(
kind
);
...
...
@@ -50,6 +52,11 @@ private SearchQuery(Func<string, bool> predicate)
_predicate
=
predicate
??
throw
new
ArgumentNullException
(
nameof
(
predicate
));
}
public
void
Dispose
()
{
_wordSimilarityChecker
?.
Free
();
}
public
static
SearchQuery
Create
(
string
name
,
SearchKind
kind
)
=>
new
SearchQuery
(
name
,
kind
);
...
...
src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_AllDeclarations.cs
浏览文件 @
de1b70df
...
...
@@ -14,9 +14,12 @@ public static partial class SymbolFinder
public
static
async
Task
<
IEnumerable
<
ISymbol
>>
FindDeclarationsAsync
(
Project
project
,
string
name
,
bool
ignoreCase
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
var
declarations
=
await
DeclarationFinder
.
FindAllDeclarationsWithNormalQueryAsync
(
project
,
SearchQuery
.
Create
(
name
,
ignoreCase
),
SymbolFilter
.
All
,
cancellationToken
).
ConfigureAwait
(
false
);
return
declarations
.
SelectAsArray
(
t
=>
t
.
Symbol
);
using
(
var
query
=
SearchQuery
.
Create
(
name
,
ignoreCase
))
{
var
declarations
=
await
DeclarationFinder
.
FindAllDeclarationsWithNormalQueryAsync
(
project
,
query
,
SymbolFilter
.
All
,
cancellationToken
).
ConfigureAwait
(
false
);
return
declarations
.
SelectAsArray
(
t
=>
t
.
Symbol
);
}
}
/// <summary>
...
...
@@ -25,9 +28,12 @@ public static partial class SymbolFinder
public
static
async
Task
<
IEnumerable
<
ISymbol
>>
FindDeclarationsAsync
(
Project
project
,
string
name
,
bool
ignoreCase
,
SymbolFilter
filter
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
var
declarations
=
await
DeclarationFinder
.
FindAllDeclarationsWithNormalQueryAsync
(
project
,
SearchQuery
.
Create
(
name
,
ignoreCase
),
filter
,
cancellationToken
).
ConfigureAwait
(
false
);
return
declarations
.
SelectAsArray
(
t
=>
t
.
Symbol
);
using
(
var
query
=
SearchQuery
.
Create
(
name
,
ignoreCase
))
{
var
declarations
=
await
DeclarationFinder
.
FindAllDeclarationsWithNormalQueryAsync
(
project
,
query
,
filter
,
cancellationToken
).
ConfigureAwait
(
false
);
return
declarations
.
SelectAsArray
(
t
=>
t
.
Symbol
);
}
}
}
}
\ No newline at end of file
src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_CustomQueries.cs
浏览文件 @
de1b70df
...
...
@@ -30,10 +30,13 @@ public static Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(Solution so
/// </summary>
public
static
async
Task
<
IEnumerable
<
ISymbol
>>
FindSourceDeclarationsAsync
(
Solution
solution
,
Func
<
string
,
bool
>
predicate
,
SymbolFilter
filter
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
var
declarations
=
await
FindSourceDeclarationsWithCustomQueryAsync
(
solution
,
SearchQuery
.
CreateCustom
(
predicate
),
filter
,
cancellationToken
).
ConfigureAwait
(
false
);
using
(
var
query
=
SearchQuery
.
CreateCustom
(
predicate
))
{
var
declarations
=
await
FindSourceDeclarationsWithCustomQueryAsync
(
solution
,
query
,
filter
,
cancellationToken
).
ConfigureAwait
(
false
);
return
declarations
.
SelectAsArray
(
d
=>
d
.
Symbol
);
return
declarations
.
SelectAsArray
(
d
=>
d
.
Symbol
);
}
}
private
static
async
Task
<
ImmutableArray
<
SymbolAndProjectId
>>
FindSourceDeclarationsWithCustomQueryAsync
(
...
...
@@ -74,10 +77,13 @@ public static Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(Project pro
/// </summary>
public
static
async
Task
<
IEnumerable
<
ISymbol
>>
FindSourceDeclarationsAsync
(
Project
project
,
Func
<
string
,
bool
>
predicate
,
SymbolFilter
filter
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
var
declarations
=
await
FindSourceDeclarationsWithCustomQueryAsync
(
project
,
SearchQuery
.
CreateCustom
(
predicate
),
filter
,
cancellationToken
).
ConfigureAwait
(
false
);
using
(
var
query
=
SearchQuery
.
CreateCustom
(
predicate
))
{
var
declarations
=
await
FindSourceDeclarationsWithCustomQueryAsync
(
project
,
query
,
filter
,
cancellationToken
).
ConfigureAwait
(
false
);
return
declarations
.
SelectAsArray
(
d
=>
d
.
Symbol
);
return
declarations
.
SelectAsArray
(
d
=>
d
.
Symbol
);
}
}
internal
static
async
Task
<
ImmutableArray
<
SymbolAndProjectId
>>
FindSourceDeclarationsWithCustomQueryAsync
(
...
...
src/Workspaces/Remote/ServiceHub/Services/CodeAnalysisService_SymbolFinder.cs
浏览文件 @
de1b70df
...
...
@@ -50,10 +50,13 @@ public async Task FindLiteralReferencesAsync(object value)
var
solution
=
await
GetSolutionAsync
().
ConfigureAwait
(
false
);
var
project
=
solution
.
GetProject
(
projectId
);
var
result
=
await
DeclarationFinder
.
FindAllDeclarationsWithNormalQueryInCurrentProcessAsync
(
project
,
SearchQuery
.
Create
(
name
,
searchKind
),
criteria
,
this
.
CancellationToken
).
ConfigureAwait
(
false
);
using
(
var
query
=
SearchQuery
.
Create
(
name
,
searchKind
))
{
var
result
=
await
DeclarationFinder
.
FindAllDeclarationsWithNormalQueryInCurrentProcessAsync
(
project
,
query
,
criteria
,
this
.
CancellationToken
).
ConfigureAwait
(
false
);
return
result
.
Select
(
SerializableSymbolAndProjectId
.
Dehydrate
).
ToArray
();
return
result
.
Select
(
SerializableSymbolAndProjectId
.
Dehydrate
).
ToArray
();
}
}
public
async
Task
<
SerializableSymbolAndProjectId
[
]>
FindSolutionSourceDeclarationsWithNormalQueryAsync
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录