Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
e4adebbe
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,发现更多精彩内容 >>
提交
e4adebbe
编写于
8月 10, 2016
作者:
C
CyrusNajmabadi
提交者:
GitHub
8月 10, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #13059 from CyrusNajmabadi/clearerFuzzyMatches
Make fuzzy add-using matches clearer Fixes #12985
上级
f941893d
9800282e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
75 addition
and
40 deletion
+75
-40
src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.ProjectSymbolReference.cs
...bstractAddImportCodeFixProvider.ProjectSymbolReference.cs
+1
-11
src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.Reference.cs
...s/AddImport/AbstractAddImportCodeFixProvider.Reference.cs
+32
-3
src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.SymbolReference.cs
...mport/AbstractAddImportCodeFixProvider.SymbolReference.cs
+7
-13
src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.SymbolReferenceFinder.cs
...AbstractAddImportCodeFixProvider.SymbolReferenceFinder.cs
+6
-6
src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.SymbolResult.cs
...ddImport/AbstractAddImportCodeFixProvider.SymbolResult.cs
+22
-0
src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.cs
...e/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.cs
+7
-7
未找到文件。
src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.ProjectSymbolReference.cs
浏览文件 @
e4adebbe
...
...
@@ -47,21 +47,11 @@ protected override CodeActionPriority GetPriority(Document document)
if
(
document
.
Project
.
Id
==
_project
.
Id
)
{
if
(
!
SearchResult
.
DesiredNameDiffersFromSourceName
(
))
if
(
SearchResult
.
DesiredNameMatchesSourceName
(
document
))
{
// The name doesn't change. This is a normal priority action.
return
CodeActionPriority
.
Medium
;
}
// We need to update the source name. If all we're doing is changing the
// casing, and this is a case insensitive language, then this is just a
// normal priority action. Otherwise, this wil be low priority.
var
syntaxFacts
=
document
.
GetLanguageService
<
ISyntaxFactsService
>();
if
(!
syntaxFacts
.
IsCaseSensitive
&&
SearchResult
.
DesiredNameDiffersFromSourceNameOnlyByCase
())
{
return
CodeActionPriority
.
Medium
;
}
}
// This is a weaker match. This should be lower than all other fixes.
...
...
src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.Reference.cs
浏览文件 @
e4adebbe
...
...
@@ -13,7 +13,7 @@ namespace Microsoft.CodeAnalysis.CodeFixes.AddImport
{
internal
abstract
partial
class
AbstractAddImportCodeFixProvider
<
TSimpleNameSyntax
>
{
private
abstract
class
Reference
:
I
Comparable
<
Reference
>,
I
Equatable
<
Reference
>
private
abstract
class
Reference
:
IEquatable
<
Reference
>
{
protected
readonly
AbstractAddImportCodeFixProvider
<
TSimpleNameSyntax
>
provider
;
public
readonly
SearchResult
SearchResult
;
...
...
@@ -24,7 +24,7 @@ protected Reference(AbstractAddImportCodeFixProvider<TSimpleNameSyntax> provider
this
.
SearchResult
=
searchResult
;
}
public
virtual
int
CompareTo
(
Reference
other
)
public
int
CompareTo
(
Document
document
,
Reference
other
)
{
// If references have different weights, order by the ones with lower weight (i.e.
// they are better matches).
...
...
@@ -38,7 +38,36 @@ public virtual int CompareTo(Reference other)
return
1
;
}
// If the weight are the same, just order them based on their names.
if
(
this
.
SearchResult
.
DesiredNameMatchesSourceName
(
document
))
{
if
(!
other
.
SearchResult
.
DesiredNameMatchesSourceName
(
document
))
{
// Prefer us as our name doesn't need to change.
return
-
1
;
}
}
else
{
if
(
other
.
SearchResult
.
DesiredNameMatchesSourceName
(
document
))
{
// Prefer them as their name doesn't need to change.
return
1
;
}
else
{
// Both our names need to change. Sort by the name we're
// changing to.
var
diff
=
StringComparer
.
OrdinalIgnoreCase
.
Compare
(
this
.
SearchResult
.
DesiredName
,
other
.
SearchResult
.
DesiredName
);
if
(
diff
!=
0
)
{
return
diff
;
}
}
}
// If the weights are the same and no names changed, just order
// them based on the namespace we're adding an import for.
return
INamespaceOrTypeSymbolExtensions
.
CompareNameParts
(
this
.
SearchResult
.
NameParts
,
other
.
SearchResult
.
NameParts
);
}
...
...
src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.SymbolReference.cs
浏览文件 @
e4adebbe
...
...
@@ -26,19 +26,6 @@ public SymbolReference(AbstractAddImportCodeFixProvider<TSimpleNameSyntax> provi
protected
abstract
Glyph
?
GetGlyph
(
Document
document
);
protected
abstract
bool
CheckForExistingImport
(
Project
project
);
public
override
int
CompareTo
(
Reference
other
)
{
var
diff
=
base
.
CompareTo
(
other
);
if
(
diff
!=
0
)
{
return
diff
;
}
var
name1
=
this
.
SymbolResult
.
DesiredName
;
var
name2
=
(
other
as
SymbolReference
)?.
SymbolResult
.
DesiredName
;
return
StringComparer
.
Ordinal
.
Compare
(
name1
,
name2
);
}
public
override
bool
Equals
(
object
obj
)
{
var
equals
=
base
.
Equals
(
obj
);
...
...
@@ -88,6 +75,13 @@ public override int GetHashCode()
return
null
;
}
if
(!
this
.
SearchResult
.
DesiredNameMatchesSourceName
(
document
))
{
// The name is going to change. Make it clear in the description that
// this is going to happen.
description
=
$"
{
this
.
SearchResult
.
DesiredName
}
-
{
description
}
"
;
}
return
new
OperationBasedCodeAction
(
description
,
GetGlyph
(
document
),
GetPriority
(
document
),
c
=>
this
.
GetOperationsAsync
(
document
,
node
,
placeSystemNamespaceFirst
,
c
),
this
.
GetIsApplicableCheck
(
document
.
Project
));
...
...
src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.SymbolReferenceFinder.cs
浏览文件 @
e4adebbe
...
...
@@ -74,10 +74,10 @@ private INamespaceSymbol MapToCompilationNamespaceIfPossible(INamespaceSymbol co
return
_semanticModel
.
Compilation
.
GetCompilationNamespace
(
containingNamespace
)
??
containingNamespace
;
}
internal
Task
<
List
<
SymbolReference
>>
FindInAllSymbolsInProjectAsync
(
Project
project
,
bool
exact
,
CancellationToken
cancellationToken
)
internal
Task
<
List
<
SymbolReference
>>
FindInAllSymbolsIn
Starting
ProjectAsync
(
bool
exact
,
CancellationToken
cancellationToken
)
{
var
searchScope
=
new
AllSymbolsProjectSearchScope
(
_owner
,
p
roject
,
exact
,
cancellationToken
);
var
searchScope
=
new
AllSymbolsProjectSearchScope
(
_owner
,
_document
.
P
roject
,
exact
,
cancellationToken
);
return
DoAsync
(
searchScope
);
}
...
...
@@ -91,11 +91,11 @@ private INamespaceSymbol MapToCompilationNamespaceIfPossible(INamespaceSymbol co
}
internal
Task
<
List
<
SymbolReference
>>
FindInMetadataSymbolsAsync
(
Solution
solution
,
IAssemblySymbol
assembly
,
PortableExecutableReference
metadataReference
,
IAssemblySymbol
assembly
,
PortableExecutableReference
metadataReference
,
bool
exact
,
CancellationToken
cancellationToken
)
{
var
searchScope
=
new
MetadataSymbolsSearchScope
(
_owner
,
s
olution
,
assembly
,
metadataReference
,
exact
,
cancellationToken
);
_owner
,
_document
.
Project
.
S
olution
,
assembly
,
metadataReference
,
exact
,
cancellationToken
);
return
DoAsync
(
searchScope
);
}
...
...
@@ -153,7 +153,7 @@ private List<SymbolReference> DeDupeAndSortReferences(List<SymbolReference> allR
.
Distinct
()
.
Where
(
NotNull
)
.
Where
(
NotGlobalNamespace
)
.
Order
(
)
.
Order
By
((
r1
,
r2
)
=>
r1
.
CompareTo
(
_document
,
r2
)
)
.
ToList
();
}
...
...
src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.SymbolResult.cs
浏览文件 @
e4adebbe
...
...
@@ -3,6 +3,7 @@
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
Microsoft.CodeAnalysis.LanguageServices
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
namespace
Microsoft.CodeAnalysis.CodeFixes.AddImport
...
...
@@ -49,6 +50,27 @@ public bool DesiredNameDiffersFromSourceNameOnlyByCase()
return
StringComparer
.
OrdinalIgnoreCase
.
Equals
(
this
.
NameNode
.
GetFirstToken
().
ValueText
,
this
.
DesiredName
);
}
public
bool
DesiredNameMatchesSourceName
(
Document
document
)
{
if
(!
this
.
DesiredNameDiffersFromSourceName
())
{
// Names match in any language.
return
true
;
}
var
syntaxFacts
=
document
.
GetLanguageService
<
ISyntaxFactsService
>();
// Names differ. But in a case insensitive language they may match.
if
(!
syntaxFacts
.
IsCaseSensitive
&&
this
.
DesiredNameDiffersFromSourceNameOnlyByCase
())
{
return
true
;
}
// Name are totally different in any language.
return
false
;
}
}
private
struct
SymbolResult
<
T
>
where
T
:
ISymbol
...
...
src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.cs
浏览文件 @
e4adebbe
...
...
@@ -160,8 +160,8 @@ private static bool IsHostOrTestWorkspace(Project project)
// First search the current project to see if any symbols (source or metadata) match the
// search string.
await
FindResultsInAll
ProjectSymbols
Async
(
project
,
allReferences
,
finder
,
exact
,
cancellationToken
).
ConfigureAwait
(
false
);
await
FindResultsInAll
SymbolsInStartingProject
Async
(
allReferences
,
finder
,
exact
,
cancellationToken
).
ConfigureAwait
(
false
);
// Only bother doing this for host workspaces. We don't want this for
// things like the Interactive workspace as we can't even add project
...
...
@@ -186,11 +186,11 @@ private static bool IsHostOrTestWorkspace(Project project)
return
allReferences
;
}
private
async
Task
FindResultsInAll
ProjectSymbols
Async
(
Project
project
,
List
<
Reference
>
allSymbolReferences
,
SymbolReferenceFinder
finder
,
bool
exact
,
CancellationToken
cancellationToken
)
private
async
Task
FindResultsInAll
SymbolsInStartingProject
Async
(
List
<
Reference
>
allSymbolReferences
,
SymbolReferenceFinder
finder
,
bool
exact
,
CancellationToken
cancellationToken
)
{
var
references
=
await
finder
.
FindInAllSymbolsIn
ProjectAsync
(
project
,
exact
,
cancellationToken
).
ConfigureAwait
(
false
);
var
references
=
await
finder
.
FindInAllSymbolsIn
StartingProjectAsync
(
exact
,
cancellationToken
).
ConfigureAwait
(
false
);
AddRange
(
allSymbolReferences
,
references
);
}
...
...
@@ -272,7 +272,7 @@ private static bool IsHostOrTestWorkspace(Project project)
if
(
assembly
!=
null
)
{
findTasks
.
Add
(
finder
.
FindInMetadataSymbolsAsync
(
project
.
Solution
,
assembly
,
reference
,
exact
,
linkedTokenSource
.
Token
));
assembly
,
reference
,
exact
,
linkedTokenSource
.
Token
));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录