Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
5e840a6d
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,发现更多精彩内容 >>
提交
5e840a6d
编写于
12月 11, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
eng - no TPromise in save participants
上级
d221a282
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
37 addition
and
34 deletion
+37
-34
src/vs/base/common/async.ts
src/vs/base/common/async.ts
+5
-4
src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts
...rkbench/api/electron-browser/mainThreadSaveParticipant.ts
+7
-8
src/vs/workbench/api/node/extHost.protocol.ts
src/vs/workbench/api/node/extHost.protocol.ts
+1
-1
src/vs/workbench/api/node/extHostDocumentSaveParticipant.ts
src/vs/workbench/api/node/extHostDocumentSaveParticipant.ts
+17
-11
src/vs/workbench/test/electron-browser/api/extHostDocumentSaveParticipant.test.ts
...ectron-browser/api/extHostDocumentSaveParticipant.test.ts
+7
-10
未找到文件。
src/vs/base/common/async.ts
浏览文件 @
5e840a6d
...
...
@@ -349,13 +349,14 @@ export function always<T>(promise: TPromise<T>, f: Function): TPromise<T> {
* Runs the provided list of promise factories in sequential order. The returned
* promise will complete to an array of results from each promise.
*/
export
function
sequence
<
T
>
(
promiseFactories
:
ITask
<
TPromise
<
T
>>
[]):
TPromise
<
T
[]
>
{
export
function
sequence
<
T
>
(
promiseFactories
:
ITask
<
Thenable
<
T
>>
[]):
TPromise
<
T
[]
>
{
const
results
:
T
[]
=
[];
// reverse since we start with last element using pop()
promiseFactories
=
promiseFactories
.
reverse
();
function
next
():
Promise
{
function
next
():
Thenable
<
any
>
{
if
(
promiseFactories
.
length
)
{
return
promiseFactories
.
pop
()();
}
...
...
@@ -363,7 +364,7 @@ export function sequence<T>(promiseFactories: ITask<TPromise<T>>[]): TPromise<T[
return
null
;
}
function
thenHandler
(
result
:
any
):
Promise
{
function
thenHandler
(
result
:
any
):
Thenable
<
any
>
{
if
(
result
!==
undefined
&&
result
!==
null
)
{
results
.
push
(
result
);
}
...
...
@@ -692,4 +693,4 @@ export class ThrottledEmitter<T> extends Emitter<T> {
this
.
hasLastEvent
=
false
;
this
.
lastEvent
=
void
0
;
}
}
\ No newline at end of file
}
src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts
浏览文件 @
5e840a6d
...
...
@@ -5,7 +5,6 @@
'
use strict
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
sequence
}
from
'
vs/base/common/async
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
ICodeEditorService
}
from
'
vs/editor/browser/services/codeEditorService
'
;
...
...
@@ -175,7 +174,7 @@ class FormatOnSaveParticipant implements ISaveParticipant {
// Nothing
}
participate
(
editorModel
:
ITextFileEditorModel
,
env
:
{
reason
:
SaveReason
}):
T
Promise
<
void
>
{
participate
(
editorModel
:
ITextFileEditorModel
,
env
:
{
reason
:
SaveReason
}):
Promise
<
void
>
{
const
model
=
editorModel
.
textEditorModel
;
if
(
env
.
reason
===
SaveReason
.
AUTO
...
...
@@ -186,7 +185,7 @@ class FormatOnSaveParticipant implements ISaveParticipant {
const
versionNow
=
model
.
getVersionId
();
const
{
tabSize
,
insertSpaces
}
=
model
.
getOptions
();
return
new
T
Promise
<
ISingleEditOperation
[]
>
((
resolve
,
reject
)
=>
{
return
new
Promise
<
ISingleEditOperation
[]
>
((
resolve
,
reject
)
=>
{
setTimeout
(
reject
,
750
);
getDocumentFormattingEdits
(
model
,
{
tabSize
,
insertSpaces
})
.
then
(
edits
=>
this
.
_editorWorkerService
.
computeMoreMinimalEdits
(
model
.
uri
,
edits
))
...
...
@@ -241,13 +240,13 @@ class ExtHostSaveParticipant implements ISaveParticipant {
this
.
_proxy
=
extHostContext
.
get
(
ExtHostContext
.
ExtHostDocumentSaveParticipant
);
}
participate
(
editorModel
:
ITextFileEditorModel
,
env
:
{
reason
:
SaveReason
}):
T
Promise
<
void
>
{
return
new
T
Promise
<
any
>
((
resolve
,
reject
)
=>
{
participate
(
editorModel
:
ITextFileEditorModel
,
env
:
{
reason
:
SaveReason
}):
Promise
<
void
>
{
return
new
Promise
<
any
>
((
resolve
,
reject
)
=>
{
setTimeout
(
reject
,
1750
);
this
.
_proxy
.
$participateInSave
(
editorModel
.
getResource
(),
env
.
reason
).
then
(
values
=>
{
for
(
const
success
of
values
)
{
if
(
!
success
)
{
return
TPromise
.
wrapError
(
new
Error
(
'
listener failed
'
));
return
Promise
.
reject
(
new
Error
(
'
listener failed
'
));
}
}
return
undefined
;
...
...
@@ -286,9 +285,9 @@ export class SaveParticipant implements ISaveParticipant {
TextFileEditorModel
.
setSaveParticipant
(
undefined
);
}
participate
(
model
:
ITextFileEditorModel
,
env
:
{
reason
:
SaveReason
}):
T
Promis
e
<
void
>
{
participate
(
model
:
ITextFileEditorModel
,
env
:
{
reason
:
SaveReason
}):
T
henabl
e
<
void
>
{
const
promiseFactory
=
this
.
_saveParticipants
.
map
(
p
=>
()
=>
{
return
TPromise
.
as
(
p
.
participate
(
model
,
env
));
return
Promise
.
resolve
(
p
.
participate
(
model
,
env
));
});
return
sequence
(
promiseFactory
).
then
(()
=>
{
});
...
...
src/vs/workbench/api/node/extHost.protocol.ts
浏览文件 @
5e840a6d
...
...
@@ -462,7 +462,7 @@ export interface ExtHostDocumentsShape {
}
export
interface
ExtHostDocumentSaveParticipantShape
{
$participateInSave
(
resource
:
URI
,
reason
:
SaveReason
):
T
Promis
e
<
boolean
[]
>
;
$participateInSave
(
resource
:
URI
,
reason
:
SaveReason
):
T
henabl
e
<
boolean
[]
>
;
}
export
interface
ITextEditorAddData
{
...
...
src/vs/workbench/api/node/extHostDocumentSaveParticipant.ts
浏览文件 @
5e840a6d
...
...
@@ -8,7 +8,6 @@ import Event from 'vs/base/common/event';
import
URI
from
'
vs/base/common/uri
'
;
import
{
sequence
,
always
}
from
'
vs/base/common/async
'
;
import
{
illegalState
}
from
'
vs/base/common/errors
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
ExtHostDocumentSaveParticipantShape
,
MainThreadEditorsShape
,
IWorkspaceResourceEdit
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
TextEdit
}
from
'
vs/workbench/api/node/extHostTypes
'
;
import
{
fromRange
,
TextDocumentSaveReason
,
EndOfLine
}
from
'
vs/workbench/api/node/extHostTypeConverters
'
;
...
...
@@ -46,7 +45,7 @@ export class ExtHostDocumentSaveParticipant implements ExtHostDocumentSavePartic
};
}
$participateInSave
(
resource
:
URI
,
reason
:
SaveReason
):
T
Promis
e
<
boolean
[]
>
{
$participateInSave
(
resource
:
URI
,
reason
:
SaveReason
):
T
henabl
e
<
boolean
[]
>
{
const
entries
=
this
.
_callbacks
.
toArray
();
let
didTimeout
=
false
;
...
...
@@ -68,11 +67,11 @@ export class ExtHostDocumentSaveParticipant implements ExtHostDocumentSavePartic
return
always
(
promise
,
()
=>
clearTimeout
(
didTimeoutHandle
));
}
private
_deliverEventAsyncAndBlameBadListeners
(
listener
:
Function
,
thisArg
:
any
,
stubEvent
:
vscode
.
TextDocumentWillSaveEvent
):
T
Promise
<
any
>
{
private
_deliverEventAsyncAndBlameBadListeners
(
listener
:
Function
,
thisArg
:
any
,
stubEvent
:
vscode
.
TextDocumentWillSaveEvent
):
Promise
<
any
>
{
const
errors
=
this
.
_badListeners
.
get
(
listener
);
if
(
errors
>
this
.
_thresholds
.
errors
)
{
// bad listener - ignore
return
TPromise
.
wrap
(
false
);
return
Promise
.
resolve
(
false
);
}
return
this
.
_deliverEventAsync
(
listener
,
thisArg
,
stubEvent
).
then
(()
=>
{
...
...
@@ -93,9 +92,9 @@ export class ExtHostDocumentSaveParticipant implements ExtHostDocumentSavePartic
});
}
private
_deliverEventAsync
(
listener
:
Function
,
thisArg
:
any
,
stubEvent
:
vscode
.
TextDocumentWillSaveEvent
):
T
Promise
<
any
>
{
private
_deliverEventAsync
(
listener
:
Function
,
thisArg
:
any
,
stubEvent
:
vscode
.
TextDocumentWillSaveEvent
):
Promise
<
any
>
{
const
promises
:
T
Promise
<
vscode
.
TextEdit
[]
>
[]
=
[];
const
promises
:
Promise
<
vscode
.
TextEdit
[]
>
[]
=
[];
const
{
document
,
reason
}
=
stubEvent
;
const
{
version
}
=
document
;
...
...
@@ -107,7 +106,7 @@ export class ExtHostDocumentSaveParticipant implements ExtHostDocumentSavePartic
if
(
Object
.
isFrozen
(
promises
))
{
throw
illegalState
(
'
waitUntil can not be called async
'
);
}
promises
.
push
(
TPromise
.
wrap
(
p
));
promises
.
push
(
Promise
.
resolve
(
p
));
}
});
...
...
@@ -115,16 +114,23 @@ export class ExtHostDocumentSaveParticipant implements ExtHostDocumentSavePartic
// fire event
listener
.
apply
(
thisArg
,
[
event
]);
}
catch
(
err
)
{
return
TPromise
.
wrapError
(
err
);
return
Promise
.
reject
(
err
);
}
// freeze promises after event call
Object
.
freeze
(
promises
);
return
new
T
Promise
<
vscode
.
TextEdit
[][]
>
((
resolve
,
reject
)
=>
{
return
new
Promise
<
vscode
.
TextEdit
[][]
>
((
resolve
,
reject
)
=>
{
// join on all listener promises, reject after timeout
const
handle
=
setTimeout
(()
=>
reject
(
new
Error
(
'
timeout
'
)),
this
.
_thresholds
.
timeout
);
return
always
(
TPromise
.
join
(
promises
),
()
=>
clearTimeout
(
handle
)).
then
(
resolve
,
reject
);
return
Promise
.
all
(
promises
).
then
(
edits
=>
{
clearTimeout
(
handle
);
resolve
(
edits
);
}).
catch
(
err
=>
{
clearTimeout
(
handle
);
reject
(
err
);
});
}).
then
(
values
=>
{
...
...
@@ -156,7 +162,7 @@ export class ExtHostDocumentSaveParticipant implements ExtHostDocumentSavePartic
}
// TODO@joh bubble this to listener?
return
TPromise
.
wrapError
(
new
Error
(
'
concurrent_edits
'
));
return
Promise
.
reject
(
new
Error
(
'
concurrent_edits
'
));
});
}
}
src/vs/workbench/test/electron-browser/api/extHostDocumentSaveParticipant.test.ts
浏览文件 @
5e840a6d
...
...
@@ -128,7 +128,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
});
});
test
(
'
event delivery, ignore bad listeners
'
,
()
=>
{
test
(
'
event delivery, ignore bad listeners
'
,
async
()
=>
{
const
participant
=
new
ExtHostDocumentSaveParticipant
(
documents
,
mainThreadEditors
,
{
timeout
:
5
,
errors
:
1
});
let
callCount
=
0
;
...
...
@@ -137,16 +137,13 @@ suite('ExtHostDocumentSaveParticipant', () => {
throw
new
Error
(
'
boom
'
);
});
return
TPromise
.
join
([
participant
.
$participateInSave
(
resource
,
SaveReason
.
EXPLICIT
),
participant
.
$participateInSave
(
resource
,
SaveReason
.
EXPLICIT
),
participant
.
$participateInSave
(
resource
,
SaveReason
.
EXPLICIT
),
participant
.
$participateInSave
(
resource
,
SaveReason
.
EXPLICIT
)
await
participant
.
$participateInSave
(
resource
,
SaveReason
.
EXPLICIT
);
await
participant
.
$participateInSave
(
resource
,
SaveReason
.
EXPLICIT
);
await
participant
.
$participateInSave
(
resource
,
SaveReason
.
EXPLICIT
);
await
participant
.
$participateInSave
(
resource
,
SaveReason
.
EXPLICIT
);
]).
then
(
values
=>
{
sub
.
dispose
();
assert
.
equal
(
callCount
,
2
);
});
sub
.
dispose
();
assert
.
equal
(
callCount
,
2
);
});
test
(
'
event delivery, overall timeout
'
,
()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录