Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
f04d2761
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,发现更多精彩内容 >>
提交
f04d2761
编写于
9月 21, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add word distance (by line) and rank suggestions by that
上级
20e3a158
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
92 addition
and
10 deletion
+92
-10
src/vs/editor/contrib/suggest/completionModel.ts
src/vs/editor/contrib/suggest/completionModel.ts
+14
-2
src/vs/editor/contrib/suggest/suggestController.ts
src/vs/editor/contrib/suggest/suggestController.ts
+3
-1
src/vs/editor/contrib/suggest/suggestModel.ts
src/vs/editor/contrib/suggest/suggestModel.ts
+13
-7
src/vs/editor/contrib/suggest/wordDistance.ts
src/vs/editor/contrib/suggest/wordDistance.ts
+62
-0
未找到文件。
src/vs/editor/contrib/suggest/completionModel.ts
浏览文件 @
f04d2761
...
...
@@ -10,11 +10,13 @@ import { isDisposable } from 'vs/base/common/lifecycle';
import
{
ISuggestResult
,
ISuggestSupport
}
from
'
vs/editor/common/modes
'
;
import
{
ISuggestionItem
}
from
'
./suggest
'
;
import
{
InternalSuggestOptions
,
EDITOR_DEFAULTS
}
from
'
vs/editor/common/config/editorOptions
'
;
import
{
WordDistance
}
from
'
vs/editor/contrib/suggest/wordDistance
'
;
export
interface
ICompletionItem
extends
ISuggestionItem
{
matches
?:
number
[];
score
?:
number
;
idx
?:
number
;
distance
?:
number
;
word
?:
string
;
}
...
...
@@ -58,7 +60,13 @@ export class CompletionModel {
private
_isIncomplete
:
Set
<
ISuggestSupport
>
;
private
_stats
:
ICompletionStats
;
constructor
(
items
:
ISuggestionItem
[],
column
:
number
,
lineContext
:
LineContext
,
options
:
InternalSuggestOptions
=
EDITOR_DEFAULTS
.
contribInfo
.
suggest
)
{
constructor
(
items
:
ISuggestionItem
[],
column
:
number
,
lineContext
:
LineContext
,
private
readonly
_wordDistanceOracle
:
WordDistance
,
options
:
InternalSuggestOptions
=
EDITOR_DEFAULTS
.
contribInfo
.
suggest
)
{
this
.
_items
=
items
;
this
.
_column
=
column
;
this
.
_options
=
options
;
...
...
@@ -209,7 +217,7 @@ export class CompletionModel {
}
item
.
idx
=
i
;
item
.
distance
=
this
.
_wordDistanceOracle
.
distance
(
item
.
position
,
suggestion
.
label
);
target
.
push
(
item
);
// update stats
...
...
@@ -229,6 +237,10 @@ export class CompletionModel {
return
-
1
;
}
else
if
(
a
.
score
<
b
.
score
)
{
return
1
;
}
else
if
(
a
.
distance
<
b
.
distance
)
{
return
-
1
;
}
else
if
(
a
.
distance
>
b
.
distance
)
{
return
1
;
}
else
if
(
a
.
idx
<
b
.
idx
)
{
return
-
1
;
}
else
if
(
a
.
idx
>
b
.
idx
)
{
...
...
src/vs/editor/contrib/suggest/suggestController.ts
浏览文件 @
f04d2761
...
...
@@ -32,6 +32,7 @@ import { State, SuggestModel } from './suggestModel';
import
{
ISelectedSuggestion
,
SuggestWidget
}
from
'
./suggestWidget
'
;
import
{
WordContextKey
}
from
'
vs/editor/contrib/suggest/wordContextKey
'
;
import
{
once
,
anyEvent
}
from
'
vs/base/common/event
'
;
import
{
IEditorWorkerService
}
from
'
vs/editor/common/services/editorWorkerService
'
;
class
AcceptOnCharacterOracle
{
...
...
@@ -97,12 +98,13 @@ export class SuggestController implements IEditorContribution {
constructor
(
private
_editor
:
ICodeEditor
,
@
IEditorWorkerService
editorWorker
:
IEditorWorkerService
,
@
ICommandService
private
readonly
_commandService
:
ICommandService
,
@
IContextKeyService
private
readonly
_contextKeyService
:
IContextKeyService
,
@
ITelemetryService
private
readonly
_telemetryService
:
ITelemetryService
,
@
IInstantiationService
private
readonly
_instantiationService
:
IInstantiationService
,
)
{
this
.
_model
=
new
SuggestModel
(
this
.
_editor
);
this
.
_model
=
new
SuggestModel
(
this
.
_editor
,
editorWorker
);
this
.
_memory
=
_instantiationService
.
createInstance
(
SuggestMemories
,
this
.
_editor
.
getConfiguration
().
contribInfo
.
suggestSelection
);
this
.
_alternatives
=
new
SuggestAlternatives
(
this
.
_editor
,
item
=>
this
.
_onDidSelectItem
(
item
,
false
,
false
),
this
.
_contextKeyService
);
...
...
src/vs/editor/contrib/suggest/suggestModel.ts
浏览文件 @
f04d2761
...
...
@@ -20,6 +20,8 @@ import { CompletionModel } from './completionModel';
import
{
ISuggestionItem
,
getSuggestionComparator
,
provideSuggestionItems
,
getSnippetSuggestSupport
}
from
'
./suggest
'
;
import
{
SnippetController2
}
from
'
vs/editor/contrib/snippet/snippetController2
'
;
import
{
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
import
{
IEditorWorkerService
}
from
'
vs/editor/common/services/editorWorkerService
'
;
import
{
WordDistance
}
from
'
vs/editor/contrib/suggest/wordDistance
'
;
export
interface
ICancelEvent
{
readonly
retrigger
:
boolean
;
...
...
@@ -91,13 +93,12 @@ export const enum State {
export
class
SuggestModel
implements
IDisposable
{
private
_editor
:
ICodeEditor
;
private
_toDispose
:
IDisposable
[]
=
[];
private
_quickSuggestDelay
:
number
;
private
_triggerCharacterListener
:
IDisposable
;
private
readonly
_triggerQuickSuggest
=
new
TimeoutTimer
();
private
readonly
_triggerRefilter
=
new
TimeoutTimer
();
private
_state
:
State
;
private
_state
:
State
=
State
.
Idle
;
private
_requestToken
:
CancellationTokenSource
;
private
_context
:
LineContext
;
...
...
@@ -112,9 +113,10 @@ export class SuggestModel implements IDisposable {
readonly
onDidTrigger
:
Event
<
ITriggerEvent
>
=
this
.
_onDidTrigger
.
event
;
readonly
onDidSuggest
:
Event
<
ISuggestEvent
>
=
this
.
_onDidSuggest
.
event
;
constructor
(
editor
:
ICodeEditor
)
{
this
.
_editor
=
editor
;
this
.
_state
=
State
.
Idle
;
constructor
(
private
readonly
_editor
:
ICodeEditor
,
private
readonly
_editorWorker
:
IEditorWorkerService
)
{
this
.
_completionModel
=
null
;
this
.
_context
=
null
;
this
.
_currentSelection
=
this
.
_editor
.
getSelection
()
||
new
Selection
(
1
,
1
,
1
,
1
);
...
...
@@ -385,15 +387,18 @@ export class SuggestModel implements IDisposable {
this
.
_requestToken
=
new
CancellationTokenSource
();
provideSuggestionItems
(
let
wordDistance
=
WordDistance
.
create
(
this
.
_editorWorker
,
this
.
_editor
);
let
items
=
provideSuggestionItems
(
model
,
this
.
_editor
.
getPosition
(),
this
.
_editor
.
getConfiguration
().
contribInfo
.
suggest
.
snippets
,
onlyFrom
,
suggestCtx
,
this
.
_requestToken
.
token
);
).
then
(
items
=>
{
Promise
.
all
([
items
,
wordDistance
]).
then
(([
items
,
wordDistance
])
=>
{
this
.
_requestToken
.
dispose
();
...
...
@@ -416,6 +421,7 @@ export class SuggestModel implements IDisposable {
leadingLineContent
:
ctx
.
leadingLineContent
,
characterCountDelta
:
this
.
_context
?
ctx
.
column
-
this
.
_context
.
column
:
0
},
wordDistance
,
this
.
_editor
.
getConfiguration
().
contribInfo
.
suggest
);
this
.
_onNewContext
(
ctx
);
...
...
src/vs/editor/contrib/suggest/wordDistance.ts
0 → 100644
浏览文件 @
f04d2761
/*---------------------------------------------------------------------------------------------
* 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
{
binarySearch
}
from
'
vs/base/common/arrays
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
IEditorWorkerService
}
from
'
vs/editor/common/services/editorWorkerService
'
;
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
export
abstract
class
WordDistance
{
static
create
(
service
:
IEditorWorkerService
,
editor
:
ICodeEditor
):
Thenable
<
WordDistance
>
{
const
model
=
editor
.
getModel
();
const
position
=
editor
.
getPosition
();
return
service
.
getWordRanges
(
model
.
uri
,
position
).
then
(
data
=>
{
return
new
class
extends
WordDistance
{
distance
(
anchor
:
IPosition
,
word
:
string
)
{
if
(
!
data
||
!
position
.
equals
(
editor
.
getPosition
()))
{
return
0
;
}
let
lineNumbers
=
new
Map
<
string
,
number
[]
>
();
if
(
!
lineNumbers
.
has
(
word
))
{
let
wordLineNumbers
:
number
[];
let
ranges
=
data
[
word
];
if
(
ranges
)
{
wordLineNumbers
=
ranges
.
map
(
range
=>
range
.
startLineNumber
);
wordLineNumbers
=
wordLineNumbers
.
sort
();
}
lineNumbers
.
set
(
word
,
wordLineNumbers
);
delete
data
[
word
];
}
let
offset
=
lineNumbers
.
get
(
word
);
if
(
!
offset
)
{
return
Number
.
MAX_VALUE
;
}
let
idx
=
binarySearch
(
offset
,
anchor
.
lineNumber
,
(
a
,
b
)
=>
a
-
b
);
if
(
idx
>=
0
)
{
return
0
;
}
else
{
idx
=
~
idx
;
idx
%=
offset
.
length
;
return
Math
.
abs
(
offset
[
idx
]
-
anchor
.
lineNumber
);
}
}
};
});
}
abstract
distance
(
anchor
:
IPosition
,
word
:
string
):
number
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录