Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
2d584060
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,发现更多精彩内容 >>
提交
2d584060
编写于
2月 07, 2020
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
get rid of TokenClassification
上级
5e0189c8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
20 addition
and
67 deletion
+20
-67
src/vs/platform/theme/common/tokenClassificationRegistry.ts
src/vs/platform/theme/common/tokenClassificationRegistry.ts
+11
-46
src/vs/workbench/services/themes/common/colorThemeData.ts
src/vs/workbench/services/themes/common/colorThemeData.ts
+7
-14
src/vs/workbench/services/themes/test/electron-browser/tokenStyleResolving.test.ts
.../themes/test/electron-browser/tokenStyleResolving.test.ts
+2
-7
未找到文件。
src/vs/platform/theme/common/tokenClassificationRegistry.ts
浏览文件 @
2d584060
...
...
@@ -13,7 +13,6 @@ import { Event, Emitter } from 'vs/base/common/event';
import
{
IJSONSchema
,
IJSONSchemaMap
}
from
'
vs/base/common/jsonSchema
'
;
export
const
TOKEN_TYPE_WILDCARD
=
'
*
'
;
export
const
TOKEN_TYPE_WILDCARD_NUM
=
-
1
;
// qualified string [type|*](.modifier)*
export
type
TokenClassificationString
=
string
;
...
...
@@ -21,13 +20,8 @@ export type TokenClassificationString = string;
export
const
typeAndModifierIdPattern
=
'
^
\\
w+[-_
\\
w+]*$
'
;
export
const
fontStylePattern
=
'
^(
\\
s*(-?italic|-?bold|-?underline))*
\\
s*$
'
;
export
interface
TokenClassification
{
type
:
number
;
modifiers
:
number
;
}
export
interface
TokenSelector
{
match
(
classification
:
TokenClassification
):
number
;
match
(
type
:
string
,
modifiers
:
string
[]
):
number
;
asString
():
string
;
}
...
...
@@ -138,8 +132,6 @@ export interface ITokenClassificationRegistry {
*/
registerTokenModifier
(
id
:
string
,
description
:
string
):
void
;
getTokenClassification
(
type
:
string
,
modifiers
:
string
[]):
TokenClassification
|
undefined
;
/**
* Parses a token selector from a selector string.
* @param selectorString selector string in the form (*|type)(.modifier)*
...
...
@@ -241,8 +233,6 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
constructor
()
{
this
.
tokenTypeById
=
{};
this
.
tokenModifierById
=
{};
this
.
tokenTypeById
[
TOKEN_TYPE_WILDCARD
]
=
{
num
:
TOKEN_TYPE_WILDCARD_NUM
,
id
:
TOKEN_TYPE_WILDCARD
,
description
:
''
,
deprecationMessage
:
undefined
};
}
public
registerTokenType
(
id
:
string
,
description
:
string
,
deprecationMessage
?:
string
):
void
{
...
...
@@ -270,42 +260,27 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
this
.
tokenStylingSchema
.
properties
[
`*.
${
id
}
`
]
=
getStylingSchemeEntry
(
description
,
deprecationMessage
);
}
public
getTokenClassification
(
type
:
string
,
modifiers
:
string
[]):
TokenClassification
|
undefined
{
const
tokenTypeDesc
=
this
.
tokenTypeById
[
type
];
if
(
!
tokenTypeDesc
)
{
return
undefined
;
}
let
allModifierBits
=
0
;
for
(
const
modifier
of
modifiers
)
{
const
tokenModifierDesc
=
this
.
tokenModifierById
[
modifier
];
if
(
tokenModifierDesc
)
{
allModifierBits
|=
tokenModifierDesc
.
num
;
}
}
return
{
type
:
tokenTypeDesc
.
num
,
modifiers
:
allModifierBits
};
}
public
parseTokenSelector
(
selectorString
:
string
):
TokenSelector
{
const
[
type
,
...
m
odifiers
]
=
selectorString
.
split
(
'
.
'
);
const
[
selectorType
,
...
selectorM
odifiers
]
=
selectorString
.
split
(
'
.
'
);
const
selectorClassification
=
this
.
getTokenClassification
(
type
,
modifiers
);
if
(
!
selectorClassification
)
{
if
(
!
selectorType
)
{
return
{
match
:
()
=>
-
1
,
asString
:
()
=>
selectorString
};
}
const
score
=
getTokenStylingScore
(
selectorClassification
);
const
score
=
selectorModifiers
.
length
+
((
selectorString
!==
TOKEN_TYPE_WILDCARD
)
?
1
:
0
);
return
{
match
:
(
classification
:
TokenClassification
)
=>
{
if
(
selector
Classification
.
type
!==
TOKEN_TYPE_WILDCARD_NUM
&&
selectorClassification
.
type
!==
classification
.
type
)
{
match
:
(
type
:
string
,
modifiers
:
string
[]
)
=>
{
if
(
selector
Type
!==
TOKEN_TYPE_WILDCARD
&&
selectorType
!==
type
)
{
return
-
1
;
}
const
selectorModifier
=
selectorClassification
.
modifiers
;
if
((
classification
.
modifiers
&
selectorModifier
)
!==
selectorModifier
)
{
return
-
1
;
// all selector modifiers must be present
for
(
const
selectorModifier
of
selectorModifiers
)
{
if
(
modifiers
.
indexOf
(
selectorModifier
)
===
-
1
)
{
return
-
1
;
}
}
return
score
;
},
...
...
@@ -432,16 +407,6 @@ export function getTokenClassificationRegistry(): ITokenClassificationRegistry {
return
tokenClassificationRegistry
;
}
function
bitCount
(
u
:
number
)
{
// https://blogs.msdn.microsoft.com/jeuge/2005/06/08/bit-fiddling-3/
const
uCount
=
u
-
((
u
>>
1
)
&
0o33333333333
)
-
((
u
>>
2
)
&
0o11111111111
);
return
((
uCount
+
(
uCount
>>
3
))
&
0o30707070707
)
%
63
;
}
function
getTokenStylingScore
(
classification
:
TokenClassification
)
{
return
bitCount
(
classification
.
modifiers
)
+
((
classification
.
type
!==
TOKEN_TYPE_WILDCARD_NUM
)
?
1
:
0
);
}
function
getStylingSchemeEntry
(
description
?:
string
,
deprecationMessage
?:
string
):
IJSONSchema
{
return
{
description
,
...
...
src/vs/workbench/services/themes/common/colorThemeData.ts
浏览文件 @
2d584060
...
...
@@ -19,7 +19,7 @@ import { getParseErrorMessage } from 'vs/base/common/jsonErrorMessages';
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
parse
as
parsePList
}
from
'
vs/workbench/services/themes/common/plistParser
'
;
import
{
startsWith
}
from
'
vs/base/common/strings
'
;
import
{
TokenStyle
,
TokenClassification
,
ProbeScope
,
TokenStylingRule
,
getTokenClassificationRegistry
,
TokenStyleValue
,
TokenStyleData
}
from
'
vs/platform/theme/common/tokenClassificationRegistry
'
;
import
{
TokenStyle
,
ProbeScope
,
TokenStylingRule
,
getTokenClassificationRegistry
,
TokenStyleValue
,
TokenStyleData
}
from
'
vs/platform/theme/common/tokenClassificationRegistry
'
;
import
{
MatcherWithPriority
,
Matcher
,
createMatchers
}
from
'
vs/workbench/services/themes/common/textMateScopeMatcher
'
;
import
{
IExtensionResourceLoaderService
}
from
'
vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
...
...
@@ -124,7 +124,7 @@ export class ColorThemeData implements IColorTheme {
return
color
;
}
public
getTokenStyle
(
classification
:
TokenClassification
,
useDefault
=
true
,
definitions
:
TokenStyleDefinitions
=
{}):
TokenStyle
|
undefined
{
public
getTokenStyle
(
type
:
string
,
modifiers
:
string
[]
,
useDefault
=
true
,
definitions
:
TokenStyleDefinitions
=
{}):
TokenStyle
|
undefined
{
let
result
:
any
=
{
foreground
:
undefined
,
bold
:
undefined
,
...
...
@@ -158,7 +158,7 @@ export class ColorThemeData implements IColorTheme {
}
if
(
this
.
tokenStylingRules
===
undefined
)
{
for
(
const
rule
of
tokenClassificationRegistry
.
getTokenStylingDefaultRules
())
{
const
matchScore
=
rule
.
selector
.
match
(
classification
);
const
matchScore
=
rule
.
selector
.
match
(
type
,
modifiers
);
if
(
matchScore
>=
0
)
{
let
style
:
TokenStyle
|
undefined
;
if
(
rule
.
defaults
.
scopesToProbe
)
{
...
...
@@ -178,14 +178,14 @@ export class ColorThemeData implements IColorTheme {
}
}
else
{
for
(
const
rule
of
this
.
tokenStylingRules
)
{
const
matchScore
=
rule
.
selector
.
match
(
classification
);
const
matchScore
=
rule
.
selector
.
match
(
type
,
modifiers
);
if
(
matchScore
>=
0
)
{
_processStyle
(
matchScore
,
rule
.
style
,
rule
);
}
}
}
for
(
const
rule
of
this
.
customTokenStylingRules
)
{
const
matchScore
=
rule
.
selector
.
match
(
classification
);
const
matchScore
=
rule
.
selector
.
match
(
type
,
modifiers
);
if
(
matchScore
>=
0
)
{
_processStyle
(
matchScore
,
rule
.
style
,
rule
);
}
...
...
@@ -202,10 +202,7 @@ export class ColorThemeData implements IColorTheme {
return
undefined
;
}
else
if
(
typeof
tokenStyleValue
===
'
string
'
)
{
const
[
type
,
...
modifiers
]
=
tokenStyleValue
.
split
(
'
.
'
);
const
classification
=
tokenClassificationRegistry
.
getTokenClassification
(
type
,
modifiers
);
if
(
classification
)
{
return
this
.
getTokenStyle
(
classification
);
}
return
this
.
getTokenStyle
(
type
,
modifiers
);
}
else
if
(
typeof
tokenStyleValue
===
'
object
'
)
{
return
tokenStyleValue
;
}
...
...
@@ -243,11 +240,7 @@ export class ColorThemeData implements IColorTheme {
}
public
getTokenStyleMetadata
(
type
:
string
,
modifiers
:
string
[],
useDefault
=
true
,
definitions
:
TokenStyleDefinitions
=
{}):
ITokenStyle
|
undefined
{
const
classification
=
tokenClassificationRegistry
.
getTokenClassification
(
type
,
modifiers
);
if
(
!
classification
)
{
return
undefined
;
}
const
style
=
this
.
getTokenStyle
(
classification
,
useDefault
,
definitions
);
const
style
=
this
.
getTokenStyle
(
type
,
modifiers
,
useDefault
,
definitions
);
if
(
!
style
)
{
return
undefined
;
}
...
...
src/vs/workbench/services/themes/test/electron-browser/tokenStyleResolving.test.ts
浏览文件 @
2d584060
...
...
@@ -6,7 +6,7 @@
import
{
ColorThemeData
}
from
'
vs/workbench/services/themes/common/colorThemeData
'
;
import
*
as
assert
from
'
assert
'
;
import
{
ITokenColorCustomizations
}
from
'
vs/workbench/services/themes/common/workbenchThemeService
'
;
import
{
TokenStyle
,
getTokenClassificationRegistry
}
from
'
vs/platform/theme/common/tokenClassificationRegistry
'
;
import
{
TokenStyle
}
from
'
vs/platform/theme/common/tokenClassificationRegistry
'
;
import
{
Color
}
from
'
vs/base/common/color
'
;
import
{
isString
}
from
'
vs/base/common/types
'
;
import
{
FileService
}
from
'
vs/platform/files/common/fileService
'
;
...
...
@@ -18,8 +18,6 @@ import { getPathFromAmdModule } from 'vs/base/common/amd';
import
{
ExtensionResourceLoaderService
}
from
'
vs/workbench/services/extensionResourceLoader/electron-browser/extensionResourceLoaderService
'
;
import
{
ITokenStyle
}
from
'
vs/platform/theme/common/themeService
'
;
let
tokenClassificationRegistry
=
getTokenClassificationRegistry
();
const
undefinedStyle
=
{
bold
:
undefined
,
underline
:
undefined
,
italic
:
undefined
};
const
unsetStyle
=
{
bold
:
false
,
underline
:
false
,
italic
:
false
};
...
...
@@ -73,10 +71,7 @@ function assertTokenStyles(themeData: ColorThemeData, expected: { [qualifiedClas
for
(
let
qualifiedClassifier
in
expected
)
{
const
[
type
,
...
modifiers
]
=
qualifiedClassifier
.
split
(
'
.
'
);
const
classification
=
tokenClassificationRegistry
.
getTokenClassification
(
type
,
modifiers
);
assert
.
ok
(
classification
,
'
Classification not found
'
);
const
tokenStyle
=
themeData
.
getTokenStyle
(
classification
!
);
const
tokenStyle
=
themeData
.
getTokenStyle
(
type
,
modifiers
);
const
expectedTokenStyle
=
expected
[
qualifiedClassifier
];
assertTokenStyle
(
tokenStyle
,
expectedTokenStyle
,
qualifiedClassifier
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录