Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
03e88fd3
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,发现更多精彩内容 >>
提交
03e88fd3
编写于
1月 04, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename Context to LineContext, more simplifications
上级
7f967892
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
17 addition
and
26 deletion
+17
-26
src/vs/editor/contrib/suggest/common/suggestModel.ts
src/vs/editor/contrib/suggest/common/suggestModel.ts
+12
-21
src/vs/editor/contrib/suggest/test/common/suggestModel.test.ts
...s/editor/contrib/suggest/test/common/suggestModel.test.ts
+5
-5
未找到文件。
src/vs/editor/contrib/suggest/common/suggestModel.ts
浏览文件 @
03e88fd3
...
...
@@ -30,7 +30,7 @@ export interface ISuggestEvent {
auto
:
boolean
;
}
export
class
Context
{
export
class
Line
Context
{
static
shouldAutoTrigger
(
editor
:
ICommonCodeEditor
):
boolean
{
const
model
=
editor
.
getModel
();
...
...
@@ -65,26 +65,17 @@ export class Context {
readonly
lineNumber
:
number
;
readonly
column
:
number
;
readonly
lineContentBefore
:
string
;
readonly
wordBefore
:
string
;
constructor
(
model
:
IModel
,
position
:
IPosition
,
private
auto
:
boolean
)
{
const
lineContent
=
model
.
getLineContent
(
position
.
lineNumber
);
const
wordUnderCursor
=
model
.
getWordAtPosition
(
position
);
if
(
wordUnderCursor
)
{
this
.
wordBefore
=
lineContent
.
substring
(
wordUnderCursor
.
startColumn
-
1
,
position
.
column
-
1
);
}
else
{
this
.
wordBefore
=
''
;
}
this
.
lineContentBefore
=
model
.
getLineContent
(
position
.
lineNumber
).
substr
(
0
,
position
.
column
-
1
);
this
.
wordBefore
=
model
.
getWordUntilPosition
(
position
).
word
;
this
.
lineNumber
=
position
.
lineNumber
;
this
.
column
=
position
.
column
;
this
.
lineContentBefore
=
lineContent
.
substr
(
0
,
position
.
column
-
1
);
}
isDifferentContext
(
context
:
Context
):
boolean
{
isDifferentContext
(
context
:
Line
Context
):
boolean
{
if
(
this
.
lineNumber
!==
context
.
lineNumber
)
{
// Line number has changed
return
true
;
...
...
@@ -108,7 +99,7 @@ export class Context {
return
false
;
}
shouldRetrigger
(
context
:
Context
):
boolean
{
shouldRetrigger
(
context
:
Line
Context
):
boolean
{
if
(
!
startsWith
(
this
.
lineContentBefore
,
context
.
lineContentBefore
))
{
// Doesn't look like the same line
return
false
;
...
...
@@ -144,7 +135,7 @@ export class SuggestModel implements IDisposable {
private
state
:
State
;
private
requestPromise
:
TPromise
<
void
>
;
private
context
:
Context
;
private
context
:
Line
Context
;
private
completionModel
:
CompletionModel
;
...
...
@@ -294,7 +285,7 @@ export class SuggestModel implements IDisposable {
if
(
this
.
editor
.
getConfiguration
().
contribInfo
.
quickSuggestions
)
{
// trigger suggest from idle when configured to do so
this
.
cancel
();
if
(
Context
.
shouldAutoTrigger
(
this
.
editor
))
{
if
(
Line
Context
.
shouldAutoTrigger
(
this
.
editor
))
{
this
.
triggerAutoSuggestPromise
=
TPromise
.
timeout
(
this
.
quickSuggestDelay
);
this
.
triggerAutoSuggestPromise
.
then
(()
=>
{
this
.
triggerAutoSuggestPromise
=
null
;
...
...
@@ -305,7 +296,7 @@ export class SuggestModel implements IDisposable {
}
else
{
// refine active suggestion
const
ctx
=
new
Context
(
model
,
this
.
editor
.
getPosition
(),
false
);
const
ctx
=
new
Line
Context
(
model
,
this
.
editor
.
getPosition
(),
false
);
this
.
onNewContext
(
ctx
);
}
}
...
...
@@ -318,9 +309,9 @@ export class SuggestModel implements IDisposable {
return
;
}
const
ctx
=
new
Context
(
model
,
this
.
editor
.
getPosition
(),
auto
);
const
ctx
=
new
Line
Context
(
model
,
this
.
editor
.
getPosition
(),
auto
);
if
(
!
Context
.
isInEditableRange
(
this
.
editor
))
{
if
(
!
Line
Context
.
isInEditableRange
(
this
.
editor
))
{
return
;
}
...
...
@@ -351,7 +342,7 @@ export class SuggestModel implements IDisposable {
items
=
items
.
concat
(
existingItems
).
sort
(
cmpFn
);
}
const
ctx
=
new
Context
(
model
,
this
.
editor
.
getPosition
(),
auto
);
const
ctx
=
new
Line
Context
(
model
,
this
.
editor
.
getPosition
(),
auto
);
this
.
completionModel
=
new
CompletionModel
(
items
,
this
.
context
.
column
,
{
leadingLineContent
:
ctx
.
lineContentBefore
,
characterCountDelta
:
this
.
context
?
ctx
.
column
-
this
.
context
.
column
:
0
...
...
@@ -361,7 +352,7 @@ export class SuggestModel implements IDisposable {
}).
then
(
null
,
onUnexpectedError
);
}
private
onNewContext
(
ctx
:
Context
):
void
{
private
onNewContext
(
ctx
:
Line
Context
):
void
{
if
(
this
.
context
&&
this
.
context
.
isDifferentContext
(
ctx
))
{
if
(
this
.
context
.
shouldRetrigger
(
ctx
))
{
this
.
trigger
(
this
.
state
===
State
.
Auto
,
true
);
...
...
src/vs/editor/contrib/suggest/test/common/suggestModel.test.ts
浏览文件 @
03e88fd3
...
...
@@ -12,7 +12,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import
{
Model
}
from
'
vs/editor/common/model/model
'
;
import
{
ICommonCodeEditor
,
Handler
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ISuggestSupport
,
ISuggestResult
,
SuggestRegistry
}
from
'
vs/editor/common/modes
'
;
import
{
SuggestModel
,
Context
}
from
'
vs/editor/contrib/suggest/common/suggestModel
'
;
import
{
SuggestModel
,
Line
Context
}
from
'
vs/editor/contrib/suggest/common/suggestModel
'
;
import
{
MockCodeEditor
,
MockScopeLocation
}
from
'
vs/editor/test/common/mocks/mockCodeEditor
'
;
import
{
ServiceCollection
}
from
'
vs/platform/instantiation/common/serviceCollection
'
;
import
{
InstantiationService
}
from
'
vs/platform/instantiation/common/instantiationService
'
;
...
...
@@ -51,7 +51,7 @@ suite('SuggestModel - Context', function () {
const
pos
=
model
.
getPositionAt
(
offset
);
const
editor
=
createMockEditor
(
model
);
editor
.
setPosition
(
pos
);
assert
.
equal
(
Context
.
shouldAutoTrigger
(
editor
),
expected
);
assert
.
equal
(
Line
Context
.
shouldAutoTrigger
(
editor
),
expected
);
editor
.
dispose
();
}
...
...
@@ -64,13 +64,13 @@ suite('SuggestModel - Context', function () {
test
(
'
Context - isDifferentContext
'
,
function
()
{
// different line
const
ctx
=
new
Context
(
model
,
{
lineNumber
:
1
,
column
:
8
},
true
);
// Das Pfer|d
assert
.
equal
(
ctx
.
isDifferentContext
(
new
Context
(
model
,
{
lineNumber
:
2
,
column
:
1
},
true
)),
true
);
const
ctx
=
new
Line
Context
(
model
,
{
lineNumber
:
1
,
column
:
8
},
true
);
// Das Pfer|d
assert
.
equal
(
ctx
.
isDifferentContext
(
new
Line
Context
(
model
,
{
lineNumber
:
2
,
column
:
1
},
true
)),
true
);
function
createEndContext
(
value
:
string
)
{
const
model
=
Model
.
createFromString
(
value
);
const
ctx
=
new
Context
(
model
,
model
.
getPositionAt
(
value
.
length
),
true
);
// Das Pfer|d
const
ctx
=
new
Line
Context
(
model
,
model
.
getPositionAt
(
value
.
length
),
true
);
// Das Pfer|d
return
ctx
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录