Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
3c6f232d
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,发现更多精彩内容 >>
提交
3c6f232d
编写于
10月 27, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
revert heuristics change, more tests, #14583
上级
3469ee49
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
42 addition
and
66 deletion
+42
-66
src/vs/editor/contrib/suggest/common/completionModel.ts
src/vs/editor/contrib/suggest/common/completionModel.ts
+9
-21
src/vs/editor/contrib/suggest/test/common/completionModel.test.ts
...ditor/contrib/suggest/test/common/completionModel.test.ts
+33
-45
未找到文件。
src/vs/editor/contrib/suggest/common/completionModel.ts
浏览文件 @
3c6f232d
...
...
@@ -6,7 +6,6 @@
'
use strict
'
;
import
{
isFalsyOrEmpty
}
from
'
vs/base/common/arrays
'
;
import
{
escapeRegExpCharacters
}
from
'
vs/base/common/strings
'
;
import
{
IMatch
,
fuzzyContiguousFilter
}
from
'
vs/base/common/filters
'
;
import
{
ISuggestSupport
}
from
'
vs/editor/common/modes
'
;
import
{
ISuggestionItem
}
from
'
./suggest
'
;
...
...
@@ -155,7 +154,7 @@ export class CompletionModel {
this
.
_filteredItems
.
push
(
item
);
// compute score against word
const
score
=
CompletionModel
.
_scoreByHighlight
(
item
,
word
);
const
score
=
CompletionModel
.
_scoreByHighlight
(
item
,
word
,
word
.
toLowerCase
()
);
if
(
score
>
topScore
)
{
topScore
=
score
;
this
.
_topScoreIdx
=
this
.
_filteredItems
.
length
-
1
;
...
...
@@ -176,30 +175,19 @@ export class CompletionModel {
}
}
private
static
_scoreByHighlight
(
item
:
ICompletionItem
,
currentWord
:
string
):
number
{
private
static
_scoreByHighlight
(
item
:
ICompletionItem
,
currentWord
:
string
,
currentWordLowerCase
:
string
):
number
{
const
{
highlights
,
suggestion
}
=
item
;
let
score
=
0
;
if
(
!
isFalsyOrEmpty
(
highlights
))
{
for
(
const
{
start
,
end
}
of
highlights
)
{
// scoring logic:
// First find the highlighted portion from the label in the current
// word and second score a case-senstive match with 2pts and everything
// else with 1pt.
// this is a case-insensitive String#indexOf
// find the highlight in the current word and
// score it based on case-match and start index
const
part
=
suggestion
.
label
.
substring
(
start
,
end
);
const
regexp
=
new
RegExp
(
escapeRegExpCharacters
(
part
),
'
i
'
);
const
idx
=
currentWord
.
search
(
regexp
);
// case senstive match score 2, the rest 1
if
(
idx
>=
0
)
{
for
(
let
i
=
0
;
i
<
part
.
length
;
i
++
)
{
if
(
part
[
i
]
===
currentWord
[
idx
+
i
])
{
score
+=
2
;
}
else
{
score
+=
1
;
}
}
if
(
currentWord
.
indexOf
(
part
)
>=
0
)
{
score
+=
(
2
*
part
.
length
)
/
(
start
+
1
);
}
else
if
(
currentWordLowerCase
.
indexOf
(
part
)
>=
0
)
{
score
+=
part
.
length
/
(
start
+
1
);
}
}
}
...
...
src/vs/editor/contrib/suggest/test/common/completionModel.test.ts
浏览文件 @
3c6f232d
...
...
@@ -74,51 +74,6 @@ suite('CompletionModel', function () {
assert
.
ok
(
itemsNow
!==
itemsThen
);
});
test
(
'
top score
'
,
function
()
{
assert
.
equal
(
model
.
topScoreIdx
,
0
);
model
.
lineContext
=
{
leadingLineContent
:
'
Foo
'
,
characterCountDelta
:
0
};
assert
.
equal
(
model
.
topScoreIdx
,
1
);
});
test
(
'
top score, issue #14446
'
,
function
()
{
const
model
=
new
CompletionModel
([
createSuggestItem
(
'
workbench.editor.defaultSideBySideLayout
'
,
15
),
createSuggestItem
(
'
workbench.sideBar.location
'
,
15
),
],
15
,
{
leadingLineContent
:
'
workbench.sideb
'
,
characterCountDelta
:
0
}
)
assert
.
equal
(
model
.
topScoreIdx
,
1
);
assert
.
equal
(
model
.
items
[
model
.
topScoreIdx
].
suggestion
.
label
,
'
workbench.sideBar.location
'
)
});
test
(
'
top score, issue #11423
'
,
function
()
{
const
model
=
new
CompletionModel
([
createSuggestItem
(
'
diffEditor.renderSideBySide
'
,
8
),
createSuggestItem
(
'
editor.overviewRulerlanes
'
,
8
),
createSuggestItem
(
'
editor.renderControlCharacter
'
,
8
),
createSuggestItem
(
'
editor.renderWhitespace
'
,
8
),
],
15
,
{
leadingLineContent
:
'
editor.r
'
,
characterCountDelta
:
0
}
)
assert
.
equal
(
model
.
topScoreIdx
,
2
);
assert
.
equal
(
model
.
items
[
model
.
topScoreIdx
].
suggestion
.
label
,
'
editor.renderControlCharacter
'
)
model
.
lineContext
=
{
leadingLineContent
:
'
editor.R
'
,
characterCountDelta
:
0
};
assert
.
equal
(
model
.
topScoreIdx
,
1
);
model
.
lineContext
=
{
leadingLineContent
:
'
Editor.r
'
,
characterCountDelta
:
0
};
assert
.
equal
(
model
.
topScoreIdx
,
0
);
});
test
(
'
complete/incomplete
'
,
function
()
{
...
...
@@ -152,4 +107,37 @@ suite('CompletionModel', function () {
assert
.
equal
(
model
.
incomplete
.
length
,
0
);
assert
.
equal
(
model
.
items
.
length
,
3
);
});
function
assertTopScore
(
lineContent
:
string
,
expected
:
number
,
...
suggestionLabels
:
string
[]):
void
{
const
model
=
new
CompletionModel
(
suggestionLabels
.
map
(
label
=>
createSuggestItem
(
label
,
lineContent
.
length
)),
lineContent
.
length
,
{
characterCountDelta
:
0
,
leadingLineContent
:
lineContent
}
);
assert
.
equal
(
model
.
topScoreIdx
,
expected
,
`
${
lineContent
}
, ACTUAL:
${
model
.
items
[
model
.
topScoreIdx
].
suggestion
.
label
}
<> EXPECTED:
${
model
.
items
[
expected
].
suggestion
.
label
}
`
);
}
test
(
'
top score
'
,
function
()
{
assertTopScore
(
'
Foo
'
,
1
,
'
foo
'
,
'
Foo
'
,
'
foo
'
);
// issue #14583
assertTopScore
(
'
log
'
,
3
,
'
HTMLOptGroupElement
'
,
'
ScrollLogicalPosition
'
,
'
SVGFEMorphologyElement
'
,
'
log
'
);
assertTopScore
(
'
e
'
,
2
,
'
AbstractWorker
'
,
'
ActiveXObject
'
,
'
else
'
);
// issue #14446
// assertTopScore('workbench.sideb', 1, 'workbench.editor.defaultSideBySideLayout', 'workbench.sideBar.location');
// issue #11423
assertTopScore
(
'
editor.r
'
,
2
,
'
diffEditor.renderSideBySide
'
,
'
editor.overviewRulerlanes
'
,
'
editor.renderControlCharacter
'
,
'
editor.renderWhitespace
'
);
assertTopScore
(
'
editor.R
'
,
1
,
'
diffEditor.renderSideBySide
'
,
'
editor.overviewRulerlanes
'
,
'
editor.renderControlCharacter
'
,
'
editor.renderWhitespace
'
);
// assertTopScore('Editor.r', 0, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录