Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d6bf8879
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d6bf8879
编写于
3月 24, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove old scorer
上级
89568273
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
3 addition
and
152 deletion
+3
-152
src/vs/base/common/filters.ts
src/vs/base/common/filters.ts
+0
-82
src/vs/base/test/common/filters.perf.test.ts
src/vs/base/test/common/filters.perf.test.ts
+0
-1
src/vs/base/test/common/filters.test.ts
src/vs/base/test/common/filters.test.ts
+3
-69
未找到文件。
src/vs/base/common/filters.ts
浏览文件 @
d6bf8879
...
...
@@ -395,88 +395,6 @@ export function createMatches(position: number[]): IMatch[] {
return
ret
;
}
export
function
fuzzyMatchAndScore
(
pattern
:
string
,
word
:
string
):
[
number
,
number
[]]
{
if
(
!
pattern
)
{
return
[
-
1
,
[]];
}
if
(
pattern
.
length
>
word
.
length
)
{
return
undefined
;
}
let
matches
:
number
[]
=
[];
let
score
=
_matchRecursive
(
pattern
,
pattern
.
toLowerCase
(),
pattern
.
toUpperCase
(),
0
,
word
,
word
.
toLowerCase
(),
0
,
matches
);
if
(
score
<=
0
)
{
return
undefined
;
}
score
-=
Math
.
min
(
matches
[
0
],
3
)
*
3
;
// penalty for first matching character
score
-=
(
1
+
matches
[
matches
.
length
-
1
])
-
(
pattern
.
length
);
// penalty for all non matching characters between first and last
return
[
score
,
matches
];
}
export
function
_matchRecursive
(
pattern
:
string
,
lowPattern
:
string
,
upPattern
:
string
,
patternPos
:
number
,
word
:
string
,
lowWord
:
string
,
wordPos
:
number
,
matches
:
number
[]
):
number
{
if
(
patternPos
>=
lowPattern
.
length
)
{
return
0
;
}
const
lowPatternChar
=
lowPattern
[
patternPos
];
let
idx
=
-
1
;
let
value
=
0
;
if
((
patternPos
===
wordPos
&&
lowPatternChar
===
lowWord
[
wordPos
])
&&
((
value
=
_matchRecursive
(
pattern
,
lowPattern
,
upPattern
,
patternPos
+
1
,
word
,
lowWord
,
wordPos
+
1
,
matches
))
>=
0
)
)
{
matches
.
unshift
(
wordPos
);
return
(
pattern
[
patternPos
]
===
word
[
wordPos
]
?
17
:
11
)
+
value
;
}
if
((
idx
=
word
.
indexOf
(
upPattern
[
patternPos
],
wordPos
))
>=
0
&&
((
value
=
_matchRecursive
(
pattern
,
lowPattern
,
upPattern
,
patternPos
+
1
,
word
,
lowWord
,
idx
+
1
,
matches
))
>=
0
)
)
{
matches
.
unshift
(
idx
);
return
(
pattern
[
patternPos
]
===
word
[
idx
]
?
17
:
11
)
+
value
;
}
if
((
idx
=
lowWord
.
indexOf
(
`_
${
lowPatternChar
}
`
,
wordPos
))
>=
0
&&
((
value
=
_matchRecursive
(
pattern
,
lowPattern
,
upPattern
,
patternPos
+
1
,
word
,
lowWord
,
idx
+
2
,
matches
))
>=
0
)
)
{
matches
.
unshift
(
idx
+
1
);
return
(
pattern
[
patternPos
]
===
word
[
idx
+
1
]
?
17
:
11
)
+
value
;
}
if
((
idx
=
lowWord
.
indexOf
(
`.
${
lowPatternChar
}
`
,
wordPos
))
>=
0
&&
((
value
=
_matchRecursive
(
pattern
,
lowPattern
,
upPattern
,
patternPos
+
1
,
word
,
lowWord
,
idx
+
2
,
matches
))
>=
0
)
)
{
matches
.
unshift
(
idx
+
1
);
return
11
+
value
;
}
if
(
patternPos
>
0
&&
(
idx
=
lowWord
.
indexOf
(
lowPatternChar
,
wordPos
))
>=
0
&&
((
value
=
_matchRecursive
(
pattern
,
lowPattern
,
upPattern
,
patternPos
+
1
,
word
,
lowWord
,
idx
+
1
,
matches
))
>=
0
)
)
{
matches
.
unshift
(
idx
);
return
1
+
value
;
}
return
-
1
;
}
function
initTable
()
{
const
table
:
number
[][]
=
[];
const
row
:
number
[]
=
[
0
];
...
...
src/vs/base/test/common/filters.perf.test.ts
浏览文件 @
d6bf8879
...
...
@@ -40,7 +40,6 @@ perfSuite('Performance - fuzzyMatch', function () {
perfTest
(
'
matchesFuzzy
'
,
filters
.
matchesFuzzy
);
perfTest
(
'
fuzzyContiguousFilter
'
,
filters
.
fuzzyContiguousFilter
);
perfTest
(
'
matchesFuzzy2
'
,
filters
.
matchesFuzzy2
);
perfTest
(
'
fuzzyMatchAndScore
'
,
filters
.
fuzzyMatchAndScore
);
perfTest
(
'
fuzzyScore
'
,
filters
.
fuzzyScore
);
});
...
...
src/vs/base/test/common/filters.test.ts
浏览文件 @
d6bf8879
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
IFilter
,
or
,
matchesPrefix
,
matchesStrictPrefix
,
matchesCamelCase
,
matchesSubString
,
matchesContiguousSubString
,
matchesWords
,
fuzzy
MatchAndScore
,
fuzzy
Score
}
from
'
vs/base/common/filters
'
;
import
{
IFilter
,
or
,
matchesPrefix
,
matchesStrictPrefix
,
matchesCamelCase
,
matchesSubString
,
matchesContiguousSubString
,
matchesWords
,
fuzzyScore
}
from
'
vs/base/common/filters
'
;
function
filterOk
(
filter
:
IFilter
,
word
:
string
,
wordToMatchAgainst
:
string
,
highlights
?:
{
start
:
number
;
end
:
number
;
}[])
{
let
r
=
filter
(
word
,
wordToMatchAgainst
);
...
...
@@ -193,7 +193,7 @@ suite('Filters', () => {
assert
.
deepEqual
(
matchesWords
(
'
pu
'
,
'
Category: Git: Pull
'
,
true
),
[{
start
:
15
,
end
:
17
}]);
});
function
assertMatches
(
pattern
:
string
,
word
:
string
,
decoratedWord
:
string
,
filter
:
typeof
fuzzy
MatchAnd
Score
)
{
function
assertMatches
(
pattern
:
string
,
word
:
string
,
decoratedWord
:
string
,
filter
:
typeof
fuzzyScore
)
{
let
r
=
filter
(
pattern
,
word
);
assert
.
ok
(
Boolean
(
r
)
===
Boolean
(
decoratedWord
));
if
(
r
)
{
...
...
@@ -208,36 +208,6 @@ suite('Filters', () => {
}
}
test
(
'
fuzzyMatchAndScore
'
,
function
()
{
assertMatches
(
'
no
'
,
'
match
'
,
undefined
,
fuzzyMatchAndScore
);
assertMatches
(
'
no
'
,
''
,
undefined
,
fuzzyMatchAndScore
);
assertMatches
(
'
BK
'
,
'
the_black_knight
'
,
'
the_^black_^knight
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
bkn
'
,
'
the_black_knight
'
,
'
the_^black_^k^night
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
bt
'
,
'
the_black_knight
'
,
'
the_^black_knigh^t
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
bti
'
,
'
the_black_knight
'
,
undefined
,
fuzzyMatchAndScore
);
assertMatches
(
'
LLL
'
,
'
SVisualLoggerLogsList
'
,
'
SVisual^Logger^Logs^List
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
LLLL
'
,
'
SVisualLoggerLogsList
'
,
undefined
,
fuzzyMatchAndScore
);
assertMatches
(
'
sllll
'
,
'
SVisualLoggerLogsList
'
,
'
^SVisua^l^Logger^Logs^List
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
sl
'
,
'
SVisualLoggerLogsList
'
,
'
^SVisual^LoggerLogsList
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
foobar
'
,
'
foobar
'
,
'
^f^o^o^b^a^r
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
fob
'
,
'
foobar
'
,
'
^f^oo^bar
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
ob
'
,
'
foobar
'
,
undefined
,
fuzzyMatchAndScore
);
assertMatches
(
'
gp
'
,
'
Git: Pull
'
,
'
^Git: ^Pull
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
gp
'
,
'
Git_Git_Pull
'
,
'
^Git_Git_^Pull
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
g p
'
,
'
Git: Pull
'
,
'
^Git:^ ^Pull
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
gip
'
,
'
Git: Pull
'
,
'
^G^it: ^Pull
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
is
'
,
'
isValid
'
,
'
^i^sValid
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
is
'
,
'
ImportStatement
'
,
'
^Import^Statement
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
lowrd
'
,
'
lowWord
'
,
'
^l^o^wWo^r^d
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
ccm
'
,
'
cacmelCase
'
,
'
^ca^c^melCase
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
ccm
'
,
'
camelCase
'
,
undefined
,
fuzzyMatchAndScore
);
assertMatches
(
'
ccm
'
,
'
camelCasecm
'
,
'
^camel^Casec^m
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
myvable
'
,
'
myvariable
'
,
'
^m^y^v^aria^b^l^e
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
fdm
'
,
'
findModel
'
,
'
^fin^d^Model
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
form
'
,
'
editor.formatOnSave
'
,
'
editor.^f^o^r^matOnSave
'
,
fuzzyMatchAndScore
);
assertMatches
(
'
KeyboardLayoutEventChange=
'
,
'
KeyboardLayoutEventChange
'
,
undefined
,
fuzzyMatchAndScore
);
});
test
(
'
fuzzyScore
'
,
function
()
{
assertMatches
(
'
ab
'
,
'
abA
'
,
'
^a^bA
'
,
fuzzyScore
);
assertMatches
(
'
ccm
'
,
'
cacmelCase
'
,
'
^ca^c^melCase
'
,
fuzzyScore
);
...
...
@@ -283,7 +253,7 @@ suite('Filters', () => {
assertMatches
(
'
Three
'
,
'
Three
'
,
'
^T^h^r^e^e
'
,
fuzzyScore
);
});
function
assertTopScore
(
filter
:
typeof
fuzzy
MatchAnd
Score
,
pattern
:
string
,
expected
:
number
,
...
words
:
string
[])
{
function
assertTopScore
(
filter
:
typeof
fuzzyScore
,
pattern
:
string
,
expected
:
number
,
...
words
:
string
[])
{
let
topScore
=
Number
.
MIN_VALUE
;
let
topIdx
=
0
;
for
(
let
i
=
0
;
i
<
words
.
length
;
i
++
)
{
...
...
@@ -300,44 +270,8 @@ suite('Filters', () => {
assert
.
equal
(
topIdx
,
expected
,
`
${
pattern
}
-> actual=
${
words
[
topIdx
]}
<> expected=
${
words
[
expected
]}
`
);
}
test
(
'
topScore - fuzzyMatchAndScore
'
,
function
()
{
assertTopScore
(
fuzzyMatchAndScore
,
'
cons
'
,
2
,
'
ArrayBufferConstructor
'
,
'
Console
'
,
'
console
'
);
assertTopScore
(
fuzzyMatchAndScore
,
'
Foo
'
,
1
,
'
foo
'
,
'
Foo
'
,
'
foo
'
);
assertTopScore
(
fuzzyMatchAndScore
,
'
CC
'
,
1
,
'
camelCase
'
,
'
CamelCase
'
);
assertTopScore
(
fuzzyMatchAndScore
,
'
cC
'
,
0
,
'
camelCase
'
,
'
CamelCase
'
);
assertTopScore
(
fuzzyMatchAndScore
,
'
cC
'
,
1
,
'
ccfoo
'
,
'
camelCase
'
);
assertTopScore
(
fuzzyMatchAndScore
,
'
cC
'
,
1
,
'
ccfoo
'
,
'
camelCase
'
,
'
foo-cC-bar
'
);
// issue #17836
assertTopScore
(
fuzzyMatchAndScore
,
'
p
'
,
0
,
'
parse
'
,
'
posix
'
,
'
pafdsa
'
,
'
path
'
,
'
p
'
);
assertTopScore
(
fuzzyMatchAndScore
,
'
pa
'
,
0
,
'
parse
'
,
'
pafdsa
'
,
'
path
'
);
// issue #14583
assertTopScore
(
fuzzyMatchAndScore
,
'
log
'
,
3
,
'
HTMLOptGroupElement
'
,
'
ScrollLogicalPosition
'
,
'
SVGFEMorphologyElement
'
,
'
log
'
);
assertTopScore
(
fuzzyMatchAndScore
,
'
e
'
,
2
,
'
AbstractWorker
'
,
'
ActiveXObject
'
,
'
else
'
);
// issue #14446
assertTopScore
(
fuzzyMatchAndScore
,
'
workbench.sideb
'
,
1
,
'
workbench.editor.defaultSideBySideLayout
'
,
'
workbench.sideBar.location
'
);
// issue #11423
assertTopScore
(
fuzzyMatchAndScore
,
'
editor.r
'
,
2
,
'
diffEditor.renderSideBySide
'
,
'
editor.overviewRulerlanes
'
,
'
editor.renderControlCharacter
'
,
'
editor.renderWhitespace
'
);
// assertTopScore(fuzzyMatchAndScore, 'editor.R', 1, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
// assertTopScore(fuzzyMatchAndScore, 'Editor.r', 0, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
assertTopScore
(
fuzzyMatchAndScore
,
'
-mo
'
,
1
,
'
-ms-ime-mode
'
,
'
-moz-columns
'
);
// // dupe, issue #14861
assertTopScore
(
fuzzyMatchAndScore
,
'
convertModelPosition
'
,
0
,
'
convertModelPositionToViewPosition
'
,
'
convertViewToModelPosition
'
);
// // dupe, issue #14942
assertTopScore
(
fuzzyMatchAndScore
,
'
is
'
,
0
,
'
isValidViewletId
'
,
'
import statement
'
);
});
test
(
'
topScore - fuzzyScore
'
,
function
()
{
assertTopScore
(
fuzzyScore
,
'
TEdit
'
,
1
,
'
TextEditorDecorationType
'
,
'
TextEdit
'
,
'
TextEditor
'
);
assertTopScore
(
fuzzyScore
,
'
cons
'
,
2
,
'
ArrayBufferConstructor
'
,
'
Console
'
,
'
console
'
);
assertTopScore
(
fuzzyScore
,
'
Foo
'
,
1
,
'
foo
'
,
'
Foo
'
,
'
foo
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录