Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
093eac50
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
093eac50
编写于
5月 22, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow offsets for fuzzyScore, towards #26096
上级
aac718a2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
37 deletion
+44
-37
src/vs/base/common/filters.ts
src/vs/base/common/filters.ts
+37
-37
src/vs/base/test/common/filters.test.ts
src/vs/base/test/common/filters.test.ts
+7
-0
未找到文件。
src/vs/base/common/filters.ts
浏览文件 @
093eac50
...
...
@@ -450,7 +450,7 @@ _seps[':'] = true;
const
enum
Arrow
{
Top
=
0b1
,
Diag
=
0b10
,
Left
=
0b100
}
export
function
fuzzyScore
(
pattern
:
string
,
word
:
string
):
[
number
,
number
[]]
{
export
function
fuzzyScore
(
pattern
:
string
,
word
:
string
,
patternOffset
:
number
=
0
,
wordOffset
:
number
=
0
):
[
number
,
number
[]]
{
const
patternLen
=
pattern
.
length
>
100
?
100
:
pattern
.
length
;
const
wordLen
=
word
.
length
>
100
?
100
:
word
.
length
;
...
...
@@ -465,16 +465,16 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
const
lowPattern
=
pattern
.
toLowerCase
();
const
lowWord
=
word
.
toLowerCase
();
let
i
=
0
;
let
j
=
0
;
let
patternPos
=
patternOffset
;
let
wordPos
=
wordOffset
;
while
(
i
<
patternLen
&&
j
<
wordLen
)
{
if
(
lowPattern
[
i
]
===
lowWord
[
j
])
{
i
+=
1
;
while
(
patternPos
<
patternLen
&&
wordPos
<
wordLen
)
{
if
(
lowPattern
[
patternPos
]
===
lowWord
[
wordPos
])
{
patternPos
+=
1
;
}
j
+=
1
;
wordPos
+=
1
;
}
if
(
i
!==
patternLen
)
{
if
(
patternPos
!==
patternLen
)
{
// no simple matches found -> return early
return
undefined
;
}
...
...
@@ -482,24 +482,24 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
// keep track of the maximum score
let
maxScore
=
-
1
;
for
(
i
=
1
;
i
<=
patternLen
;
i
++
)
{
for
(
patternPos
=
patternOffset
+
1
;
patternPos
<=
patternLen
;
patternPos
++
)
{
let
lastLowWordChar
=
''
;
for
(
j
=
1
;
j
<=
wordLen
;
j
++
)
{
for
(
wordPos
=
wordOffset
+
1
;
wordPos
<=
wordLen
;
wordPos
++
)
{
let
score
=
-
1
;
let
lowWordChar
=
lowWord
[
j
-
1
];
if
(
lowPattern
[
i
-
1
]
===
lowWordChar
)
{
let
lowWordChar
=
lowWord
[
wordPos
-
1
];
if
(
lowPattern
[
patternPos
-
1
]
===
lowWordChar
)
{
if
(
j
===
1
)
{
if
(
pattern
[
i
-
1
]
===
word
[
j
-
1
])
{
if
(
wordPos
===
wordOffset
+
1
)
{
if
(
pattern
[
patternPos
-
1
]
===
word
[
wordPos
-
1
])
{
score
=
7
;
}
else
{
score
=
5
;
}
}
else
if
(
lowWordChar
!==
word
[
j
-
1
])
{
if
(
pattern
[
i
-
1
]
===
word
[
j
-
1
])
{
}
else
if
(
lowWordChar
!==
word
[
wordPos
-
1
])
{
if
(
pattern
[
patternPos
-
1
]
===
word
[
wordPos
-
1
])
{
score
=
7
;
}
else
{
score
=
5
;
...
...
@@ -512,38 +512,38 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
}
}
_scores
[
i
][
j
]
=
score
;
_scores
[
patternPos
][
wordPos
]
=
score
;
if
(
score
>
maxScore
)
{
maxScore
=
score
;
}
let
diag
=
_table
[
i
-
1
][
j
-
1
]
+
(
score
>
1
?
1
:
score
);
let
top
=
_table
[
i
-
1
][
j
]
+
-
1
;
let
left
=
_table
[
i
][
j
-
1
]
+
-
1
;
let
diag
=
_table
[
patternPos
-
1
][
wordPos
-
1
]
+
(
score
>
1
?
1
:
score
);
let
top
=
_table
[
patternPos
-
1
][
wordPos
]
+
-
1
;
let
left
=
_table
[
patternPos
][
wordPos
-
1
]
+
-
1
;
if
(
left
>=
top
)
{
// left or diag
if
(
left
>
diag
)
{
_table
[
i
][
j
]
=
left
;
_arrows
[
i
][
j
]
=
Arrow
.
Left
;
_table
[
patternPos
][
wordPos
]
=
left
;
_arrows
[
patternPos
][
wordPos
]
=
Arrow
.
Left
;
}
else
if
(
left
===
diag
)
{
_table
[
i
][
j
]
=
left
;
_arrows
[
i
][
j
]
=
Arrow
.
Left
|
Arrow
.
Diag
;
_table
[
patternPos
][
wordPos
]
=
left
;
_arrows
[
patternPos
][
wordPos
]
=
Arrow
.
Left
|
Arrow
.
Diag
;
}
else
{
_table
[
i
][
j
]
=
diag
;
_arrows
[
i
][
j
]
=
Arrow
.
Diag
;
_table
[
patternPos
][
wordPos
]
=
diag
;
_arrows
[
patternPos
][
wordPos
]
=
Arrow
.
Diag
;
}
}
else
{
// top or diag
if
(
top
>
diag
)
{
_table
[
i
][
j
]
=
top
;
_arrows
[
i
][
j
]
=
Arrow
.
Top
;
_table
[
patternPos
][
wordPos
]
=
top
;
_arrows
[
patternPos
][
wordPos
]
=
Arrow
.
Top
;
}
else
if
(
top
===
diag
)
{
_table
[
i
][
j
]
=
top
;
_arrows
[
i
][
j
]
=
Arrow
.
Top
|
Arrow
.
Diag
;
_table
[
patternPos
][
wordPos
]
=
top
;
_arrows
[
patternPos
][
wordPos
]
=
Arrow
.
Top
|
Arrow
.
Diag
;
}
else
{
_table
[
i
][
j
]
=
diag
;
_arrows
[
i
][
j
]
=
Arrow
.
Diag
;
_table
[
patternPos
][
wordPos
]
=
diag
;
_arrows
[
patternPos
][
wordPos
]
=
Arrow
.
Diag
;
}
}
...
...
@@ -562,7 +562,7 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
}
let
bucket
:
[
number
,
number
[]][]
=
[];
findAllMatches
(
patternLen
,
patternLen
,
wordLen
,
0
,
[],
bucket
,
false
);
findAllMatches
(
patternLen
,
patternLen
,
patternOffset
,
wordLen
,
wordOffset
,
0
,
[],
bucket
,
false
);
if
(
bucket
.
length
===
0
)
{
return
undefined
;
...
...
@@ -580,7 +580,7 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
return
topMatch
;
}
function
findAllMatches
(
patternLen
:
number
,
patternPos
:
number
,
wordPos
:
number
,
total
:
number
,
matches
:
number
[],
bucket
:
[
number
,
number
[]][],
lastMatched
:
boolean
):
void
{
function
findAllMatches
(
patternLen
:
number
,
patternPos
:
number
,
patternOffset
:
number
,
wordPos
:
number
,
wordOffset
:
number
,
total
:
number
,
matches
:
number
[],
bucket
:
[
number
,
number
[]][],
lastMatched
:
boolean
):
void
{
if
(
bucket
.
length
>=
10
)
{
return
;
...
...
@@ -588,7 +588,7 @@ function findAllMatches(patternLen: number, patternPos: number, wordPos: number,
let
simpleMatchCount
=
0
;
while
(
patternPos
>
0
&&
wordPos
>
0
)
{
while
(
patternPos
>
patternOffset
&&
wordPos
>
wordOffset
)
{
let
score
=
_scores
[
patternPos
][
wordPos
];
let
arrow
=
_arrows
[
patternPos
][
wordPos
];
...
...
@@ -609,8 +609,8 @@ function findAllMatches(patternLen: number, patternPos: number, wordPos: number,
if
(
arrow
&
Arrow
.
Left
)
{
// left
findAllMatches
(
patternLen
,
patternPos
,
wordPos
-
1
,
patternLen
,
patternPos
,
patternOffset
,
wordPos
-
1
,
wordOffset
,
matches
.
length
!==
0
?
total
-
1
:
total
,
matches
.
slice
(
0
),
bucket
,
lastMatched
);
...
...
src/vs/base/test/common/filters.test.ts
浏览文件 @
093eac50
...
...
@@ -325,6 +325,13 @@ suite('Filters', () => {
assertMatches
(
'
f
'
,
'
:foo
'
,
'
:^foo
'
,
fuzzyScore
);
});
test
(
'
fuzzyScore with offset
'
,
function
()
{
const
matches
=
fuzzyScore
(
'
bc
'
,
'
abc
'
,
0
,
1
);
assert
.
ok
(
matches
);
const
[,
range
]
=
matches
;
assert
.
deepEqual
(
range
,
[
1
,
2
]);
});
function
assertTopScore
(
filter
:
typeof
fuzzyScore
,
pattern
:
string
,
expected
:
number
,
...
words
:
string
[])
{
let
topScore
=
-
(
100
*
10
);
let
topIdx
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录