Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
3698d323
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,发现更多精彩内容 >>
提交
3698d323
编写于
1月 08, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove ICommand#precondition, #41103
上级
a17bdc15
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
4 addition
and
63 deletion
+4
-63
src/vs/platform/commands/common/commandService.ts
src/vs/platform/commands/common/commandService.ts
+0
-8
src/vs/platform/commands/common/commands.ts
src/vs/platform/commands/common/commands.ts
+0
-2
src/vs/platform/commands/test/commandService.test.ts
src/vs/platform/commands/test/commandService.test.ts
+4
-35
src/vs/platform/commands/test/commands.test.ts
src/vs/platform/commands/test/commands.test.ts
+0
-18
未找到文件。
src/vs/platform/commands/common/commandService.ts
浏览文件 @
3698d323
...
...
@@ -10,7 +10,6 @@ import { ICommandService, ICommandEvent, CommandsRegistry } from 'vs/platform/co
import
{
IExtensionService
}
from
'
vs/platform/extensions/common/extensions
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ILogService
}
from
'
vs/platform/log/common/log
'
;
export
class
CommandService
extends
Disposable
implements
ICommandService
{
...
...
@@ -25,7 +24,6 @@ export class CommandService extends Disposable implements ICommandService {
constructor
(
@
IInstantiationService
private
_instantiationService
:
IInstantiationService
,
@
IExtensionService
private
_extensionService
:
IExtensionService
,
@
IContextKeyService
private
_contextKeyService
:
IContextKeyService
,
@
ILogService
private
_logService
:
ILogService
)
{
super
();
...
...
@@ -53,12 +51,6 @@ export class CommandService extends Disposable implements ICommandService {
if
(
!
command
)
{
return
TPromise
.
wrapError
(
new
Error
(
`command '
${
id
}
' not found`
));
}
if
(
command
.
precondition
&&
!
this
.
_contextKeyService
.
contextMatchesRules
(
command
.
precondition
))
{
// not enabled
return
TPromise
.
wrapError
(
new
Error
(
'
NOT_ENABLED
'
));
}
try
{
this
.
_onWillExecuteCommand
.
fire
({
commandId
:
id
});
const
result
=
this
.
_instantiationService
.
invokeFunction
.
apply
(
this
.
_instantiationService
,
[
command
.
handler
].
concat
(
args
));
...
...
src/vs/platform/commands/common/commands.ts
浏览文件 @
3698d323
...
...
@@ -9,7 +9,6 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import
{
TypeConstraint
,
validateConstraints
}
from
'
vs/base/common/types
'
;
import
{
ServicesAccessor
,
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
Event
from
'
vs/base/common/event
'
;
import
{
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
LinkedList
}
from
'
vs/base/common/linkedList
'
;
export
const
ICommandService
=
createDecorator
<
ICommandService
>
(
'
commandService
'
);
...
...
@@ -35,7 +34,6 @@ export interface ICommandHandler {
export
interface
ICommand
{
id
:
string
;
handler
:
ICommandHandler
;
precondition
?:
ContextKeyExpr
;
description
?:
ICommandHandlerDescription
;
}
...
...
src/vs/platform/commands/test/commandService.test.ts
浏览文件 @
3698d323
...
...
@@ -12,9 +12,6 @@ import { CommandService } from 'vs/platform/commands/common/commandService';
import
{
IExtensionService
,
ExtensionPointContribution
,
IExtensionDescription
,
IExtensionHostInformation
,
ProfileSession
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
InstantiationService
}
from
'
vs/platform/instantiation/common/instantiationService
'
;
import
{
IExtensionPoint
}
from
'
vs/platform/extensions/common/extensionsRegistry
'
;
import
{
ContextKeyService
}
from
'
vs/platform/contextkey/browser/contextKeyService
'
;
import
{
SimpleConfigurationService
}
from
'
vs/editor/standalone/browser/simpleServices
'
;
import
{
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
NullLogService
}
from
'
vs/platform/log/common/log
'
;
...
...
@@ -75,7 +72,7 @@ suite('CommandService', function () {
lastEvent
=
activationEvent
;
return
super
.
activateByEvent
(
activationEvent
);
}
},
new
ContextKeyService
(
new
SimpleConfigurationService
()),
new
NullLogService
());
},
new
NullLogService
());
return
service
.
executeCommand
(
'
foo
'
).
then
(()
=>
{
assert
.
ok
(
lastEvent
,
'
onCommand:foo
'
);
...
...
@@ -93,7 +90,7 @@ suite('CommandService', function () {
activateByEvent
(
activationEvent
:
string
):
TPromise
<
void
>
{
return
TPromise
.
wrapError
<
void
>
(
new
Error
(
'
bad_activate
'
));
}
},
new
ContextKeyService
(
new
SimpleConfigurationService
()),
new
NullLogService
());
},
new
NullLogService
());
return
service
.
executeCommand
(
'
foo
'
).
then
(()
=>
assert
.
ok
(
false
),
err
=>
{
assert
.
equal
(
err
.
message
,
'
bad_activate
'
);
...
...
@@ -109,7 +106,7 @@ suite('CommandService', function () {
whenInstalledExtensionsRegistered
()
{
return
new
TPromise
<
boolean
>
(
_resolve
=>
{
/*ignore*/
});
}
},
new
ContextKeyService
(
new
SimpleConfigurationService
()),
new
NullLogService
());
},
new
NullLogService
());
service
.
executeCommand
(
'
bar
'
);
assert
.
equal
(
callCounter
,
1
);
...
...
@@ -126,7 +123,7 @@ suite('CommandService', function () {
whenInstalledExtensionsRegistered
()
{
return
new
TPromise
<
boolean
>
(
_resolve
=>
{
resolveFunc
=
_resolve
;
});
}
},
new
ContextKeyService
(
new
SimpleConfigurationService
()),
new
NullLogService
());
},
new
NullLogService
());
let
r
=
service
.
executeCommand
(
'
bar
'
);
assert
.
equal
(
callCounter
,
0
);
...
...
@@ -139,32 +136,4 @@ suite('CommandService', function () {
assert
.
equal
(
callCounter
,
1
);
});
});
test
(
'
honor command-precondition
'
,
function
()
{
let
contextKeyService
=
new
ContextKeyService
(
new
SimpleConfigurationService
());
let
commandService
=
new
CommandService
(
new
InstantiationService
(),
new
SimpleExtensionService
(),
contextKeyService
,
new
NullLogService
()
);
let
counter
=
0
;
let
reg
=
CommandsRegistry
.
registerCommand
({
id
:
'
bar
'
,
handler
:
()
=>
{
counter
+=
1
;
},
precondition
:
ContextKeyExpr
.
has
(
'
foocontext
'
)
});
return
commandService
.
executeCommand
(
'
bar
'
).
then
(()
=>
{
assert
.
throws
(()
=>
{
});
},
()
=>
{
contextKeyService
.
setContext
(
'
foocontext
'
,
true
);
return
commandService
.
executeCommand
(
'
bar
'
);
}).
then
(()
=>
{
assert
.
equal
(
counter
,
1
);
reg
.
dispose
();
});
});
});
src/vs/platform/commands/test/commands.test.ts
浏览文件 @
3698d323
...
...
@@ -6,7 +6,6 @@
import
*
as
assert
from
'
assert
'
;
import
{
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
RawContextKey
}
from
'
vs/platform/contextkey/common/contextkey
'
;
suite
(
'
Command Tests
'
,
function
()
{
...
...
@@ -77,21 +76,4 @@ suite('Command Tests', function () {
assert
.
equal
(
CommandsRegistry
.
getCommands
()[
'
test3
'
].
handler
.
apply
(
undefined
,
[
undefined
,
1
]),
true
);
});
test
(
'
CommandsRegistry with precondition
'
,
function
()
{
let
r1
=
CommandsRegistry
.
registerCommand
(
'
foo
'
,
()
=>
{
});
const
precondition
=
new
RawContextKey
<
boolean
>
(
'
ddd
'
,
false
);
let
r2
=
CommandsRegistry
.
registerCommand
({
id
:
'
bar
'
,
handler
:
()
=>
{
},
precondition
});
assert
.
ok
(
CommandsRegistry
.
getCommand
(
'
bar
'
).
precondition
===
precondition
);
assert
.
equal
(
CommandsRegistry
.
getCommand
(
'
foo
'
).
precondition
,
undefined
);
r1
.
dispose
();
r2
.
dispose
();
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录