Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
3c99c244
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,发现更多精彩内容 >>
提交
3c99c244
编写于
7月 04, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt - async winjs.promise, add cancelation token
上级
5ef47e74
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
45 deletion
+37
-45
src/vs/editor/contrib/suggest/suggest.ts
src/vs/editor/contrib/suggest/suggest.ts
+9
-10
src/vs/editor/contrib/suggest/suggestWidget.ts
src/vs/editor/contrib/suggest/suggestWidget.ts
+28
-35
未找到文件。
src/vs/editor/contrib/suggest/suggest.ts
浏览文件 @
3c99c244
...
...
@@ -3,12 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
asWinJsPromise
,
first2
}
from
'
vs/base/common/async
'
;
import
{
first2
}
from
'
vs/base/common/async
'
;
import
{
isFalsyOrEmpty
}
from
'
vs/base/common/arrays
'
;
import
{
compareIgnoreCase
}
from
'
vs/base/common/strings
'
;
import
{
assign
}
from
'
vs/base/common/objects
'
;
import
{
onUnexpectedExternalError
}
from
'
vs/base/common/errors
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IEditorContribution
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
import
{
registerDefaultLanguageCommand
}
from
'
vs/editor/browser/editorExtensions
'
;
...
...
@@ -31,7 +30,7 @@ export interface ISuggestionItem {
suggestion
:
ISuggestion
;
container
:
ISuggestResult
;
support
:
ISuggestSupport
;
resolve
(
):
TPromis
e
<
void
>
;
resolve
(
token
:
CancellationToken
):
Thenabl
e
<
void
>
;
}
export
type
SnippetConfig
=
'
top
'
|
'
bottom
'
|
'
inline
'
|
'
none
'
;
...
...
@@ -133,13 +132,13 @@ function fixOverwriteBeforeAfter(suggestion: ISuggestion, container: ISuggestRes
}
}
function
createSuggestionResolver
(
provider
:
ISuggestSupport
,
suggestion
:
ISuggestion
,
model
:
ITextModel
,
position
:
Position
):
(
)
=>
T
Promise
<
void
>
{
return
()
=>
{
function
createSuggestionResolver
(
provider
:
ISuggestSupport
,
suggestion
:
ISuggestion
,
model
:
ITextModel
,
position
:
Position
):
(
token
:
CancellationToken
)
=>
Promise
<
void
>
{
return
(
token
)
=>
{
if
(
typeof
provider
.
resolveCompletionItem
===
'
function
'
)
{
return
asWinJsPromise
(
token
=>
provider
.
resolveCompletionItem
(
model
,
position
,
suggestion
,
token
))
.
then
(
value
=>
{
assign
(
suggestion
,
value
);
});
return
Promise
.
resolve
(
provider
.
resolveCompletionItem
(
model
,
position
,
suggestion
,
token
)).
then
(
value
=>
{
assign
(
suggestion
,
value
);
});
}
else
{
return
Promise
.
resolve
(
void
0
);
}
return
TPromise
.
as
(
void
0
);
};
}
...
...
@@ -221,13 +220,13 @@ registerDefaultLanguageCommand('_executeCompletionItemProvider', (model, positio
return
provideSuggestionItems
(
model
,
position
).
then
(
items
=>
{
for
(
const
item
of
items
)
{
if
(
resolving
.
length
<
maxItemsToResolve
)
{
resolving
.
push
(
item
.
resolve
());
resolving
.
push
(
item
.
resolve
(
CancellationToken
.
None
));
}
result
.
incomplete
=
result
.
incomplete
||
item
.
container
.
incomplete
;
result
.
suggestions
.
push
(
item
.
suggestion
);
}
}).
then
(()
=>
{
return
TPromise
.
join
(
resolving
);
return
Promise
.
all
(
resolving
);
}).
then
(()
=>
{
return
result
;
});
...
...
src/vs/editor/contrib/suggest/suggestWidget.ts
浏览文件 @
3c99c244
...
...
@@ -10,8 +10,7 @@ import * as nls from 'vs/nls';
import
{
createMatches
}
from
'
vs/base/common/filters
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
Event
,
Emitter
,
chain
}
from
'
vs/base/common/event
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
isPromiseCanceledError
,
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
IDisposable
,
dispose
,
toDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
addClass
,
append
,
$
,
hide
,
removeClass
,
show
,
toggleClass
,
getDomNodePagePosition
,
hasClass
}
from
'
vs/base/browser/dom
'
;
import
{
HighlightedLabel
}
from
'
vs/base/browser/ui/highlightedlabel/highlightedLabel
'
;
...
...
@@ -33,6 +32,8 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag
import
{
MarkdownRenderer
}
from
'
vs/editor/contrib/markdown/markdownRenderer
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
IOpenerService
}
from
'
vs/platform/opener/common/opener
'
;
import
{
TimeoutTimer
,
CancelablePromise
,
createCancelablePromise
}
from
'
vs/base/common/async
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
const
sticky
=
false
;
// for development purposes
const
expandSuggestionDocsByDefault
=
false
;
...
...
@@ -361,7 +362,7 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
private
state
:
State
;
private
isAuto
:
boolean
;
private
loadingTimeout
:
number
;
private
currentSuggestionDetails
:
T
Promise
<
void
>
;
private
currentSuggestionDetails
:
Cancelable
Promise
<
void
>
;
private
focusedItem
:
ICompletionItem
;
private
ignoreFocusEvents
=
false
;
private
completionModel
:
CompletionModel
;
...
...
@@ -377,8 +378,8 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
private
suggestWidgetMultipleSuggestions
:
IContextKey
<
boolean
>
;
private
suggestionSupportsAutoAccept
:
IContextKey
<
boolean
>
;
private
editorBlurTimeout
:
TPromise
<
void
>
;
private
showTimeout
:
TPromise
<
void
>
;
private
readonly
editorBlurTimeout
=
new
TimeoutTimer
()
;
private
readonly
showTimeout
=
new
TimeoutTimer
()
;
private
toDispose
:
IDisposable
[];
private
onDidSelectEmitter
=
new
Emitter
<
ISelectedSuggestion
>
();
...
...
@@ -482,11 +483,11 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
return
;
}
this
.
editorBlurTimeout
=
TPromise
.
timeout
(
150
).
then
(()
=>
{
this
.
editorBlurTimeout
.
cancelAndSet
(()
=>
{
if
(
!
this
.
editor
.
hasTextFocus
())
{
this
.
setState
(
State
.
Hidden
);
}
});
}
,
150
);
}
private
onEditorLayoutChange
():
void
{
...
...
@@ -502,7 +503,7 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
const
item
=
e
.
elements
[
0
];
const
index
=
e
.
indexes
[
0
];
item
.
resolve
().
then
(()
=>
{
item
.
resolve
(
CancellationToken
.
None
).
then
(()
=>
{
this
.
onDidSelectEmitter
.
fire
({
item
,
index
,
model
:
this
.
completionModel
});
alert
(
nls
.
localize
(
'
suggestionAriaAccepted
'
,
"
{0}, accepted
"
,
item
.
suggestion
.
label
));
this
.
editor
.
focus
();
...
...
@@ -586,22 +587,21 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
this
.
list
.
reveal
(
index
);
this
.
currentSuggestionDetails
=
item
.
resolve
()
.
then
(()
=>
{
// item can have extra information, so re-render
this
.
ignoreFocusEvents
=
true
;
this
.
list
.
splice
(
index
,
1
,
[
item
]);
this
.
list
.
setFocus
([
index
]);
this
.
ignoreFocusEvents
=
false
;
if
(
this
.
expandDocsSettingFromStorage
())
{
this
.
showDetails
();
}
else
{
removeClass
(
this
.
element
,
'
docs-side
'
);
}
})
.
then
(
null
,
err
=>
!
isPromiseCanceledError
(
err
)
&&
onUnexpectedError
(
err
))
.
then
(()
=>
this
.
currentSuggestionDetails
=
null
);
this
.
currentSuggestionDetails
=
createCancelablePromise
(
token
=>
item
.
resolve
(
token
));
this
.
currentSuggestionDetails
.
then
(()
=>
{
// item can have extra information, so re-render
this
.
ignoreFocusEvents
=
true
;
this
.
list
.
splice
(
index
,
1
,
[
item
]);
this
.
list
.
setFocus
([
index
]);
this
.
ignoreFocusEvents
=
false
;
if
(
this
.
expandDocsSettingFromStorage
())
{
this
.
showDetails
();
}
else
{
removeClass
(
this
.
element
,
'
docs-side
'
);
}
}).
catch
(
onUnexpectedError
).
then
(()
=>
this
.
currentSuggestionDetails
=
null
);
// emit an event
this
.
onDidFocusEmitter
.
fire
({
item
,
index
,
model
:
this
.
completionModel
});
...
...
@@ -925,10 +925,10 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
this
.
suggestWidgetVisible
.
set
(
true
);
this
.
showTimeout
=
TPromise
.
timeout
(
100
).
then
(()
=>
{
this
.
showTimeout
.
cancelAndSet
(()
=>
{
addClass
(
this
.
element
,
'
visible
'
);
this
.
onDidShowEmitter
.
fire
(
this
);
});
}
,
100
);
}
private
hide
():
void
{
...
...
@@ -1082,15 +1082,8 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
this
.
loadingTimeout
=
null
;
}
if
(
this
.
editorBlurTimeout
)
{
this
.
editorBlurTimeout
.
cancel
();
this
.
editorBlurTimeout
=
null
;
}
if
(
this
.
showTimeout
)
{
this
.
showTimeout
.
cancel
();
this
.
showTimeout
=
null
;
}
this
.
editorBlurTimeout
.
dispose
();
this
.
showTimeout
.
dispose
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录