Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
706ada46
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,发现更多精彩内容 >>
提交
706ada46
编写于
10月 01, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt - let sequence and first use native promises
上级
7278fdbd
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
26 addition
and
42 deletion
+26
-42
src/vs/base/common/async.ts
src/vs/base/common/async.ts
+7
-29
src/vs/editor/contrib/format/format.ts
src/vs/editor/contrib/format/format.ts
+3
-3
src/vs/editor/contrib/parameterHints/provideSignatureHelp.ts
src/vs/editor/contrib/parameterHints/provideSignatureHelp.ts
+2
-2
src/vs/editor/contrib/suggest/suggest.ts
src/vs/editor/contrib/suggest/suggest.ts
+2
-2
src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts
src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts
+2
-2
src/vs/workbench/services/textmodelResolver/test/textModelResolverService.test.ts
...s/textmodelResolver/test/textModelResolverService.test.ts
+10
-4
未找到文件。
src/vs/base/common/async.ts
浏览文件 @
706ada46
...
...
@@ -333,7 +333,7 @@ export function always<T>(winjsPromiseOrThenable: Thenable<T>, callback: () => v
* promise will complete to an array of results from each promise.
*/
export
function
sequence
<
T
>
(
promiseFactories
:
ITask
<
Thenable
<
T
>>
[]):
T
Promise
<
T
[]
>
{
export
function
sequence
<
T
>
(
promiseFactories
:
ITask
<
Thenable
<
T
>>
[]):
Promise
<
T
[]
>
{
const
results
:
T
[]
=
[];
let
index
=
0
;
const
len
=
promiseFactories
.
length
;
...
...
@@ -352,49 +352,27 @@ export function sequence<T>(promiseFactories: ITask<Thenable<T>>[]): TPromise<T[
return
n
.
then
(
thenHandler
);
}
return
TPromise
.
as
(
results
);
return
Promise
.
resolve
(
results
);
}
return
TPromise
.
as
(
null
).
then
(
thenHandler
);
return
Promise
.
resolve
(
null
).
then
(
thenHandler
);
}
export
function
first2
<
T
>
(
promiseFactories
:
ITask
<
Promise
<
T
>>
[],
shouldStop
:
(
t
:
T
)
=>
boolean
=
t
=>
!!
t
,
defaultValue
:
T
=
null
):
Promise
<
T
>
{
export
function
first
<
T
>
(
promiseFactories
:
ITask
<
Thenable
<
T
>>
[],
shouldStop
:
(
t
:
T
)
=>
boolean
=
t
=>
!!
t
,
defaultValue
:
T
=
null
):
Promise
<
T
>
{
let
index
=
0
;
const
len
=
promiseFactories
.
length
;
const
loop
=
()
=>
{
const
loop
:
()
=>
Promise
<
T
>
=
()
=>
{
if
(
index
>=
len
)
{
return
Promise
.
resolve
(
defaultValue
);
}
const
factory
=
promiseFactories
[
index
++
];
const
promise
=
factory
();
return
promise
.
then
(
result
=>
{
if
(
shouldStop
(
result
))
{
return
Promise
.
resolve
(
result
);
}
return
loop
();
});
};
return
loop
();
}
export
function
first
<
T
>
(
promiseFactories
:
ITask
<
TPromise
<
T
>>
[],
shouldStop
:
(
t
:
T
)
=>
boolean
=
t
=>
!!
t
,
defaultValue
:
T
=
null
):
TPromise
<
T
>
{
let
index
=
0
;
const
len
=
promiseFactories
.
length
;
const
loop
:
()
=>
TPromise
<
T
>
=
()
=>
{
if
(
index
>=
len
)
{
return
TPromise
.
as
(
defaultValue
);
}
const
factory
=
promiseFactories
[
index
++
];
const
promise
=
factory
(
);
const
promise
=
Promise
.
resolve
(
factory
()
);
return
promise
.
then
(
result
=>
{
if
(
shouldStop
(
result
))
{
return
TPromise
.
as
(
result
);
return
Promise
.
resolve
(
result
);
}
return
loop
();
...
...
src/vs/editor/contrib/format/format.ts
浏览文件 @
706ada46
...
...
@@ -11,7 +11,7 @@ import { ITextModel } from 'vs/editor/common/model';
import
{
registerDefaultLanguageCommand
,
registerLanguageCommand
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
DocumentFormattingEditProviderRegistry
,
DocumentRangeFormattingEditProviderRegistry
,
OnTypeFormattingEditProviderRegistry
,
FormattingOptions
,
TextEdit
}
from
'
vs/editor/common/modes
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
first
2
}
from
'
vs/base/common/async
'
;
import
{
first
}
from
'
vs/base/common/async
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
...
...
@@ -34,7 +34,7 @@ export function getDocumentRangeFormattingEdits(model: ITextModel, range: Range,
return
Promise
.
reject
(
new
NoProviderError
());
}
return
first
2
(
providers
.
map
(
provider
=>
()
=>
{
return
first
(
providers
.
map
(
provider
=>
()
=>
{
return
Promise
.
resolve
(
provider
.
provideDocumentRangeFormattingEdits
(
model
,
range
,
options
,
token
))
.
then
(
undefined
,
onUnexpectedExternalError
);
}),
result
=>
!
isFalsyOrEmpty
(
result
));
...
...
@@ -48,7 +48,7 @@ export function getDocumentFormattingEdits(model: ITextModel, options: Formattin
return
getDocumentRangeFormattingEdits
(
model
,
model
.
getFullModelRange
(),
options
,
token
);
}
return
first
2
(
providers
.
map
(
provider
=>
()
=>
{
return
first
(
providers
.
map
(
provider
=>
()
=>
{
return
Promise
.
resolve
(
provider
.
provideDocumentFormattingEdits
(
model
,
options
,
token
))
.
then
(
undefined
,
onUnexpectedExternalError
);
}),
result
=>
!
isFalsyOrEmpty
(
result
));
...
...
src/vs/editor/contrib/parameterHints/provideSignatureHelp.ts
浏览文件 @
706ada46
...
...
@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
first
2
}
from
'
vs/base/common/async
'
;
import
{
first
}
from
'
vs/base/common/async
'
;
import
{
onUnexpectedExternalError
}
from
'
vs/base/common/errors
'
;
import
{
registerDefaultLanguageCommand
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
...
...
@@ -21,7 +21,7 @@ export function provideSignatureHelp(model: ITextModel, position: Position, cont
const
supports
=
modes
.
SignatureHelpProviderRegistry
.
ordered
(
model
);
return
first
2
(
supports
.
map
(
support
=>
()
=>
{
return
first
(
supports
.
map
(
support
=>
()
=>
{
return
Promise
.
resolve
(
support
.
provideSignatureHelp
(
model
,
position
,
token
,
context
)).
catch
(
onUnexpectedExternalError
);
}));
}
...
...
src/vs/editor/contrib/suggest/suggest.ts
浏览文件 @
706ada46
...
...
@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
first
2
}
from
'
vs/base/common/async
'
;
import
{
first
}
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
'
;
...
...
@@ -111,7 +111,7 @@ export function provideSuggestionItems(
}));
});
const
result
=
first
2
(
factory
,
()
=>
{
const
result
=
first
(
factory
,
()
=>
{
// stop on result or cancellation
return
hasResult
||
token
.
isCancellationRequested
;
}).
then
(()
=>
{
...
...
src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts
浏览文件 @
706ada46
...
...
@@ -5,7 +5,7 @@
import
*
as
nls
from
'
vs/nls
'
;
import
{
first
2
,
createCancelablePromise
,
CancelablePromise
,
timeout
}
from
'
vs/base/common/async
'
;
import
{
first
,
createCancelablePromise
,
CancelablePromise
,
timeout
}
from
'
vs/base/common/async
'
;
import
{
onUnexpectedExternalError
,
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
...
...
@@ -45,7 +45,7 @@ export function getOccurrencesAtPosition(model: ITextModel, position: Position,
// in order of score ask the occurrences provider
// until someone response with a good result
// (good = none empty array)
return
first
2
(
orderedByScore
.
map
(
provider
=>
()
=>
{
return
first
(
orderedByScore
.
map
(
provider
=>
()
=>
{
return
Promise
.
resolve
(
provider
.
provideDocumentHighlights
(
model
,
position
,
token
))
.
then
(
undefined
,
onUnexpectedExternalError
);
}),
result
=>
!
isFalsyOrEmpty
(
result
));
...
...
src/vs/workbench/services/textmodelResolver/test/textModelResolverService.test.ts
浏览文件 @
706ada46
...
...
@@ -72,16 +72,19 @@ suite('Workbench - TextModelResolverService', () => {
let
resource
=
URI
.
from
({
scheme
:
'
test
'
,
authority
:
null
,
path
:
'
thePath
'
});
let
input
:
ResourceEditorInput
=
instantiationService
.
createInstance
(
ResourceEditorInput
,
'
The Name
'
,
'
The Description
'
,
resource
);
return
input
.
resolve
().
then
(
model
=>
{
return
input
.
resolve
().
then
(
async
model
=>
{
assert
.
ok
(
model
);
assert
.
equal
(
snapshotToString
((
model
as
ResourceEditorModel
).
createSnapshot
()),
'
Hello Test
'
);
let
disposed
=
false
;
once
(
model
.
onDispose
)(()
=>
{
disposed
=
true
;
let
disposedPromise
=
new
Promise
(
resolve
=>
{
once
(
model
.
onDispose
)(()
=>
{
disposed
=
true
;
resolve
();
});
});
input
.
dispose
();
await
disposedPromise
;
assert
.
equal
(
disposed
,
true
);
dispose
.
dispose
();
...
...
@@ -161,7 +164,10 @@ suite('Workbench - TextModelResolverService', () => {
modelRef1
.
dispose
();
assert
(
!
textModel
.
isDisposed
(),
'
the text model should still not be disposed
'
);
let
p1
=
new
Promise
(
resolve
=>
textModel
.
onWillDispose
(
resolve
));
modelRef2
.
dispose
();
await
p1
;
assert
(
textModel
.
isDisposed
(),
'
the text model should finally be disposed
'
);
disposable
.
dispose
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录