Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
fe740b4b
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,发现更多精彩内容 >>
提交
fe740b4b
编写于
5月 24, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make fuzzy match skip leading whitespace in pattern, fixes #26096
上级
2e539276
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
68 addition
and
38 deletion
+68
-38
src/vs/base/common/filters.ts
src/vs/base/common/filters.ts
+55
-37
src/vs/base/test/common/filters.test.ts
src/vs/base/test/common/filters.test.ts
+13
-1
未找到文件。
src/vs/base/common/filters.ts
浏览文件 @
fe740b4b
...
...
@@ -448,6 +448,10 @@ _seps['\''] = true;
_seps
[
'
"
'
]
=
true
;
_seps
[
'
:
'
]
=
true
;
const
_ws
:
{
[
ch
:
string
]:
boolean
}
=
Object
.
create
(
null
);
_ws
[
'
'
]
=
true
;
_ws
[
'
\t
'
]
=
true
;
const
enum
Arrow
{
Top
=
0b1
,
Diag
=
0b10
,
Left
=
0b100
}
export
function
fuzzyScore
(
pattern
:
string
,
word
:
string
):
[
number
,
number
[]]
{
...
...
@@ -455,7 +459,20 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
const
patternLen
=
pattern
.
length
>
100
?
100
:
pattern
.
length
;
const
wordLen
=
word
.
length
>
100
?
100
:
word
.
length
;
if
(
patternLen
===
0
)
{
// Check for leading whitespace in the pattern and
// start matching just after that position. This is
// like `pattern = pattern.rtrim()` but doesn't create
// a new string
let
patternStartPos
=
0
;
for
(
const
ch
of
pattern
)
{
if
(
_ws
[
ch
])
{
patternStartPos
+=
1
;
}
else
{
break
;
}
}
if
(
patternLen
===
patternStartPos
)
{
return
[
-
1
,
[]];
}
...
...
@@ -465,16 +482,17 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
const
lowPattern
=
pattern
.
toLowerCase
();
const
lowWord
=
word
.
toLowerCase
();
let
i
=
0
;
let
j
=
0
;
while
(
i
<
patternLen
&&
j
<
wordLen
)
{
if
(
lowPattern
[
i
]
===
lowWord
[
j
])
{
i
+=
1
;
let
patternPos
=
patternStartPos
;
let
wordPos
=
0
;
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 +500,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
=
patternStartPos
+
1
;
patternPos
<=
patternLen
;
patternPos
++
)
{
let
lastLowWordChar
=
''
;
for
(
j
=
1
;
j
<=
wordLen
;
j
++
)
{
for
(
wordPos
=
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
===
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 +530,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 +580,7 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
}
let
bucket
:
[
number
,
number
[]][]
=
[];
findAllMatches
(
patternLen
,
patternLen
,
wordLen
,
0
,
[],
bucket
,
false
);
findAllMatches
(
patternLen
,
patternLen
,
patternStartPos
,
wordLen
,
0
,
[],
bucket
,
false
);
if
(
bucket
.
length
===
0
)
{
return
undefined
;
...
...
@@ -580,7 +598,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
,
patternStartPos
:
number
,
wordPos
:
number
,
total
:
number
,
matches
:
number
[],
bucket
:
[
number
,
number
[]][],
lastMatched
:
boolean
):
void
{
if
(
bucket
.
length
>=
10
)
{
return
;
...
...
@@ -588,7 +606,7 @@ function findAllMatches(patternLen: number, patternPos: number, wordPos: number,
let
simpleMatchCount
=
0
;
while
(
patternPos
>
0
&&
wordPos
>
0
)
{
while
(
patternPos
>
patternStartPos
&&
wordPos
>
0
)
{
let
score
=
_scores
[
patternPos
][
wordPos
];
let
arrow
=
_arrows
[
patternPos
][
wordPos
];
...
...
@@ -609,7 +627,7 @@ function findAllMatches(patternLen: number, patternPos: number, wordPos: number,
if
(
arrow
&
Arrow
.
Left
)
{
// left
findAllMatches
(
patternLen
,
patternPos
,
patternLen
,
patternPos
,
patternStartPos
,
wordPos
-
1
,
matches
.
length
!==
0
?
total
-
1
:
total
,
matches
.
slice
(
0
),
bucket
,
lastMatched
...
...
@@ -635,7 +653,7 @@ function findAllMatches(patternLen: number, patternPos: number, wordPos: number,
}
}
if
(
matches
.
length
!==
patternLen
)
{
if
(
matches
.
length
!==
patternLen
-
patternStartPos
)
{
// doesn't cover whole pattern
return
undefined
;
}
...
...
src/vs/base/test/common/filters.test.ts
浏览文件 @
fe740b4b
...
...
@@ -195,7 +195,7 @@ suite('Filters', () => {
function
assertMatches
(
pattern
:
string
,
word
:
string
,
decoratedWord
:
string
,
filter
:
typeof
fuzzyScore
)
{
let
r
=
filter
(
pattern
,
word
);
assert
.
ok
(
Boolean
(
r
)
===
Boolean
(
decoratedWord
));
assert
.
ok
(
!
decoratedWord
===
(
!
r
||
r
[
1
].
length
===
0
));
if
(
r
)
{
const
[,
matches
]
=
r
;
let
pos
=
0
;
...
...
@@ -325,6 +325,18 @@ suite('Filters', () => {
assertMatches
(
'
f
'
,
'
:foo
'
,
'
:^foo
'
,
fuzzyScore
);
});
test
(
'
Vscode 1.12 no longer obeys
\'
sortText
\'
in completion items (from language server), #26096
'
,
function
()
{
assertMatches
(
'
'
,
'
group
'
,
undefined
,
fuzzyScore
);
assertMatches
(
'
g
'
,
'
group
'
,
'
^group
'
,
fuzzyScore
);
assertMatches
(
'
g
'
,
'
group
'
,
'
^group
'
,
fuzzyScore
);
assertMatches
(
'
g g
'
,
'
groupGroup
'
,
undefined
,
fuzzyScore
);
assertMatches
(
'
g g
'
,
'
group Group
'
,
'
^group^ ^Group
'
,
fuzzyScore
);
assertMatches
(
'
g g
'
,
'
group Group
'
,
'
^group^ ^Group
'
,
fuzzyScore
);
assertMatches
(
'
zz
'
,
'
zzGroup
'
,
'
^z^zGroup
'
,
fuzzyScore
);
assertMatches
(
'
zzg
'
,
'
zzGroup
'
,
'
^z^z^Group
'
,
fuzzyScore
);
assertMatches
(
'
g
'
,
'
zzGroup
'
,
'
zz^Group
'
,
fuzzyScore
);
});
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录