Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
a27782ed
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
a27782ed
编写于
8月 29, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wire-up dispose calls, #9384
上级
0ed5aef1
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
122 addition
and
2 deletion
+122
-2
src/vs/workbench/api/node/extHost.protocol.ts
src/vs/workbench/api/node/extHost.protocol.ts
+1
-0
src/vs/workbench/api/node/extHostCommands.ts
src/vs/workbench/api/node/extHostCommands.ts
+5
-1
src/vs/workbench/api/node/mainThreadCommands.ts
src/vs/workbench/api/node/mainThreadCommands.ts
+17
-1
src/vs/workbench/test/node/api/extHostCommands.test.ts
src/vs/workbench/test/node/api/extHostCommands.test.ts
+59
-0
src/vs/workbench/test/node/api/mainThreadCommands.test.ts
src/vs/workbench/test/node/api/mainThreadCommands.test.ts
+28
-0
src/vs/workbench/test/node/api/testThreadService.ts
src/vs/workbench/test/node/api/testThreadService.ts
+12
-0
未找到文件。
src/vs/workbench/api/node/extHost.protocol.ts
浏览文件 @
a27782ed
...
@@ -78,6 +78,7 @@ function ni() { return new Error('Not implemented'); }
...
@@ -78,6 +78,7 @@ function ni() { return new Error('Not implemented'); }
export
abstract
class
MainThreadCommandsShape
{
export
abstract
class
MainThreadCommandsShape
{
$registerCommand
(
id
:
string
):
TPromise
<
any
>
{
throw
ni
();
}
$registerCommand
(
id
:
string
):
TPromise
<
any
>
{
throw
ni
();
}
$unregisterCommand
(
id
:
string
):
TPromise
<
any
>
{
throw
ni
();
}
$executeCommand
<
T
>
(
id
:
string
,
args
:
any
[]):
Thenable
<
T
>
{
throw
ni
();
}
$executeCommand
<
T
>
(
id
:
string
,
args
:
any
[]):
Thenable
<
T
>
{
throw
ni
();
}
$getCommands
():
Thenable
<
string
[]
>
{
throw
ni
();
}
$getCommands
():
Thenable
<
string
[]
>
{
throw
ni
();
}
}
}
...
...
src/vs/workbench/api/node/extHostCommands.ts
浏览文件 @
a27782ed
...
@@ -48,7 +48,11 @@ export class ExtHostCommands extends ExtHostCommandsShape {
...
@@ -48,7 +48,11 @@ export class ExtHostCommands extends ExtHostCommandsShape {
this
.
_commands
[
id
]
=
{
callback
,
thisArg
,
description
};
this
.
_commands
[
id
]
=
{
callback
,
thisArg
,
description
};
this
.
_proxy
.
$registerCommand
(
id
);
this
.
_proxy
.
$registerCommand
(
id
);
return
new
extHostTypes
.
Disposable
(()
=>
delete
this
.
_commands
[
id
]);
return
new
extHostTypes
.
Disposable
(()
=>
{
if
(
delete
this
.
_commands
[
id
])
{
this
.
_proxy
.
$unregisterCommand
(
id
);
}
});
}
}
executeCommand
<
T
>
(
id
:
string
,
...
args
:
any
[]):
Thenable
<
T
>
{
executeCommand
<
T
>
(
id
:
string
,
...
args
:
any
[]):
Thenable
<
T
>
{
...
...
src/vs/workbench/api/node/mainThreadCommands.ts
浏览文件 @
a27782ed
...
@@ -6,11 +6,13 @@
...
@@ -6,11 +6,13 @@
import
{
IThreadService
}
from
'
vs/workbench/services/thread/common/threadService
'
;
import
{
IThreadService
}
from
'
vs/workbench/services/thread/common/threadService
'
;
import
{
ICommandService
,
CommandsRegistry
,
ICommandHandlerDescription
}
from
'
vs/platform/commands/common/commands
'
;
import
{
ICommandService
,
CommandsRegistry
,
ICommandHandlerDescription
}
from
'
vs/platform/commands/common/commands
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
ExtHostContext
,
MainThreadCommandsShape
,
ExtHostCommandsShape
}
from
'
./extHost.protocol
'
;
import
{
ExtHostContext
,
MainThreadCommandsShape
,
ExtHostCommandsShape
}
from
'
./extHost.protocol
'
;
export
class
MainThreadCommands
extends
MainThreadCommandsShape
{
export
class
MainThreadCommands
extends
MainThreadCommandsShape
{
private
_disposables
:
{
[
id
:
string
]:
IDisposable
}
=
Object
.
create
(
null
);
private
_proxy
:
ExtHostCommandsShape
;
private
_proxy
:
ExtHostCommandsShape
;
constructor
(
constructor
(
...
@@ -21,11 +23,25 @@ export class MainThreadCommands extends MainThreadCommandsShape {
...
@@ -21,11 +23,25 @@ export class MainThreadCommands extends MainThreadCommandsShape {
this
.
_proxy
=
this
.
_threadService
.
get
(
ExtHostContext
.
ExtHostCommands
);
this
.
_proxy
=
this
.
_threadService
.
get
(
ExtHostContext
.
ExtHostCommands
);
}
}
dispose
()
{
for
(
let
id
in
this
.
_disposables
)
{
this
.
_disposables
[
id
].
dispose
();
}
}
$registerCommand
(
id
:
string
):
TPromise
<
any
>
{
$registerCommand
(
id
:
string
):
TPromise
<
any
>
{
CommandsRegistry
.
registerCommand
(
id
,
(
accessor
,
...
args
)
=>
this
.
_proxy
.
$executeContributedCommand
(
id
,
...
args
));
this
.
_disposables
[
id
]
=
CommandsRegistry
.
registerCommand
(
id
,
(
accessor
,
...
args
)
=>
this
.
_proxy
.
$executeContributedCommand
(
id
,
...
args
));
return
undefined
;
return
undefined
;
}
}
$unregisterCommand
(
id
:
string
):
TPromise
<
any
>
{
if
(
this
.
_disposables
[
id
])
{
this
.
_disposables
[
id
].
dispose
();
delete
this
.
_disposables
[
id
];
}
return
;
}
$executeCommand
<
T
>
(
id
:
string
,
args
:
any
[]):
Thenable
<
T
>
{
$executeCommand
<
T
>
(
id
:
string
,
args
:
any
[]):
Thenable
<
T
>
{
return
this
.
_commandService
.
executeCommand
(
id
,
...
args
);
return
this
.
_commandService
.
executeCommand
(
id
,
...
args
);
}
}
...
...
src/vs/workbench/test/node/api/extHostCommands.test.ts
0 → 100644
浏览文件 @
a27782ed
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
ExtHostCommands
}
from
'
vs/workbench/api/node/extHostCommands
'
;
import
{
MainThreadCommandsShape
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
OneGetThreadService
}
from
'
./testThreadService
'
;
suite
(
'
ExtHostCommands
'
,
function
()
{
test
(
'
dispose calls unregister
'
,
function
()
{
let
lastUnregister
:
string
;
const
shape
=
new
class
extends
MainThreadCommandsShape
{
$registerCommand
(
id
:
string
):
TPromise
<
any
>
{
return
;
}
$unregisterCommand
(
id
:
string
):
TPromise
<
any
>
{
lastUnregister
=
id
;
return
;
}
};
const
commands
=
new
ExtHostCommands
(
OneGetThreadService
(
shape
),
undefined
);
commands
.
registerCommand
(
'
foo
'
,
()
=>
{
}).
dispose
();
assert
.
equal
(
lastUnregister
,
'
foo
'
);
assert
.
equal
(
CommandsRegistry
.
getCommand
(
'
foo
'
),
undefined
);
});
test
(
'
dispose bubbles only once
'
,
function
()
{
let
unregisterCounter
=
0
;
const
shape
=
new
class
extends
MainThreadCommandsShape
{
$registerCommand
(
id
:
string
):
TPromise
<
any
>
{
return
;
}
$unregisterCommand
(
id
:
string
):
TPromise
<
any
>
{
unregisterCounter
+=
1
;
return
;
}
};
const
commands
=
new
ExtHostCommands
(
OneGetThreadService
(
shape
),
undefined
);
const
reg
=
commands
.
registerCommand
(
'
foo
'
,
()
=>
{
});
reg
.
dispose
();
reg
.
dispose
();
reg
.
dispose
();
assert
.
equal
(
unregisterCounter
,
1
);
});
});
\ No newline at end of file
src/vs/workbench/test/node/api/mainThreadCommands.test.ts
0 → 100644
浏览文件 @
a27782ed
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
MainThreadCommands
}
from
'
vs/workbench/api/node/mainThreadCommands
'
;
import
{
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
OneGetThreadService
}
from
'
./testThreadService
'
;
suite
(
'
MainThreadCommands
'
,
function
()
{
test
(
'
dispose on unregister
'
,
function
()
{
const
commands
=
new
MainThreadCommands
(
OneGetThreadService
(
null
),
undefined
);
assert
.
equal
(
CommandsRegistry
.
getCommand
(
'
foo
'
),
undefined
);
// register
commands
.
$registerCommand
(
'
foo
'
);
assert
.
ok
(
CommandsRegistry
.
getCommand
(
'
foo
'
));
// unregister
commands
.
$unregisterCommand
(
'
foo
'
);
assert
.
equal
(
CommandsRegistry
.
getCommand
(
'
foo
'
),
undefined
);
});
});
\ No newline at end of file
src/vs/workbench/test/node/api/testThreadService.ts
浏览文件 @
a27782ed
...
@@ -9,6 +9,18 @@ import {TPromise} from 'vs/base/common/winjs.base';
...
@@ -9,6 +9,18 @@ import {TPromise} from 'vs/base/common/winjs.base';
import
{
AbstractThreadService
}
from
'
vs/workbench/services/thread/common/abstractThreadService
'
;
import
{
AbstractThreadService
}
from
'
vs/workbench/services/thread/common/abstractThreadService
'
;
import
{
IThreadService
,
ProxyIdentifier
}
from
'
vs/workbench/services/thread/common/threadService
'
;
import
{
IThreadService
,
ProxyIdentifier
}
from
'
vs/workbench/services/thread/common/threadService
'
;
export
function
OneGetThreadService
(
thing
:
any
):
IThreadService
{
return
{
_serviceBrand
:
undefined
,
get
<
T
>
():
T
{
return
thing
;
},
set
<
T
>
():
void
{
throw
new
Error
();
}
};
}
export
class
TestThreadService
extends
AbstractThreadService
implements
IThreadService
{
export
class
TestThreadService
extends
AbstractThreadService
implements
IThreadService
{
public
_serviceBrand
:
any
;
public
_serviceBrand
:
any
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录