Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
0851be2a
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,发现更多精彩内容 >>
提交
0851be2a
编写于
6月 08, 2016
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify completion helper code.
上级
4a79e90e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
32 deletion
+35
-32
src/EditorFeatures/Core/Extensibility/Completion/CompletionHelper.cs
...eatures/Core/Extensibility/Completion/CompletionHelper.cs
+18
-23
src/Features/Core/Portable/Shared/Utilities/PatternMatch.cs
src/Features/Core/Portable/Shared/Utilities/PatternMatch.cs
+17
-9
未找到文件。
src/EditorFeatures/Core/Extensibility/Completion/CompletionHelper.cs
浏览文件 @
0851be2a
...
...
@@ -247,15 +247,14 @@ protected int GetPrefixLength(string text, string pattern)
protected
int
CompareMatches
(
PatternMatch
match1
,
PatternMatch
match2
,
CompletionItem
item1
,
CompletionItem
item2
)
{
int
diff
;
diff
=
PatternMatch
.
CompareType
(
match1
,
match2
);
if
(
diff
!=
0
)
{
return
diff
;
}
diff
=
PatternMatch
.
CompareCamelCase
(
match1
,
match2
);
// First see how the two items compare in a case insensitive fashion. Matches that
// are strictly better (ignoring case) should prioritize the item. i.e. if we have
// a prefix match, that should always be better than a substring match.
//
// The reason we ignore case is that it's very common for people to type expecting
// completion to fix up their casing. i.e. 'false' will be written with the
// expectation that it will get fixed by the completion list to 'False'.
var
diff
=
match1
.
CompareTo
(
match2
,
ignoreCase
:
true
);
if
(
diff
!=
0
)
{
return
diff
;
...
...
@@ -271,23 +270,19 @@ protected int CompareMatches(PatternMatch match1, PatternMatch match2, Completio
return
-
1
;
}
// preselected items are prefered
if
(
item1
.
Rules
.
Preselect
&&
!
item2
.
Rules
.
Preselect
)
{
return
-
1
;
}
else
if
(
item2
.
Rules
.
Preselect
&&
!
item1
.
Rules
.
Preselect
)
{
return
1
;
}
diff
=
PatternMatch
.
CompareCase
(
match1
,
match2
);
if
(
diff
!=
0
)
// Now, after comparing matches, check if an item wants to be preselected. If so,
// we prefer that. i.e. say the user has typed 'f' and we have the items 'foo'
// and 'False' (with the latter being 'Preselected'). Both will be a prefix match.
// And because we are ignoring case, neither will be seen as better. Now, because
// 'False' is preselected we pick it even though 'foo' matches 'f' case sensitively.
if
(
item1
.
Rules
.
Preselect
!=
item2
.
Rules
.
Preselect
)
{
return
diff
;
return
item1
.
Rules
.
Preselect
?
-
1
:
1
;
}
diff
=
PatternMatch
.
ComparePunctuation
(
match1
,
match2
);
// Now compare the matches again in a case sensitive manner. If everything was
// equal up to this point, we prefer the item that better matches based on case.
diff
=
match1
.
CompareTo
(
match2
,
ignoreCase
:
false
);
if
(
diff
!=
0
)
{
return
diff
;
...
...
src/Features/Core/Portable/Shared/Utilities/PatternMatch.cs
浏览文件 @
0851be2a
...
...
@@ -37,7 +37,7 @@ internal struct PatternMatch : IComparable<PatternMatch>
bool
isCaseSensitive
,
TextSpan
?
matchedSpan
,
int
?
camelCaseWeight
=
null
)
:
this
(
resultType
,
punctuationStripped
,
isCaseSensitive
,
:
this
(
resultType
,
punctuationStripped
,
isCaseSensitive
,
matchedSpan
==
null
?
null
:
new
[]
{
matchedSpan
.
Value
},
camelCaseWeight
)
{
...
...
@@ -64,11 +64,16 @@ internal struct PatternMatch : IComparable<PatternMatch>
}
public
int
CompareTo
(
PatternMatch
other
)
{
return
CompareTo
(
other
,
ignoreCase
:
false
);
}
public
int
CompareTo
(
PatternMatch
other
,
bool
ignoreCase
)
{
int
diff
;
if
((
diff
=
CompareType
(
this
,
other
))
!=
0
||
(
diff
=
CompareCamelCase
(
this
,
other
))
!=
0
||
(
diff
=
CompareCase
(
this
,
other
))
!=
0
||
(
diff
=
CompareCase
(
this
,
other
,
ignoreCase
))
!=
0
||
(
diff
=
ComparePunctuation
(
this
,
other
))
!=
0
)
{
return
diff
;
...
...
@@ -77,7 +82,7 @@ public int CompareTo(PatternMatch other)
return
0
;
}
internal
static
int
ComparePunctuation
(
PatternMatch
result1
,
PatternMatch
result2
)
private
static
int
ComparePunctuation
(
PatternMatch
result1
,
PatternMatch
result2
)
{
// Consider a match to be better if it was successful without stripping punctuation
// versus a match that had to strip punctuation to succeed.
...
...
@@ -89,22 +94,25 @@ internal static int ComparePunctuation(PatternMatch result1, PatternMatch result
return
0
;
}
internal
static
int
CompareCase
(
PatternMatch
result1
,
PatternMatch
result2
)
private
static
int
CompareCase
(
PatternMatch
result1
,
PatternMatch
result2
,
bool
ignoreCase
)
{
if
(
result1
.
IsCaseSensitive
!=
result2
.
IsCaseSensitiv
e
)
if
(
!
ignoreCas
e
)
{
return
result1
.
IsCaseSensitive
?
-
1
:
1
;
if
(
result1
.
IsCaseSensitive
!=
result2
.
IsCaseSensitive
)
{
return
result1
.
IsCaseSensitive
?
-
1
:
1
;
}
}
return
0
;
}
internal
static
int
CompareType
(
PatternMatch
result1
,
PatternMatch
result2
)
private
static
int
CompareType
(
PatternMatch
result1
,
PatternMatch
result2
)
{
return
result1
.
Kind
-
result2
.
Kind
;
}
internal
static
int
CompareCamelCase
(
PatternMatch
result1
,
PatternMatch
result2
)
private
static
int
CompareCamelCase
(
PatternMatch
result1
,
PatternMatch
result2
)
{
if
(
result1
.
Kind
==
PatternMatchKind
.
CamelCase
&&
result2
.
Kind
==
PatternMatchKind
.
CamelCase
)
{
...
...
@@ -116,4 +124,4 @@ internal static int CompareCamelCase(PatternMatch result1, PatternMatch result2)
return
0
;
}
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录