Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
a4c9fed9
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,发现更多精彩内容 >>
提交
a4c9fed9
编写于
9月 21, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test for bad concurrent edits, test for subsequent good edits
上级
891852a7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
81 addition
and
3 deletion
+81
-3
src/vs/workbench/api/node/extHostDocumentSaveParticipant.ts
src/vs/workbench/api/node/extHostDocumentSaveParticipant.ts
+3
-3
src/vs/workbench/test/node/api/extHostDocumentSaveParticipant.test.ts
...ench/test/node/api/extHostDocumentSaveParticipant.test.ts
+78
-0
未找到文件。
src/vs/workbench/api/node/extHostDocumentSaveParticipant.ts
浏览文件 @
a4c9fed9
...
...
@@ -47,7 +47,7 @@ export class ExtHostDocumentSaveParticipant {
};
}
$participateInSave
(
resource
:
URI
):
TPromise
<
any
>
{
$participateInSave
(
resource
:
URI
):
TPromise
<
any
[]
>
{
const
entries
=
this
.
_callbacks
.
entries
();
return
sequence
(
entries
.
map
(([
fn
,
thisArg
])
=>
{
...
...
@@ -106,8 +106,8 @@ export class ExtHostDocumentSaveParticipant {
return
this
.
_workspace
.
$applyWorkspaceEdit
(
edits
);
}
// TODO@joh
- fail
?
console
.
warn
(
'
IGNORING changes because document has changed while computing change
s
'
);
// TODO@joh
bubble this to listener
?
return
new
Error
(
'
ignoring change because of concurrent edit
s
'
);
},
err
=>
{
// ignore error
...
...
src/vs/workbench/test/node/api/extHostDocumentSaveParticipant.test.ts
浏览文件 @
a4c9fed9
...
...
@@ -177,4 +177,82 @@ suite('ExtHostDocumentSaveParticipant', () => {
assert
.
equal
(
edits
.
length
,
1
);
});
});
test
(
'
event delivery, concurrent change
'
,
()
=>
{
let
edits
:
IResourceEdit
[];
const
participant
=
new
ExtHostDocumentSaveParticipant
(
documents
,
new
class
extends
MainThreadWorkspaceShape
{
$applyWorkspaceEdit
(
_edits
)
{
edits
=
_edits
;
return
TPromise
.
as
(
true
);
}
});
let
sub
=
participant
.
onWillSaveTextDocumentEvent
(
function
(
e
)
{
// concurrent change from somewhere
documents
.
$acceptModelChanged
(
resource
.
toString
(),
[{
versionId
:
2
,
range
:
{
startLineNumber
:
1
,
startColumn
:
1
,
endLineNumber
:
1
,
endColumn
:
1
},
text
:
'
bar
'
,
rangeLength
:
undefined
,
eol
:
undefined
,
isRedoing
:
undefined
,
isUndoing
:
undefined
,
}]);
e
.
waitUntil
(
TPromise
.
as
([
TextEdit
.
insert
(
new
Position
(
0
,
0
),
'
bar
'
)]));
});
return
participant
.
$participateInSave
(
resource
).
then
(
values
=>
{
sub
.
dispose
();
assert
.
equal
(
edits
,
undefined
);
assert
.
ok
((
<
Error
>
values
[
0
]).
message
);
});
});
test
(
'
event delivery, two listeners -> two document states
'
,
()
=>
{
const
participant
=
new
ExtHostDocumentSaveParticipant
(
documents
,
new
class
extends
MainThreadWorkspaceShape
{
$applyWorkspaceEdit
(
_edits
:
IResourceEdit
[])
{
for
(
const
{
resource
,
newText
,
range
}
of
_edits
)
{
documents
.
$acceptModelChanged
(
resource
.
toString
(),
[{
range
,
text
:
newText
,
versionId
:
documents
.
getDocumentData
(
resource
).
version
+
1
,
rangeLength
:
undefined
,
eol
:
undefined
,
isRedoing
:
undefined
,
isUndoing
:
undefined
,
}]);
}
return
TPromise
.
as
(
true
);
}
});
const
document
=
documents
.
getDocumentData
(
resource
).
document
;
let
sub1
=
participant
.
onWillSaveTextDocumentEvent
(
function
(
e
)
{
// the document state we started with
assert
.
equal
(
document
.
version
,
1
);
assert
.
equal
(
document
.
getText
(),
'
foo
'
);
e
.
waitUntil
(
TPromise
.
as
([
TextEdit
.
insert
(
new
Position
(
0
,
0
),
'
bar
'
)]));
});
let
sub2
=
participant
.
onWillSaveTextDocumentEvent
(
function
(
e
)
{
// the document state AFTER the first listener kicked in
assert
.
equal
(
document
.
version
,
2
);
assert
.
equal
(
document
.
getText
(),
'
barfoo
'
);
e
.
waitUntil
(
TPromise
.
as
([
TextEdit
.
insert
(
new
Position
(
0
,
0
),
'
bar
'
)]));
});
return
participant
.
$participateInSave
(
resource
).
then
(
values
=>
{
sub1
.
dispose
();
sub2
.
dispose
();
// the document state AFTER eventing is done
assert
.
equal
(
document
.
version
,
3
);
assert
.
equal
(
document
.
getText
(),
'
barbarfoo
'
);
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录