Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
7eff5f7f
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,发现更多精彩内容 >>
提交
7eff5f7f
编写于
12月 10, 2015
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
extract scorer.ts and give OSS attribution
上级
92839a05
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
133 addition
and
93 deletion
+133
-93
src/vs/base/common/OSSREADME.json
src/vs/base/common/OSSREADME.json
+8
-0
src/vs/base/common/scorer.ts
src/vs/base/common/scorer.ts
+85
-0
src/vs/base/common/strings.ts
src/vs/base/common/strings.ts
+0
-66
src/vs/base/test/common/scorer.test.ts
src/vs/base/test/common/scorer.test.ts
+35
-0
src/vs/base/test/common/strings.test.ts
src/vs/base/test/common/strings.test.ts
+0
-23
src/vs/workbench/parts/search/browser/openAnythingHandler.ts
src/vs/workbench/parts/search/browser/openAnythingHandler.ts
+5
-4
未找到文件。
src/vs/base/common/OSSREADME.json
0 → 100644
浏览文件 @
7eff5f7f
//
ATTENTION
-
THIS
DIRECTORY
CONTAINS
THIRD
PARTY
OPEN
SOURCE
MATERIALS:
[{
"name"
:
"string_scorer"
,
"version"
:
"10 March 2015"
,
"license"
:
"MIT License"
,
"repositoryURL"
:
"https://github.com/joshaven/string_score"
,
"description"
:
"The file scorer.ts was inspired by the string_score algorithm from Joshaven Potter."
}]
src/vs/base/common/scorer.ts
0 → 100644
浏览文件 @
7eff5f7f
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
// Based on material from:
/*!
* 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
*/
/**
* Compute a score for the given string and the given query.
*
* Rules:
* Character score: 1
* Same case bonus: 1
* Upper case bonus: 1
* Start of word/path bonus: 7
* Start of string bonus: 8
*/
export
function
score
(
target
:
string
,
query
:
string
):
number
{
let
score
=
0
;
if
(
!
target
||
!
query
)
{
return
score
;
// return early if target or query are undefined
}
const
queryLen
=
query
.
length
;
const
targetLower
=
target
.
toLowerCase
();
const
queryLower
=
query
.
toLowerCase
();
const
wordPathBoundary
=
[
'
-
'
,
'
_
'
,
'
'
,
'
/
'
,
'
\\
'
];
let
index
=
0
;
while
(
index
<
queryLen
)
{
var
indexOf
=
targetLower
.
indexOf
(
queryLower
[
index
]);
if
(
indexOf
<
0
)
{
index
++
;
continue
;
// no match
}
// Character Match Bonus
score
+=
1
;
// Same Case Bonous
if
(
target
[
indexOf
]
===
query
[
indexOf
])
{
score
+=
1
;
}
// Upper Case Bonus
if
(
isUpper
(
target
.
charCodeAt
(
indexOf
)))
{
score
+=
1
;
}
// Prefix Bonus
if
(
indexOf
===
0
)
{
score
+=
8
;
}
// Start of Word/Path Bonous
if
(
wordPathBoundary
.
some
(
w
=>
w
===
target
[
indexOf
-
1
]))
{
score
+=
7
;
}
index
++
;
}
return
score
;
}
function
isUpper
(
code
:
number
):
boolean
{
return
65
<=
code
&&
code
<=
90
;
}
\ No newline at end of file
src/vs/base/common/strings.ts
浏览文件 @
7eff5f7f
...
...
@@ -604,70 +604,4 @@ export var UTF8_BOM_CHARACTER = String.fromCharCode(__utf8_bom);
export
function
startsWithUTF8BOM
(
str
:
string
):
boolean
{
return
(
str
&&
str
.
length
>
0
&&
str
.
charCodeAt
(
0
)
===
__utf8_bom
);
}
/**
* Compute a score for the given string and the given query. Inspired by String Scoring Algorithm:
* http://joshaven.com/string_score
* https://github.com/joshaven/string_score
*
* Rules:
* Character score: 1
* Same case bonus: 1
* Upper case bonus: 1
* Start of word/path bonus: 7
* Start of string bonus: 8
*/
export
function
score
(
target
:
string
,
query
:
string
):
number
{
let
score
=
0
;
if
(
!
target
||
!
query
)
{
return
score
;
// return early if target or query are undefined
}
const
queryLen
=
query
.
length
;
const
targetLower
=
target
.
toLowerCase
();
const
queryLower
=
query
.
toLowerCase
();
const
wordPathBoundary
=
[
'
-
'
,
'
_
'
,
'
'
,
'
/
'
,
'
\\
'
];
let
index
=
0
;
while
(
index
<
queryLen
)
{
var
indexOf
=
targetLower
.
indexOf
(
queryLower
[
index
]);
if
(
indexOf
<
0
)
{
index
++
;
continue
;
// no match
}
// Character Match Bonus
score
+=
1
;
// Same Case Bonous
if
(
target
[
indexOf
]
===
query
[
indexOf
])
{
score
+=
1
;
}
// Upper Case Bonus
if
(
isUpper
(
target
.
charCodeAt
(
indexOf
)))
{
score
+=
1
;
}
// Prefix Bonus
if
(
indexOf
===
0
)
{
score
+=
8
;
}
// Start of Word/Path Bonous
if
(
wordPathBoundary
.
some
(
w
=>
w
===
target
[
indexOf
-
1
]))
{
score
+=
7
;
}
index
++
;
}
return
score
;
}
function
isUpper
(
code
:
number
):
boolean
{
return
65
<=
code
&&
code
<=
90
;
}
\ No newline at end of file
src/vs/base/test/common/scorer.test.ts
0 → 100644
浏览文件 @
7eff5f7f
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
scorer
=
require
(
'
vs/base/common/scorer
'
);
suite
(
'
Scorer
'
,
()
=>
{
test
(
"
score
"
,
function
()
{
const
target
=
'
HelLo-World
'
;
const
scores
=
[];
scores
.
push
(
scorer
.
score
(
target
,
'
HelLo-World
'
));
// direct case match
scores
.
push
(
scorer
.
score
(
target
,
'
hello-world
'
));
// direct mix-case match
scores
.
push
(
scorer
.
score
(
target
,
'
HW
'
));
// direct case prefix (multiple)
scores
.
push
(
scorer
.
score
(
target
,
'
H
'
));
// direct case prefix
scores
.
push
(
scorer
.
score
(
target
,
'
hw
'
));
// direct mix-case prefix (multiple)
scores
.
push
(
scorer
.
score
(
target
,
'
h
'
));
// direct mix-case prefix
scores
.
push
(
scorer
.
score
(
target
,
'
W
'
));
// direct case word prefix
scores
.
push
(
scorer
.
score
(
target
,
'
w
'
));
// direct mix-case word prefix
scores
.
push
(
scorer
.
score
(
target
,
'
Ld
'
));
// in-string case match (multiple)
scores
.
push
(
scorer
.
score
(
target
,
'
L
'
));
// in-string case match
scores
.
push
(
scorer
.
score
(
target
,
'
ld
'
));
// in-string mix-case match
scores
.
push
(
scorer
.
score
(
target
,
'
l
'
));
// in-string mix-case match
scores
.
push
(
scorer
.
score
(
target
,
'
4
'
));
// no match
// Assert scoring order
let
sortedScores
=
scores
.
sort
();
assert
.
deepEqual
(
scores
.
reverse
(),
sortedScores
);
});
});
\ No newline at end of file
src/vs/base/test/common/strings.test.ts
浏览文件 @
7eff5f7f
...
...
@@ -180,27 +180,4 @@ suite('Strings', () => {
assert
.
strictEqual
(
strings
.
localeCompare
(
'
A
'
,
'
a
'
),
'
A
'
.
localeCompare
(
'
a
'
));
assert
.
strictEqual
(
strings
.
localeCompare
(
'
a
'
,
'
A
'
),
'
a
'
.
localeCompare
(
'
A
'
));
});
test
(
"
scorer
"
,
function
()
{
const
target
=
'
HelLo-World
'
;
const
scores
=
[];
scores
.
push
(
strings
.
score
(
target
,
'
HelLo-World
'
));
// direct case match
scores
.
push
(
strings
.
score
(
target
,
'
hello-world
'
));
// direct mix-case match
scores
.
push
(
strings
.
score
(
target
,
'
HW
'
));
// direct case prefix (multiple)
scores
.
push
(
strings
.
score
(
target
,
'
H
'
));
// direct case prefix
scores
.
push
(
strings
.
score
(
target
,
'
hw
'
));
// direct mix-case prefix (multiple)
scores
.
push
(
strings
.
score
(
target
,
'
h
'
));
// direct mix-case prefix
scores
.
push
(
strings
.
score
(
target
,
'
W
'
));
// direct case word prefix
scores
.
push
(
strings
.
score
(
target
,
'
w
'
));
// direct mix-case word prefix
scores
.
push
(
strings
.
score
(
target
,
'
Ld
'
));
// in-string case match (multiple)
scores
.
push
(
strings
.
score
(
target
,
'
L
'
));
// in-string case match
scores
.
push
(
strings
.
score
(
target
,
'
ld
'
));
// in-string mix-case match
scores
.
push
(
strings
.
score
(
target
,
'
l
'
));
// in-string mix-case match
scores
.
push
(
strings
.
score
(
target
,
'
4
'
));
// no match
// Assert scoring order
let
sortedScores
=
scores
.
sort
();
assert
.
deepEqual
(
scores
.
reverse
(),
sortedScores
);
});
});
\ No newline at end of file
src/vs/workbench/parts/search/browser/openAnythingHandler.ts
浏览文件 @
7eff5f7f
...
...
@@ -10,6 +10,7 @@ import nls = require('vs/nls');
import
{
ThrottledDelayer
}
from
'
vs/base/common/async
'
;
import
types
=
require
(
'
vs/base/common/types
'
);
import
strings
=
require
(
'
vs/base/common/strings
'
);
import
scorer
=
require
(
'
vs/base/common/scorer
'
);
import
paths
=
require
(
'
vs/base/common/paths
'
);
import
filters
=
require
(
'
vs/base/common/filters
'
);
import
labels
=
require
(
'
vs/base/common/labels
'
);
...
...
@@ -292,15 +293,15 @@ export class OpenAnythingHandler extends QuickOpenHandler {
// Fuzzy scoring is special
if
(
enableFuzzyScoring
)
{
const
labelAScore
=
s
trings
.
score
(
elementA
.
getLabel
(),
lookFor
);
const
labelBScore
=
s
trings
.
score
(
elementB
.
getLabel
(),
lookFor
);
const
labelAScore
=
s
corer
.
score
(
elementA
.
getLabel
(),
lookFor
);
const
labelBScore
=
s
corer
.
score
(
elementB
.
getLabel
(),
lookFor
);
if
(
labelAScore
!==
labelBScore
)
{
return
labelAScore
>
labelBScore
?
-
1
:
1
;
}
const
descriptionAScore
=
s
trings
.
score
(
elementA
.
getDescription
(),
lookFor
);
const
descriptionBScore
=
s
trings
.
score
(
elementB
.
getDescription
(),
lookFor
);
const
descriptionAScore
=
s
corer
.
score
(
elementA
.
getDescription
(),
lookFor
);
const
descriptionBScore
=
s
corer
.
score
(
elementB
.
getDescription
(),
lookFor
);
if
(
descriptionAScore
!==
descriptionBScore
)
{
return
descriptionAScore
>
descriptionBScore
?
-
1
:
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录