Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9d40f0c6
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,发现更多精彩内容 >>
提交
9d40f0c6
编写于
10月 20, 2017
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tweak scoring to prevent match scattering
上级
5b4c9d25
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
252 addition
and
123 deletion
+252
-123
src/vs/base/parts/quickopen/common/quickOpenScorer.ts
src/vs/base/parts/quickopen/common/quickOpenScorer.ts
+159
-121
src/vs/base/parts/quickopen/test/common/quickOpenScorer.test.ts
.../base/parts/quickopen/test/common/quickOpenScorer.test.ts
+93
-2
未找到文件。
src/vs/base/parts/quickopen/common/quickOpenScorer.ts
浏览文件 @
9d40f0c6
...
@@ -14,180 +14,218 @@ import { stripWildcards } from 'vs/base/common/strings';
...
@@ -14,180 +14,218 @@ import { stripWildcards } from 'vs/base/common/strings';
export
type
Score
=
[
number
/* score */
,
number
[]
/* match positions */
];
export
type
Score
=
[
number
/* score */
,
number
[]
/* match positions */
];
export
type
ScorerCache
=
{
[
key
:
string
]:
IItemScore
};
export
type
ScorerCache
=
{
[
key
:
string
]:
IItemScore
};
const
NO_SCORE
:
Score
=
[
0
,
[]];
const
NO_MATCH
=
0
;
const
NO_SCORE
:
Score
=
[
NO_MATCH
,
[]];
export
function
_doScore
(
target
:
string
,
query
:
string
,
queryLower
:
string
,
fuzzy
:
boolean
):
Score
{
// const DEBUG = false;
// const DEBUG_MATRIX = false;
export
function
score
(
target
:
string
,
query
:
string
,
queryLower
:
string
,
fuzzy
:
boolean
):
Score
{
if
(
!
target
||
!
query
)
{
if
(
!
target
||
!
query
)
{
return
NO_SCORE
;
// return early if target or query are undefined
return
NO_SCORE
;
// return early if target or query are undefined
}
}
if
(
target
.
length
<
query
.
length
)
{
const
targetLength
=
target
.
length
;
const
queryLength
=
query
.
length
;
if
(
targetLength
<
queryLength
)
{
return
NO_SCORE
;
// impossible for query to be contained in target
return
NO_SCORE
;
// impossible for query to be contained in target
}
}
// console.group(`Target: ${target}, Query: ${query}`);
// if (DEBUG) {
// console.group(`Target: ${target}, Query: ${query}`);
// }
const
queryLen
=
query
.
length
;
const
targetLower
=
target
.
toLowerCase
();
const
targetLower
=
target
.
toLowerCase
();
let
res
=
NO_SCORE
;
// When not searching fuzzy, we require the query to be contained fully
// When not searching fuzzy, we require the query to be contained fully
// in the target string
. We set the offset to search from to that location
.
// in the target string
contiguously
.
if
(
!
fuzzy
)
{
if
(
!
fuzzy
)
{
const
indexOfQueryInTarget
=
targetLower
.
indexOf
(
queryLower
);
const
indexOfQueryInTarget
=
targetLower
.
indexOf
(
queryLower
);
if
(
indexOfQueryInTarget
===
-
1
)
{
if
(
indexOfQueryInTarget
===
-
1
)
{
// console.log(`Characters not matching consecutively ${queryLower} within ${targetLower}`);
// if (DEBUG) {
// console.log(`Characters not matching consecutively ${queryLower} within ${targetLower}`);
// }
return
NO_SCORE
;
return
NO_SCORE
;
}
}
res
=
_doScoreFromOffset
(
target
,
query
,
targetLower
,
queryLower
,
queryLen
,
indexOfQueryInTarget
);
}
}
// When searching fuzzy we run the scorer for each location of the first query
// When searching fuzzy, we require the query to be contained fully
// character so that we can produce better results in case the pattern matches
// in the target string as separate substrings
// multiple times on the target (prevent scattering of matching positions).
else
{
else
{
const
queryFirstCharacter
=
queryLower
[
0
];
let
targetOffset
=
0
;
for
(
let
queryIndex
=
0
;
queryIndex
<
queryLength
;
queryIndex
++
)
{
let
offset
=
0
;
targetOffset
=
targetLower
.
indexOf
(
queryLower
[
queryIndex
],
targetOffset
);
while
((
offset
=
targetLower
.
indexOf
(
queryFirstCharacter
,
offset
))
!==
-
1
)
{
if
(
targetOffset
===
-
1
)
{
const
scoreFromOffset
=
_doScoreFromOffset
(
target
,
query
,
targetLower
,
queryLower
,
queryLen
,
offset
);
return
NO_SCORE
;
if
(
isBetterScore
(
res
,
scoreFromOffset
))
{
res
=
scoreFromOffset
;
}
}
offset
++
;
}
}
}
}
// console.log(`%cFinal Score: ${score}`, 'font-weight: bold');
const
res
=
doScore
(
query
,
queryLower
,
queryLength
,
target
,
targetLower
,
targetLength
);
// console.groupEnd();
// if (DEBUG) {
// console.log(`%cFinal Score: ${res[0]}`, 'font-weight: bold');
// console.groupEnd();
// }
return
res
;
return
res
;
}
}
function
isBetterScore
(
score
:
Score
,
candidate
:
Score
):
boolean
{
function
doScore
(
query
:
string
,
queryLower
:
string
,
queryLength
:
number
,
target
:
string
,
targetLower
:
string
,
targetLength
:
number
):
[
number
,
number
[]]
{
if
(
candidate
[
0
]
>
score
[
0
])
{
const
scores
=
[];
return
true
;
// candidate has higher score
const
matches
=
[];
}
//
// Build Scorer Matrix
// The matrix is composed of query q and target t. For each index we score
// q[i] with t[i] and compare that with the previous score. If the score is
// equal or larger, we keep the match. In addition to the score, we also keep
// the length of the consecutive matches to use as boost for the score.
//
// t a r g e t
// q
// u
// e
// r
// y
//
for
(
let
queryIndex
=
0
;
queryIndex
<
queryLength
;
queryIndex
++
)
{
for
(
let
targetIndex
=
0
;
targetIndex
<
targetLength
;
targetIndex
++
)
{
const
currentIndex
=
queryIndex
*
targetLength
+
targetIndex
;
const
leftIndex
=
currentIndex
-
1
;
const
diagIndex
=
(
queryIndex
-
1
)
*
targetLength
+
targetIndex
-
1
;
const
leftScore
=
targetIndex
>
0
?
scores
[
leftIndex
]
:
0
;
const
diagScore
=
queryIndex
>
0
&&
targetIndex
>
0
?
scores
[
diagIndex
]
:
0
;
const
matchesSequenceLength
=
queryIndex
>
0
&&
targetIndex
>
0
?
matches
[
diagIndex
]
:
0
;
const
score
=
computeCharScore
(
query
,
queryLower
,
queryIndex
,
target
,
targetLower
,
targetIndex
,
matchesSequenceLength
);
// We have a score and its equal or larger than the left score
// Match: sequence continues growing from previous diag value
// Score: increases by diag score value
if
(
score
&&
diagScore
+
score
>=
leftScore
)
{
matches
[
currentIndex
]
=
matchesSequenceLength
+
1
;
scores
[
currentIndex
]
=
diagScore
+
score
;
}
if
(
score
[
0
]
>
candidate
[
0
])
{
// We either have no score or the score is lower than the left score
return
false
;
// candidate has lower score
// Match: reset to 0
// Score: pick up from left hand side
else
{
matches
[
currentIndex
]
=
NO_MATCH
;
scores
[
currentIndex
]
=
leftScore
;
}
}
}
}
// Score is the same, check by match compactness
// Restore Positions (starting from bottom right of matrix)
const
matchStart
=
score
[
1
][
0
];
const
positions
=
[];
const
matchEnd
=
score
[
1
][
score
[
1
].
length
-
1
];
let
queryIndex
=
queryLength
-
1
;
const
matchLength
=
matchEnd
-
matchStart
;
let
targetIndex
=
targetLength
-
1
;
while
(
queryIndex
>=
0
&&
targetIndex
>=
0
)
{
const
candidateMatchStart
=
candidate
[
1
][
0
];
const
currentIndex
=
queryIndex
*
targetLength
+
targetIndex
;
const
candidateMatchEnd
=
candidate
[
1
][
candidate
[
1
].
length
-
1
];
const
match
=
matches
[
currentIndex
];
const
candidateMatchLength
=
candidateMatchEnd
-
candidateMatchStart
;
if
(
match
===
NO_MATCH
)
{
targetIndex
--
;
// go left
if
(
candidateMatchLength
<
matchLength
)
{
}
else
{
return
true
;
// candidate has more compact matches
positions
.
push
(
targetIndex
);
// go up and left
queryIndex
--
;
targetIndex
--
;
}
}
}
return
false
;
// Print matrix
// if (DEBUG_MATRIX) {
// printMatrix(query, target, matches, scores);
// }
return
[
scores
[
queryLength
*
targetLength
-
1
],
positions
.
reverse
()];
}
}
// Based on material from:
function
computeCharScore
(
query
:
string
,
queryLower
:
string
,
queryIndex
:
number
,
target
:
string
,
targetLower
:
string
,
targetIndex
:
number
,
matchesSequenceLength
:
number
):
number
{
/*!
BEGIN THIRD PARTY
*/
/*!
* string_score.js: String Scoring Algorithm 0.1.22
*
* http://joshaven.com/string_score
* https://github.com/joshaven/string_score
*
* Copyright (C) 2009-2014 Joshaven Potter <yourtech@gmail.com>
* Special thanks to all of the contributors listed here https://github.com/joshaven/string_score
* MIT License: http://opensource.org/licenses/MIT
*
* Date: Tue Mar 1 2011
* Updated: Tue Mar 10 2015
*/
function
_doScoreFromOffset
(
target
:
string
,
query
:
string
,
targetLower
:
string
,
queryLower
:
string
,
queryLen
:
number
,
offset
:
number
):
Score
{
const
matchingPositions
:
number
[]
=
[];
let
targetIndex
=
offset
;
let
queryIndex
=
0
;
let
score
=
0
;
let
score
=
0
;
while
(
queryIndex
<
queryLen
)
{
// Check for query character being contained in target
const
indexOfQueryInTarget
=
targetLower
.
indexOf
(
queryLower
[
queryIndex
],
targetIndex
);
if
(
indexOfQueryInTarget
<
0
)
{
// console.log(`Character not part of target ${query[index]}`);
score
=
0
;
break
;
}
// Fill into positions array
if
(
queryLower
[
queryIndex
]
!==
targetLower
[
targetIndex
])
{
matchingPositions
.
push
(
indexOfQueryInTarget
);
return
score
;
// no match of characters
}
// Character match bonus
score
+=
1
;
// console.groupCollapsed(`%cCharacter match bonus: +1 (char: ${query[index]} at index ${indexOf}, total score: ${score})`, 'font-weight: normal');
// Consecutive match bonus
// Character match bonus
if
(
targetIndex
===
indexOfQueryInTarget
&&
queryIndex
>
0
)
{
score
+=
1
;
score
+=
5
;
// console.log('Consecutive match bonus: +5');
// if (DEBUG) {
}
// console.groupCollapsed(`%cCharacter match bonus: +1 (char: ${queryLower[queryIndex]} at index ${targetIndex}, total score: ${score})`, 'font-weight: normal');
// }
// Same case
bonus
// Consecutive match
bonus
if
(
target
[
indexOfQueryInTarget
]
===
query
[
queryIndex
]
)
{
if
(
matchesSequenceLength
>
0
)
{
score
+=
1
;
score
+=
(
matchesSequenceLength
*
5
)
;
// console.log('Same case bonus: +1');
// if (DEBUG) {
}
// console.log('Consecutive match bonus: ' + (matchesSequenceLength * 5));
// }
}
// Start of word
bonus
// Same case
bonus
if
(
indexOfQueryInTarget
===
0
)
{
if
(
query
[
queryIndex
]
===
target
[
targetIndex
]
)
{
score
+=
8
;
score
+=
1
;
// console.log('Start of word bonus: +8');
// if (DEBUG) {
}
// console.log('Same case bonus: +1');
// }
}
// After separator
bonus
// Start of word
bonus
else
if
(
isSeparatorAtPos
(
target
,
indexOfQueryInTarget
-
1
)
)
{
if
(
targetIndex
===
0
)
{
score
+=
7
;
score
+=
8
;
// console.log('After separtor bonus: +7');
// if (DEBUG) {
}
// console.log('Start of word bonus: +8');
// }
}
// Inside word upper case
bonus
// After separator
bonus
else
if
(
isUpper
(
target
.
charCodeAt
(
indexOfQueryInTarget
)
))
{
else
if
(
isSeparatorAtPos
(
target
,
targetIndex
-
1
))
{
score
+=
1
;
score
+=
4
;
// console.log('Inside word upper case bonus: +1');
// if (DEBUG) {
}
// console.log('After separtor bonus: +4');
// }
}
// console.groupEnd();
// Inside word upper case bonus
else
if
(
isUpper
(
target
.
charCodeAt
(
targetIndex
)))
{
score
+=
1
;
targetIndex
=
indexOfQueryInTarget
+
1
;
// if (DEBUG) {
queryIndex
++
;
// console.log('Inside word upper case bonus: +1');
// }
}
}
const
res
:
Score
=
(
score
>
0
)
?
[
score
,
matchingPositions
]
:
NO_SCORE
;
// if (DEBUG) {
// console.groupEnd();
// console.log(`%cFinal Score: ${score}`, 'font-weight: bold');
// }
// console.groupEnd();
return
res
;
return
score
;
}
}
/*!
// function printMatrix(query: string, target: string, matches: number[], scores: number[]): void {
END THIRD PARTY
// console.log('\t' + target.split('').join('\t'));
*/
// for (let queryIndex = 0; queryIndex < query.length; queryIndex++) {
// let line = query[queryIndex] + '\t';
// for (let targetIndex = 0; targetIndex < target.length; targetIndex++) {
// const currentIndex = queryIndex * target.length + targetIndex;
// line = line + 'M' + matches[currentIndex] + '/' + 'S' + scores[currentIndex] + '\t';
// }
// console.log(line);
// }
// }
/**
/**
* Scoring on structural items that have a label and optional description.
* Scoring on structural items that have a label and optional description.
...
@@ -315,7 +353,7 @@ function doScoreItem<T>(label: string, description: string, path: string, query:
...
@@ -315,7 +353,7 @@ function doScoreItem<T>(label: string, description: string, path: string, query:
}
}
// 4.) prefer scores on the label if any
// 4.) prefer scores on the label if any
const
[
labelScore
,
labelPositions
]
=
_doS
core
(
label
,
query
.
value
,
query
.
lowercase
,
fuzzy
);
const
[
labelScore
,
labelPositions
]
=
s
core
(
label
,
query
.
value
,
query
.
lowercase
,
fuzzy
);
if
(
labelScore
)
{
if
(
labelScore
)
{
return
{
score
:
labelScore
+
LABEL_SCORE_THRESHOLD
,
labelMatch
:
createMatches
(
labelPositions
)
};
return
{
score
:
labelScore
+
LABEL_SCORE_THRESHOLD
,
labelMatch
:
createMatches
(
labelPositions
)
};
}
}
...
@@ -331,7 +369,7 @@ function doScoreItem<T>(label: string, description: string, path: string, query:
...
@@ -331,7 +369,7 @@ function doScoreItem<T>(label: string, description: string, path: string, query:
const
descriptionPrefixLength
=
descriptionPrefix
.
length
;
const
descriptionPrefixLength
=
descriptionPrefix
.
length
;
const
descriptionAndLabel
=
`
${
descriptionPrefix
}${
label
}
`
;
const
descriptionAndLabel
=
`
${
descriptionPrefix
}${
label
}
`
;
const
[
labelDescriptionScore
,
labelDescriptionPositions
]
=
_doS
core
(
descriptionAndLabel
,
query
.
value
,
query
.
lowercase
,
fuzzy
);
const
[
labelDescriptionScore
,
labelDescriptionPositions
]
=
s
core
(
descriptionAndLabel
,
query
.
value
,
query
.
lowercase
,
fuzzy
);
if
(
labelDescriptionScore
)
{
if
(
labelDescriptionScore
)
{
const
labelDescriptionMatches
=
createMatches
(
labelDescriptionPositions
);
const
labelDescriptionMatches
=
createMatches
(
labelDescriptionPositions
);
const
labelMatch
:
IMatch
[]
=
[];
const
labelMatch
:
IMatch
[]
=
[];
...
...
src/vs/base/parts/quickopen/test/common/quickOpenScorer.test.ts
浏览文件 @
9d40f0c6
...
@@ -44,7 +44,7 @@ class NullAccessorClass implements scorer.IItemAccessor<URI> {
...
@@ -44,7 +44,7 @@ class NullAccessorClass implements scorer.IItemAccessor<URI> {
}
}
function
_doScore
(
target
:
string
,
query
:
string
,
fuzzy
:
boolean
):
scorer
.
Score
{
function
_doScore
(
target
:
string
,
query
:
string
,
fuzzy
:
boolean
):
scorer
.
Score
{
return
scorer
.
_doS
core
(
target
,
query
,
query
.
toLowerCase
(),
fuzzy
);
return
scorer
.
s
core
(
target
,
query
,
query
.
toLowerCase
(),
fuzzy
);
}
}
function
scoreItem
<
T
>
(
item
:
T
,
query
:
string
,
fuzzy
:
boolean
,
accessor
:
scorer
.
IItemAccessor
<
T
>
,
cache
:
scorer
.
ScorerCache
):
scorer
.
IItemScore
{
function
scoreItem
<
T
>
(
item
:
T
,
query
:
string
,
fuzzy
:
boolean
,
accessor
:
scorer
.
IItemAccessor
<
T
>
,
cache
:
scorer
.
ScorerCache
):
scorer
.
IItemScore
{
...
@@ -209,6 +209,18 @@ suite('Quick Open Scorer', () => {
...
@@ -209,6 +209,18 @@ suite('Quick Open Scorer', () => {
assert
.
equal
(
pathRes
.
descriptionMatch
[
0
].
end
,
26
);
assert
.
equal
(
pathRes
.
descriptionMatch
[
0
].
end
,
26
);
});
});
test
(
'
scoreItem - avoid match scattering (bug #36119)
'
,
function
()
{
const
resource
=
URI
.
file
(
'
projects/ui/cula/ats/target.mk
'
);;
const
pathRes
=
scoreItem
(
resource
,
'
tcltarget.mk
'
,
true
,
ResourceAccessor
,
cache
);
assert
.
ok
(
pathRes
.
score
);
assert
.
ok
(
pathRes
.
descriptionMatch
);
assert
.
ok
(
pathRes
.
labelMatch
);
assert
.
equal
(
pathRes
.
labelMatch
.
length
,
1
);
assert
.
equal
(
pathRes
.
labelMatch
[
0
].
start
,
0
);
assert
.
equal
(
pathRes
.
labelMatch
[
0
].
end
,
9
);
});
test
(
'
scoreItem - prefers more compact matches
'
,
function
()
{
test
(
'
scoreItem - prefers more compact matches
'
,
function
()
{
const
resource
=
URI
.
file
(
'
/1a111d1/11a1d1/something.txt
'
);
const
resource
=
URI
.
file
(
'
/1a111d1/11a1d1/something.txt
'
);
...
@@ -541,13 +553,19 @@ suite('Quick Open Scorer', () => {
...
@@ -541,13 +553,19 @@ suite('Quick Open Scorer', () => {
let
res
=
[
resourceA
,
resourceB
,
resourceC
,
resourceD
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
let
res
=
[
resourceA
,
resourceB
,
resourceC
,
resourceD
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceC
);
assert
.
equal
(
res
[
0
],
resourceC
);
res
=
[
resourceC
,
resourceB
,
resourceA
,
resourceD
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceC
);
query
=
isWindows
?
'
un1
\\
index.js
'
:
'
un1/index.js
'
;
query
=
isWindows
?
'
un1
\\
index.js
'
:
'
un1/index.js
'
;
res
=
[
resourceA
,
resourceB
,
resourceC
,
resourceD
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
res
=
[
resourceA
,
resourceB
,
resourceC
,
resourceD
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceB
);
assert
.
equal
(
res
[
0
],
resourceB
);
res
=
[
resourceC
,
resourceB
,
resourceA
,
resourceD
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceB
);
});
});
test
(
'
compareFilesByScore - avoid match scattering (bug #21019)
'
,
function
()
{
test
(
'
compareFilesByScore - avoid match scattering (bug #21019
1.
)
'
,
function
()
{
const
resourceA
=
URI
.
file
(
'
app/containers/Services/NetworkData/ServiceDetails/ServiceLoad/index.js
'
);
const
resourceA
=
URI
.
file
(
'
app/containers/Services/NetworkData/ServiceDetails/ServiceLoad/index.js
'
);
const
resourceB
=
URI
.
file
(
'
app/containers/Services/NetworkData/ServiceDetails/ServiceDistribution/index.js
'
);
const
resourceB
=
URI
.
file
(
'
app/containers/Services/NetworkData/ServiceDetails/ServiceDistribution/index.js
'
);
const
resourceC
=
URI
.
file
(
'
app/containers/Services/NetworkData/ServiceDetailTabs/ServiceTabs/StatVideo/index.js
'
);
const
resourceC
=
URI
.
file
(
'
app/containers/Services/NetworkData/ServiceDetailTabs/ServiceTabs/StatVideo/index.js
'
);
...
@@ -556,6 +574,22 @@ suite('Quick Open Scorer', () => {
...
@@ -556,6 +574,22 @@ suite('Quick Open Scorer', () => {
let
res
=
[
resourceA
,
resourceB
,
resourceC
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
let
res
=
[
resourceA
,
resourceB
,
resourceC
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceC
);
assert
.
equal
(
res
[
0
],
resourceC
);
res
=
[
resourceC
,
resourceB
,
resourceA
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceC
);
});
test
(
'
compareFilesByScore - avoid match scattering (bug #21019 2.)
'
,
function
()
{
const
resourceA
=
URI
.
file
(
'
src/build-helper/store/redux.ts
'
);
const
resourceB
=
URI
.
file
(
'
src/repository/store/redux.ts
'
);
let
query
=
'
reproreduxts
'
;
let
res
=
[
resourceA
,
resourceB
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceB
);
res
=
[
resourceB
,
resourceA
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceB
);
});
});
test
(
'
compareFilesByScore - avoid match scattering (bug #26649)
'
,
function
()
{
test
(
'
compareFilesByScore - avoid match scattering (bug #26649)
'
,
function
()
{
...
@@ -567,6 +601,9 @@ suite('Quick Open Scorer', () => {
...
@@ -567,6 +601,9 @@ suite('Quick Open Scorer', () => {
let
res
=
[
resourceA
,
resourceB
,
resourceC
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
let
res
=
[
resourceA
,
resourceB
,
resourceC
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceC
);
assert
.
equal
(
res
[
0
],
resourceC
);
res
=
[
resourceC
,
resourceB
,
resourceA
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceC
);
});
});
test
(
'
compareFilesByScore - avoid match scattering (bug #33247)
'
,
function
()
{
test
(
'
compareFilesByScore - avoid match scattering (bug #33247)
'
,
function
()
{
...
@@ -577,6 +614,9 @@ suite('Quick Open Scorer', () => {
...
@@ -577,6 +614,9 @@ suite('Quick Open Scorer', () => {
let
res
=
[
resourceA
,
resourceB
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
let
res
=
[
resourceA
,
resourceB
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceB
);
assert
.
equal
(
res
[
0
],
resourceB
);
res
=
[
resourceB
,
resourceA
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceB
);
});
});
test
(
'
compareFilesByScore - avoid match scattering (bug #33247 comment)
'
,
function
()
{
test
(
'
compareFilesByScore - avoid match scattering (bug #33247 comment)
'
,
function
()
{
...
@@ -587,6 +627,40 @@ suite('Quick Open Scorer', () => {
...
@@ -587,6 +627,40 @@ suite('Quick Open Scorer', () => {
let
res
=
[
resourceA
,
resourceB
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
let
res
=
[
resourceA
,
resourceB
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceB
);
assert
.
equal
(
res
[
0
],
resourceB
);
res
=
[
resourceB
,
resourceA
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceB
);
});
test
(
'
compareFilesByScore - avoid match scattering (bug #36166)
'
,
function
()
{
const
resourceA
=
URI
.
file
(
'
django/contrib/sites/locale/ga/LC_MESSAGES/django.mo
'
);
const
resourceB
=
URI
.
file
(
'
django/core/signals.py
'
);
let
query
=
'
djancosig
'
;
let
res
=
[
resourceA
,
resourceB
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceB
);
res
=
[
resourceB
,
resourceA
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceB
);
});
test
(
'
compareFilesByScore - avoid match scattering (bug #32918)
'
,
function
()
{
const
resourceA
=
URI
.
file
(
'
adsys/protected/config.php
'
);
const
resourceB
=
URI
.
file
(
'
adsys/protected/framework/smarty/sysplugins/smarty_internal_config.php
'
);
const
resourceC
=
URI
.
file
(
'
duowanVideo/wap/protected/config.php
'
);
let
query
=
'
protectedconfig.php
'
;
let
res
=
[
resourceA
,
resourceB
,
resourceC
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceA
);
assert
.
equal
(
res
[
1
],
resourceC
);
assert
.
equal
(
res
[
2
],
resourceB
);
res
=
[
resourceC
,
resourceB
,
resourceA
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceA
);
assert
.
equal
(
res
[
1
],
resourceC
);
assert
.
equal
(
res
[
2
],
resourceB
);
});
});
test
(
'
compareFilesByScore - prefer shorter hit (bug #20546)
'
,
function
()
{
test
(
'
compareFilesByScore - prefer shorter hit (bug #20546)
'
,
function
()
{
...
@@ -597,6 +671,23 @@ suite('Quick Open Scorer', () => {
...
@@ -597,6 +671,23 @@ suite('Quick Open Scorer', () => {
let
res
=
[
resourceA
,
resourceB
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
let
res
=
[
resourceA
,
resourceB
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceB
);
assert
.
equal
(
res
[
0
],
resourceB
);
res
=
[
resourceB
,
resourceA
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceB
);
});
test
(
'
compareFilesByScore - avoid match scattering (bug #12095)
'
,
function
()
{
const
resourceA
=
URI
.
file
(
'
src/vs/workbench/parts/files/common/explorerViewModel.ts
'
);
const
resourceB
=
URI
.
file
(
'
src/vs/workbench/parts/files/browser/views/explorerView.ts
'
);
const
resourceC
=
URI
.
file
(
'
src/vs/workbench/parts/files/browser/views/explorerViewer.ts
'
);
let
query
=
'
filesexplorerview.ts
'
;
let
res
=
[
resourceA
,
resourceB
,
resourceC
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceB
);
res
=
[
resourceA
,
resourceC
,
resourceB
].
sort
((
r1
,
r2
)
=>
compareItemsByScore
(
r1
,
r2
,
query
,
true
,
ResourceAccessor
,
cache
));
assert
.
equal
(
res
[
0
],
resourceB
);
});
});
test
(
'
prepareSearchForScoring
'
,
function
()
{
test
(
'
prepareSearchForScoring
'
,
function
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录