Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
37a4b96a
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,发现更多精彩内容 >>
提交
37a4b96a
编写于
1月 22, 2021
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
simplify FuzzyScore structure, fix high, low match
上级
9939537e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
25 deletion
+29
-25
src/vs/base/common/filters.ts
src/vs/base/common/filters.ts
+23
-25
src/vs/base/test/common/filters.test.ts
src/vs/base/test/common/filters.test.ts
+6
-0
未找到文件。
src/vs/base/common/filters.ts
浏览文件 @
37a4b96a
...
...
@@ -387,7 +387,7 @@ export function anyScore(pattern: string, lowPattern: string, _patternPos: numbe
break
;
}
}
return
[
score
,
matches
,
_wordPo
s
];
return
[
score
,
_wordPos
,
matche
s
];
}
//#region --- fuzzyScore ---
...
...
@@ -396,19 +396,15 @@ export function createMatches(score: undefined | FuzzyScore): IMatch[] {
if
(
typeof
score
===
'
undefined
'
)
{
return
[];
}
const
matches
=
score
[
1
].
toString
(
2
);
const
wordStart
=
score
[
2
];
const
res
:
IMatch
[]
=
[];
for
(
let
pos
=
wordStart
;
pos
<
_maxLen
;
pos
++
)
{
if
(
matches
[
matches
.
length
-
(
pos
+
1
)]
===
'
1
'
)
{
const
last
=
res
[
res
.
length
-
1
];
if
(
last
&&
last
.
end
===
pos
)
{
last
.
end
=
pos
+
1
;
}
else
{
res
.
push
({
start
:
pos
,
end
:
pos
+
1
});
}
const
wordPos
=
score
[
1
];
for
(
let
i
=
score
.
length
-
1
;
i
>
1
;
i
--
)
{
const
pos
=
score
[
i
]
+
wordPos
;
const
last
=
res
[
res
.
length
-
1
];
if
(
last
&&
last
.
end
===
pos
)
{
last
.
end
=
pos
+
1
;
}
else
{
res
.
push
({
start
:
pos
,
end
:
pos
+
1
});
}
}
return
res
;
...
...
@@ -536,18 +532,21 @@ export function isPatternInWord(patternLow: string, patternPos: number, patternL
const
enum
Arrow
{
Diag
=
1
,
Left
=
2
,
LeftLeft
=
3
}
/**
* A tuple of three values.
* An array representating a fuzzy match.
*
* 0. the score
* 1. the matches encoded as bitmask (2^53)
* 2. the offset at which matching started
* 1. the offset at which matching started
* 2. `<match_pos_1>`
* 3. `<match_pos_2>`
* 4. `<match_pos_3>` etc
*/
export
type
FuzzyScore
=
[
number
,
number
,
number
];
export
type
FuzzyScore
=
[
score
:
number
,
wordStart
:
number
,
...
matches
:
number
[]];
// [
number, number, number];
export
namespace
FuzzyScore
{
/**
* No matches and value `-100`
*/
export
const
Default
:
[
-
100
,
0
,
0
]
=
<
[
-
100
,
0
,
0
]
>
Object
.
freeze
([
-
100
,
0
,
0
]);
export
const
Default
:
FuzzyScore
=
([
-
10
0
,
0
]);
export
function
isDefault
(
score
?:
FuzzyScore
):
score
is
[
-
100
,
0
,
0
]
{
return
!
score
||
(
score
[
0
]
===
-
100
&&
score
[
1
]
===
0
&&
score
[
2
]
===
0
);
...
...
@@ -650,8 +649,8 @@ export function fuzzyScore(pattern: string, patternLow: string, patternStart: nu
row
--
;
column
--
;
const
topScore
=
_table
[
row
][
column
];
let
matches
=
0
;
const
result
:
FuzzyScore
=
[
_table
[
row
][
column
],
wordStart
];
let
backwardsDiagLength
=
0
;
let
maxMatchColumn
=
0
;
...
...
@@ -694,21 +693,20 @@ export function fuzzyScore(pattern: string, patternLow: string, patternStart: nu
row
--
;
column
=
diagColumn
-
1
;
matches
+=
2
**
(
column
+
wordStart
);
result
.
push
(
column
);
}
let
finalScore
=
topScore
;
if
(
wordLen
===
patternLen
)
{
// the word matches the pattern with all characters!
// giving the score a total match boost (to come up ahead other words)
finalScore
+=
2
;
result
[
0
]
+=
2
;
}
// Add 1 penalty for each skipped character in the word
const
skippedCharsCount
=
maxMatchColumn
-
patternLen
;
finalScore
-=
skippedCharsCount
;
result
[
0
]
-=
skippedCharsCount
;
return
[
finalScore
,
matches
,
wordStart
]
;
return
result
;
}
function
_fillInMaxWordMatchPos
(
patternLen
:
number
,
wordLen
:
number
,
patternStart
:
number
,
wordStart
:
number
,
patternLow
:
string
,
wordLow
:
string
)
{
...
...
src/vs/base/test/common/filters.test.ts
浏览文件 @
37a4b96a
...
...
@@ -521,6 +521,12 @@ suite('Filters', () => {
'
ffffffffffffffffffffffffffffbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar_^f^o^o
'
,
fuzzyScore
);
assertMatches
(
'
Aoo
'
,
'
Affffffffffffffffffffffffffffbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar_foo
'
,
'
^Affffffffffffffffffffffffffffbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar_f^o^o
'
,
fuzzyScore
);
assertMatches
(
'
foo
'
,
'
Gffffffffffffffffffffffffffffbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar_foo
'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录