Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
24ecf494
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,体验更适合开发者的 AI 搜索 >>
提交
24ecf494
编写于
1月 23, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make =~ actually be a regex test operation, #26044
上级
65318273
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
24 deletion
+30
-24
src/vs/platform/contextkey/common/contextkey.ts
src/vs/platform/contextkey/common/contextkey.ts
+24
-17
src/vs/platform/contextkey/test/common/contextkey.test.ts
src/vs/platform/contextkey/test/common/contextkey.test.ts
+6
-7
未找到文件。
src/vs/platform/contextkey/common/contextkey.ts
浏览文件 @
24ecf494
...
...
@@ -6,7 +6,6 @@
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
Event
from
'
vs/base/common/event
'
;
import
{
match
}
from
'
vs/base/common/glob
'
;
export
enum
ContextKeyExprType
{
Defined
=
1
,
...
...
@@ -14,7 +13,7 @@ export enum ContextKeyExprType {
Equals
=
3
,
NotEquals
=
4
,
And
=
5
,
Glob
=
6
Regex
=
6
}
export
abstract
class
ContextKeyExpr
{
...
...
@@ -31,8 +30,8 @@ export abstract class ContextKeyExpr {
return
new
ContextKeyNotEqualsExpr
(
key
,
value
);
}
public
static
glob
(
key
:
string
,
value
:
string
):
ContextKeyExpr
{
return
new
ContextKey
Glob
Expr
(
key
,
value
);
public
static
regex
(
key
:
string
,
value
:
string
):
ContextKeyExpr
{
return
new
ContextKey
Regex
Expr
(
key
,
value
);
}
public
static
not
(
key
:
string
):
ContextKeyExpr
{
...
...
@@ -68,7 +67,7 @@ export abstract class ContextKeyExpr {
if
(
serializedOne
.
indexOf
(
'
=~
'
)
>=
0
)
{
let
pieces
=
serializedOne
.
split
(
'
=~
'
);
return
new
ContextKey
Glob
Expr
(
pieces
[
0
].
trim
(),
this
.
_deserializeValue
(
pieces
[
1
]));
return
new
ContextKey
Regex
Expr
(
pieces
[
0
].
trim
(),
this
.
_deserializeValue
(
pieces
[
1
]));
}
if
(
/^
\!\s
*/
.
test
(
serializedOne
))
{
...
...
@@ -120,8 +119,8 @@ function cmp(a: ContextKeyExpr, b: ContextKeyExpr): number {
return
(
<
ContextKeyEqualsExpr
>
a
).
cmp
(
<
ContextKeyEqualsExpr
>
b
);
case
ContextKeyExprType
.
NotEquals
:
return
(
<
ContextKeyNotEqualsExpr
>
a
).
cmp
(
<
ContextKeyNotEqualsExpr
>
b
);
case
ContextKeyExprType
.
Glob
:
return
(
<
ContextKey
GlobExpr
>
a
).
cmp
(
<
ContextKeyGlob
Expr
>
b
);
case
ContextKeyExprType
.
Regex
:
return
(
<
ContextKey
RegexExpr
>
a
).
cmp
(
<
ContextKeyRegex
Expr
>
b
);
default
:
throw
new
Error
(
'
Unknown ContextKeyExpr!
'
);
}
...
...
@@ -333,40 +332,48 @@ export class ContextKeyNotExpr implements ContextKeyExpr {
}
}
export
class
ContextKey
Glob
Expr
implements
ContextKeyExpr
{
export
class
ContextKey
Regex
Expr
implements
ContextKeyExpr
{
constructor
(
private
key
:
string
,
private
value
:
any
)
{
private
regexp
:
{
source
:
string
,
test
(
s
:
string
):
boolean
};
constructor
(
private
key
:
string
,
value
:
any
)
{
try
{
this
.
regexp
=
new
RegExp
(
value
);
}
catch
(
e
)
{
this
.
regexp
=
{
source
:
''
,
test
()
{
return
false
;
}
};
console
.
warn
(
`Bad value for glob-context key expression:
${
value
}
`
);
}
}
public
getType
():
ContextKeyExprType
{
return
ContextKeyExprType
.
Glob
;
return
ContextKeyExprType
.
Regex
;
}
public
cmp
(
other
:
ContextKey
Glob
Expr
):
number
{
public
cmp
(
other
:
ContextKey
Regex
Expr
):
number
{
if
(
this
.
key
<
other
.
key
)
{
return
-
1
;
}
if
(
this
.
key
>
other
.
key
)
{
return
1
;
}
if
(
this
.
value
<
other
.
valu
e
)
{
if
(
this
.
regexp
.
source
<
other
.
regexp
.
sourc
e
)
{
return
-
1
;
}
if
(
this
.
value
>
other
.
valu
e
)
{
if
(
this
.
regexp
.
source
>
other
.
regexp
.
sourc
e
)
{
return
1
;
}
return
0
;
}
public
equals
(
other
:
ContextKeyExpr
):
boolean
{
if
(
other
instanceof
ContextKey
Glob
Expr
)
{
return
(
this
.
key
===
other
.
key
&&
this
.
value
===
other
.
valu
e
);
if
(
other
instanceof
ContextKey
Regex
Expr
)
{
return
(
this
.
key
===
other
.
key
&&
this
.
regexp
.
source
===
other
.
regexp
.
sourc
e
);
}
return
false
;
}
public
evaluate
(
context
:
IContext
):
boolean
{
return
match
(
this
.
value
,
context
.
getValue
(
this
.
key
));
return
this
.
regexp
.
test
(
context
.
getValue
(
this
.
key
));
}
public
normalize
():
ContextKeyExpr
{
...
...
@@ -374,7 +381,7 @@ export class ContextKeyGlobExpr implements ContextKeyExpr {
}
public
serialize
():
string
{
return
this
.
key
+
'
=~
\'
'
+
this
.
valu
e
+
'
\'
'
;
return
this
.
key
+
'
=~
\'
'
+
this
.
regexp
.
sourc
e
+
'
\'
'
;
}
public
keys
():
string
[]
{
...
...
src/vs/platform/contextkey/test/common/contextkey.test.ts
浏览文件 @
24ecf494
...
...
@@ -6,7 +6,6 @@
import
*
as
assert
from
'
assert
'
;
import
{
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
match
}
from
'
vs/base/common/glob
'
;
function
createContext
(
ctx
:
any
)
{
return
{
...
...
@@ -22,8 +21,8 @@ suite('ContextKeyExpr', () => {
ContextKeyExpr
.
has
(
'
a1
'
),
ContextKeyExpr
.
and
(
ContextKeyExpr
.
has
(
'
and.a
'
)),
ContextKeyExpr
.
has
(
'
a2
'
),
ContextKeyExpr
.
glob
(
'
d3
'
,
'
**/d
*
'
),
ContextKeyExpr
.
glob
(
'
d4
'
,
'
*
*/3*
'
),
ContextKeyExpr
.
regex
(
'
d3
'
,
'
d.
*
'
),
ContextKeyExpr
.
regex
(
'
d4
'
,
'
\\
*
\\
*/3*
'
),
ContextKeyExpr
.
equals
(
'
b1
'
,
'
bb1
'
),
ContextKeyExpr
.
equals
(
'
b2
'
,
'
bb2
'
),
ContextKeyExpr
.
notEquals
(
'
c1
'
,
'
cc1
'
),
...
...
@@ -35,11 +34,11 @@ suite('ContextKeyExpr', () => {
ContextKeyExpr
.
equals
(
'
b2
'
,
'
bb2
'
),
ContextKeyExpr
.
notEquals
(
'
c1
'
,
'
cc1
'
),
ContextKeyExpr
.
not
(
'
d1
'
),
ContextKeyExpr
.
glob
(
'
d4
'
,
'
*
*/3*
'
),
ContextKeyExpr
.
regex
(
'
d4
'
,
'
\\
*
\\
*/3*
'
),
ContextKeyExpr
.
notEquals
(
'
c2
'
,
'
cc2
'
),
ContextKeyExpr
.
has
(
'
a2
'
),
ContextKeyExpr
.
equals
(
'
b1
'
,
'
bb1
'
),
ContextKeyExpr
.
glob
(
'
d3
'
,
'
**/d
*
'
),
ContextKeyExpr
.
regex
(
'
d3
'
,
'
d.
*
'
),
ContextKeyExpr
.
has
(
'
a1
'
),
ContextKeyExpr
.
and
(
ContextKeyExpr
.
equals
(
'
and.a
'
,
true
)),
ContextKeyExpr
.
not
(
'
d2
'
)
...
...
@@ -68,7 +67,7 @@ suite('ContextKeyExpr', () => {
'
d
'
:
'
d
'
});
function
testExpression
(
expr
:
string
,
expected
:
boolean
):
void
{
console
.
log
(
expr
+
'
'
+
expected
);
//
console.log(expr + ' ' + expected);
let
rules
=
ContextKeyExpr
.
deserialize
(
expr
);
assert
.
equal
(
rules
.
evaluate
(
context
),
expected
,
expr
);
}
...
...
@@ -81,7 +80,7 @@ suite('ContextKeyExpr', () => {
testExpression
(
expr
+
'
== 5
'
,
value
==
<
any
>
'
5
'
);
testExpression
(
expr
+
'
!= 5
'
,
value
!=
<
any
>
'
5
'
);
testExpression
(
'
!
'
+
expr
,
!
value
);
testExpression
(
expr
+
'
=~
**/d*
'
,
match
(
'
**/d*
'
,
value
));
testExpression
(
expr
+
'
=~
d.*
'
,
/d.*/
.
test
(
value
));
}
testBatch
(
'
a
'
,
true
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录