Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
ef88842d
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
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,发现更多精彩内容 >>
提交
ef88842d
编写于
6月 14, 2019
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
completion model isn't dispoable but the suggest model that requests items, #75106
上级
466b29a0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
45 addition
and
34 deletion
+45
-34
src/vs/editor/contrib/suggest/completionModel.ts
src/vs/editor/contrib/suggest/completionModel.ts
+1
-14
src/vs/editor/contrib/suggest/suggestController.ts
src/vs/editor/contrib/suggest/suggestController.ts
+7
-1
src/vs/editor/contrib/suggest/suggestModel.ts
src/vs/editor/contrib/suggest/suggestModel.ts
+30
-17
src/vs/editor/contrib/suggest/test/suggestModel.test.ts
src/vs/editor/contrib/suggest/test/suggestModel.test.ts
+7
-2
未找到文件。
src/vs/editor/contrib/suggest/completionModel.ts
浏览文件 @
ef88842d
...
...
@@ -4,8 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import
{
fuzzyScore
,
fuzzyScoreGracefulAggressive
,
FuzzyScorer
,
FuzzyScore
,
anyScore
}
from
'
vs/base/common/filters
'
;
import
{
isDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
CompletionList
,
CompletionItemProvider
,
CompletionItemKind
}
from
'
vs/editor/common/modes
'
;
import
{
CompletionItemProvider
,
CompletionItemKind
}
from
'
vs/editor/common/modes
'
;
import
{
CompletionItem
}
from
'
./suggest
'
;
import
{
InternalSuggestOptions
,
EDITOR_DEFAULTS
}
from
'
vs/editor/common/config/editorOptions
'
;
import
{
WordDistance
}
from
'
vs/editor/contrib/suggest/wordDistance
'
;
...
...
@@ -75,18 +74,6 @@ export class CompletionModel {
}
}
dispose
():
void
{
const
seen
=
new
Set
<
CompletionList
>
();
for
(
const
{
container
}
of
this
.
_items
)
{
if
(
!
seen
.
has
(
container
))
{
seen
.
add
(
container
);
if
(
isDisposable
(
container
))
{
container
.
dispose
();
}
}
}
}
get
lineContext
():
LineContext
{
return
this
.
_lineContext
;
}
...
...
src/vs/editor/contrib/suggest/suggestController.ts
浏览文件 @
ef88842d
...
...
@@ -135,6 +135,7 @@ export class SuggestController implements IEditorContribution {
this
.
_toDispose
.
push
(
this
.
_editor
.
onDidBlurEditorWidget
(()
=>
{
if
(
!
this
.
_sticky
)
{
this
.
_model
.
cancel
();
this
.
_model
.
clear
();
}
}));
...
...
@@ -165,6 +166,7 @@ export class SuggestController implements IEditorContribution {
if
(
!
event
||
!
event
.
item
)
{
this
.
_alternatives
.
getValue
().
reset
();
this
.
_model
.
cancel
();
this
.
_model
.
clear
();
return
;
}
if
(
!
this
.
_editor
.
hasModel
())
{
...
...
@@ -213,6 +215,7 @@ export class SuggestController implements IEditorContribution {
if
(
!
suggestion
.
command
)
{
// done
this
.
_model
.
cancel
();
this
.
_model
.
clear
();
}
else
if
(
suggestion
.
command
.
id
===
TriggerSuggestAction
.
id
)
{
// retigger
...
...
@@ -220,7 +223,9 @@ export class SuggestController implements IEditorContribution {
}
else
{
// exec command, done
this
.
_commandService
.
executeCommand
(
suggestion
.
command
.
id
,
...(
suggestion
.
command
.
arguments
?
[...
suggestion
.
command
.
arguments
]
:
[])).
catch
(
onUnexpectedError
);
this
.
_commandService
.
executeCommand
(
suggestion
.
command
.
id
,
...(
suggestion
.
command
.
arguments
?
[...
suggestion
.
command
.
arguments
]
:
[]))
.
catch
(
onUnexpectedError
)
.
finally
(()
=>
this
.
_model
.
clear
());
// <- clear only now, keep commands alive
this
.
_model
.
cancel
();
}
...
...
@@ -340,6 +345,7 @@ export class SuggestController implements IEditorContribution {
cancelSuggestWidget
():
void
{
this
.
_model
.
cancel
();
this
.
_model
.
clear
();
this
.
_widget
.
getValue
().
hideWidget
();
}
...
...
src/vs/editor/contrib/suggest/suggestModel.ts
浏览文件 @
ef88842d
...
...
@@ -7,7 +7,7 @@ import { isNonEmptyArray } from 'vs/base/common/arrays';
import
{
TimeoutTimer
}
from
'
vs/base/common/async
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
IDisposable
,
dispose
,
DisposableStore
,
Mutable
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IDisposable
,
dispose
,
DisposableStore
,
is
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
CursorChangeReason
,
ICursorSelectionChangedEvent
}
from
'
vs/editor/common/controller/cursorEvents
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
...
...
@@ -101,7 +101,8 @@ export class SuggestModel implements IDisposable {
private
_context
?:
LineContext
;
private
_currentSelection
:
Selection
;
private
readonly
_completionModel
=
new
MutableDisposable
<
CompletionModel
>
();
private
_completionModel
:
CompletionModel
|
undefined
;
private
readonly
_completionDisposables
=
new
DisposableStore
();
private
readonly
_onDidCancel
=
new
Emitter
<
ICancelEvent
>
();
private
readonly
_onDidTrigger
=
new
Emitter
<
ITriggerEvent
>
();
private
readonly
_onDidSuggest
=
new
Emitter
<
ISuggestEvent
>
();
...
...
@@ -162,7 +163,7 @@ export class SuggestModel implements IDisposable {
dispose
():
void
{
dispose
([
this
.
_onDidCancel
,
this
.
_onDidSuggest
,
this
.
_onDidTrigger
,
this
.
_triggerCharacterListener
,
this
.
_triggerQuickSuggest
]);
this
.
_toDispose
.
dispose
();
this
.
_completion
Model
.
dispose
();
this
.
_completion
Disposables
.
dispose
();
this
.
cancel
();
}
...
...
@@ -206,8 +207,8 @@ export class SuggestModel implements IDisposable {
if
(
supports
)
{
// keep existing items that where not computed by the
// supports/providers that want to trigger now
const
items
:
CompletionItem
[]
|
undefined
=
this
.
_completionModel
.
value
?
this
.
_completionModel
.
value
.
adopt
(
supports
)
:
undefined
;
this
.
trigger
({
auto
:
true
,
shy
:
false
,
triggerCharacter
:
lastChar
},
Boolean
(
this
.
_completionModel
.
value
),
supports
,
items
);
const
items
:
CompletionItem
[]
|
undefined
=
this
.
_completionModel
?
this
.
_completionModel
.
adopt
(
supports
)
:
undefined
;
this
.
trigger
({
auto
:
true
,
shy
:
false
,
triggerCharacter
:
lastChar
},
Boolean
(
this
.
_completionModel
),
supports
,
items
);
}
});
}
...
...
@@ -226,12 +227,16 @@ export class SuggestModel implements IDisposable {
this
.
_requestToken
=
undefined
;
}
this
.
_state
=
State
.
Idle
;
this
.
_completionModel
.
clear
()
;
this
.
_completionModel
=
undefined
;
this
.
_context
=
undefined
;
this
.
_onDidCancel
.
fire
({
retrigger
});
}
}
clear
()
{
this
.
_completionDisposables
.
clear
();
}
private
_updateActiveSuggestSession
():
void
{
if
(
this
.
_state
!==
State
.
Idle
)
{
if
(
!
this
.
_editor
.
hasModel
()
||
!
CompletionProviderRegistry
.
has
(
this
.
_editor
.
getModel
()))
{
...
...
@@ -434,13 +439,21 @@ export class SuggestModel implements IDisposable {
}
const
ctx
=
new
LineContext
(
model
,
this
.
_editor
.
getPosition
(),
auto
,
context
.
shy
);
this
.
_completionModel
.
value
=
new
CompletionModel
(
items
,
this
.
_context
!
.
column
,
{
this
.
_completionModel
=
new
CompletionModel
(
items
,
this
.
_context
!
.
column
,
{
leadingLineContent
:
ctx
.
leadingLineContent
,
characterCountDelta
:
ctx
.
column
-
this
.
_context
!
.
column
},
wordDistance
,
this
.
_editor
.
getConfiguration
().
contribInfo
.
suggest
);
// store containers so that they can be disposed later
for
(
const
item
of
items
)
{
if
(
isDisposable
(
item
.
container
))
{
this
.
_completionDisposables
.
add
(
item
.
container
);
}
}
this
.
_onNewContext
(
ctx
);
}).
catch
(
onUnexpectedError
);
...
...
@@ -475,28 +488,28 @@ export class SuggestModel implements IDisposable {
return
;
}
if
(
!
this
.
_completionModel
.
value
)
{
if
(
!
this
.
_completionModel
)
{
// happens when IntelliSense is not yet computed
return
;
}
if
(
ctx
.
column
>
this
.
_context
.
column
&&
this
.
_completionModel
.
value
.
incomplete
.
size
>
0
&&
ctx
.
leadingWord
.
word
.
length
!==
0
)
{
if
(
ctx
.
column
>
this
.
_context
.
column
&&
this
.
_completionModel
.
incomplete
.
size
>
0
&&
ctx
.
leadingWord
.
word
.
length
!==
0
)
{
// typed -> moved cursor RIGHT & incomple model & still on a word -> retrigger
const
{
incomplete
}
=
this
.
_completionModel
.
value
;
const
adopted
=
this
.
_completionModel
.
value
.
adopt
(
incomplete
);
const
{
incomplete
}
=
this
.
_completionModel
;
const
adopted
=
this
.
_completionModel
.
adopt
(
incomplete
);
this
.
trigger
({
auto
:
this
.
_state
===
State
.
Auto
,
shy
:
false
},
true
,
incomplete
,
adopted
);
}
else
{
// typed -> moved cursor RIGHT -> update UI
let
oldLineContext
=
this
.
_completionModel
.
value
.
lineContext
;
let
oldLineContext
=
this
.
_completionModel
.
lineContext
;
let
isFrozen
=
false
;
this
.
_completionModel
.
value
.
lineContext
=
{
this
.
_completionModel
.
lineContext
=
{
leadingLineContent
:
ctx
.
leadingLineContent
,
characterCountDelta
:
ctx
.
column
-
this
.
_context
.
column
};
if
(
this
.
_completionModel
.
value
.
items
.
length
===
0
)
{
if
(
this
.
_completionModel
.
items
.
length
===
0
)
{
if
(
LineContext
.
shouldAutoTrigger
(
this
.
_editor
)
&&
this
.
_context
.
leadingWord
.
endColumn
<
ctx
.
leadingWord
.
startColumn
)
{
// retrigger when heading into a new word
...
...
@@ -506,8 +519,8 @@ export class SuggestModel implements IDisposable {
if
(
!
this
.
_context
.
auto
)
{
// freeze when IntelliSense was manually requested
this
.
_completionModel
.
value
.
lineContext
=
oldLineContext
;
isFrozen
=
this
.
_completionModel
.
value
.
items
.
length
>
0
;
this
.
_completionModel
.
lineContext
=
oldLineContext
;
isFrozen
=
this
.
_completionModel
.
items
.
length
>
0
;
if
(
isFrozen
&&
ctx
.
leadingWord
.
word
.
length
===
0
)
{
// there were results before but now there aren't
...
...
@@ -524,7 +537,7 @@ export class SuggestModel implements IDisposable {
}
this
.
_onDidSuggest
.
fire
({
completionModel
:
this
.
_completionModel
.
value
,
completionModel
:
this
.
_completionModel
,
auto
:
this
.
_context
.
auto
,
shy
:
this
.
_context
.
shy
,
isFrozen
,
...
...
src/vs/editor/contrib/suggest/test/suggestModel.test.ts
浏览文件 @
ef88842d
...
...
@@ -221,6 +221,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
try
{
action
();
}
catch
(
err
)
{
sub
.
dispose
();
reject
(
err
);
}
});
...
...
@@ -776,9 +777,13 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
},
event
=>
{
assert
.
equal
(
event
.
auto
,
true
);
assert
.
equal
(
event
.
completionModel
.
items
.
length
,
2
);
assert
.
equal
(
disposeA
,
1
);
assert
.
equal
(
disposeB
,
0
);
// clean up
model
.
clear
();
assert
.
equal
(
disposeA
,
2
);
// provide got called two times!
assert
.
equal
(
disposeB
,
1
);
});
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录