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';
...
@@ -13,7 +13,6 @@ import { Event, Emitter } from 'vs/base/common/event';
import
{
IJSONSchema
,
IJSONSchemaMap
}
from
'
vs/base/common/jsonSchema
'
;
import
{
IJSONSchema
,
IJSONSchemaMap
}
from
'
vs/base/common/jsonSchema
'
;
export
const
TOKEN_TYPE_WILDCARD
=
'
*
'
;
export
const
TOKEN_TYPE_WILDCARD
=
'
*
'
;
export
const
TOKEN_TYPE_WILDCARD_NUM
=
-
1
;
// qualified string [type|*](.modifier)*
// qualified string [type|*](.modifier)*
export
type
TokenClassificationString
=
string
;
export
type
TokenClassificationString
=
string
;
...
@@ -21,13 +20,8 @@ export type TokenClassificationString = string;
...
@@ -21,13 +20,8 @@ export type TokenClassificationString = string;
export
const
typeAndModifierIdPattern
=
'
^
\\
w+[-_
\\
w+]*$
'
;
export
const
typeAndModifierIdPattern
=
'
^
\\
w+[-_
\\
w+]*$
'
;
export
const
fontStylePattern
=
'
^(
\\
s*(-?italic|-?bold|-?underline))*
\\
s*$
'
;
export
const
fontStylePattern
=
'
^(
\\
s*(-?italic|-?bold|-?underline))*
\\
s*$
'
;
export
interface
TokenClassification
{
type
:
number
;
modifiers
:
number
;
}
export
interface
TokenSelector
{
export
interface
TokenSelector
{
match
(
classification
:
TokenClassification
):
number
;
match
(
type
:
string
,
modifiers
:
string
[]
):
number
;
asString
():
string
;
asString
():
string
;
}
}
...
@@ -138,8 +132,6 @@ export interface ITokenClassificationRegistry {
...
@@ -138,8 +132,6 @@ export interface ITokenClassificationRegistry {
*/
*/
registerTokenModifier
(
id
:
string
,
description
:
string
):
void
;
registerTokenModifier
(
id
:
string
,
description
:
string
):
void
;
getTokenClassification
(
type
:
string
,
modifiers
:
string
[]):
TokenClassification
|
undefined
;
/**
/**
* Parses a token selector from a selector string.
* Parses a token selector from a selector string.
* @param selectorString selector string in the form (*|type)(.modifier)*
* @param selectorString selector string in the form (*|type)(.modifier)*
...
@@ -241,8 +233,6 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
...
@@ -241,8 +233,6 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
constructor
()
{
constructor
()
{
this
.
tokenTypeById
=
{};
this
.
tokenTypeById
=
{};
this
.
tokenModifierById
=
{};
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
{
public
registerTokenType
(
id
:
string
,
description
:
string
,
deprecationMessage
?:
string
):
void
{
...
@@ -270,43 +260,28 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
...
@@ -270,43 +260,28 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
this
.
tokenStylingSchema
.
properties
[
`*.
${
id
}
`
]
=
getStylingSchemeEntry
(
description
,
deprecationMessage
);
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
{
public
parseTokenSelector
(
selectorString
:
string
):
TokenSelector
{
const
[
type
,
...
m
odifiers
]
=
selectorString
.
split
(
'
.
'
);
const
[
selectorType
,
...
selectorM
odifiers
]
=
selectorString
.
split
(
'
.
'
);
const
selectorClassification
=
this
.
getTokenClassification
(
type
,
modifiers
);
if
(
!
selectorType
)
{
if
(
!
selectorClassification
)
{
return
{
return
{
match
:
()
=>
-
1
,
match
:
()
=>
-
1
,
asString
:
()
=>
selectorString
asString
:
()
=>
selectorString
};
};
}
}
const
score
=
getTokenStylingScore
(
selectorClassification
);
const
score
=
selectorModifiers
.
length
+
((
selectorString
!==
TOKEN_TYPE_WILDCARD
)
?
1
:
0
);
return
{
return
{
match
:
(
classification
:
TokenClassification
)
=>
{
match
:
(
type
:
string
,
modifiers
:
string
[]
)
=>
{
if
(
selector
Classification
.
type
!==
TOKEN_TYPE_WILDCARD_NUM
&&
selectorClassification
.
type
!==
classification
.
type
)
{
if
(
selector
Type
!==
TOKEN_TYPE_WILDCARD
&&
selectorType
!==
type
)
{
return
-
1
;
return
-
1
;
}
}
const
selectorModifier
=
selectorClassification
.
modifiers
;
// all selector modifiers must be present
if
((
classification
.
modifiers
&
selectorModifier
)
!==
selectorModifier
)
{
for
(
const
selectorModifier
of
selectorModifiers
)
{
if
(
modifiers
.
indexOf
(
selectorModifier
)
===
-
1
)
{
return
-
1
;
return
-
1
;
}
}
}
return
score
;
return
score
;
},
},
asString
:
()
=>
selectorString
asString
:
()
=>
selectorString
...
@@ -432,16 +407,6 @@ export function getTokenClassificationRegistry(): ITokenClassificationRegistry {
...
@@ -432,16 +407,6 @@ export function getTokenClassificationRegistry(): ITokenClassificationRegistry {
return
tokenClassificationRegistry
;
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
{
function
getStylingSchemeEntry
(
description
?:
string
,
deprecationMessage
?:
string
):
IJSONSchema
{
return
{
return
{
description
,
description
,
...
...
src/vs/workbench/services/themes/common/colorThemeData.ts
浏览文件 @
2d584060
...
@@ -19,7 +19,7 @@ import { getParseErrorMessage } from 'vs/base/common/jsonErrorMessages';
...
@@ -19,7 +19,7 @@ import { getParseErrorMessage } from 'vs/base/common/jsonErrorMessages';
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
parse
as
parsePList
}
from
'
vs/workbench/services/themes/common/plistParser
'
;
import
{
parse
as
parsePList
}
from
'
vs/workbench/services/themes/common/plistParser
'
;
import
{
startsWith
}
from
'
vs/base/common/strings
'
;
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
{
MatcherWithPriority
,
Matcher
,
createMatchers
}
from
'
vs/workbench/services/themes/common/textMateScopeMatcher
'
;
import
{
IExtensionResourceLoaderService
}
from
'
vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader
'
;
import
{
IExtensionResourceLoaderService
}
from
'
vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
...
@@ -124,7 +124,7 @@ export class ColorThemeData implements IColorTheme {
...
@@ -124,7 +124,7 @@ export class ColorThemeData implements IColorTheme {
return
color
;
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
=
{
let
result
:
any
=
{
foreground
:
undefined
,
foreground
:
undefined
,
bold
:
undefined
,
bold
:
undefined
,
...
@@ -158,7 +158,7 @@ export class ColorThemeData implements IColorTheme {
...
@@ -158,7 +158,7 @@ export class ColorThemeData implements IColorTheme {
}
}
if
(
this
.
tokenStylingRules
===
undefined
)
{
if
(
this
.
tokenStylingRules
===
undefined
)
{
for
(
const
rule
of
tokenClassificationRegistry
.
getTokenStylingDefaultRules
())
{
for
(
const
rule
of
tokenClassificationRegistry
.
getTokenStylingDefaultRules
())
{
const
matchScore
=
rule
.
selector
.
match
(
classification
);
const
matchScore
=
rule
.
selector
.
match
(
type
,
modifiers
);
if
(
matchScore
>=
0
)
{
if
(
matchScore
>=
0
)
{
let
style
:
TokenStyle
|
undefined
;
let
style
:
TokenStyle
|
undefined
;
if
(
rule
.
defaults
.
scopesToProbe
)
{
if
(
rule
.
defaults
.
scopesToProbe
)
{
...
@@ -178,14 +178,14 @@ export class ColorThemeData implements IColorTheme {
...
@@ -178,14 +178,14 @@ export class ColorThemeData implements IColorTheme {
}
}
}
else
{
}
else
{
for
(
const
rule
of
this
.
tokenStylingRules
)
{
for
(
const
rule
of
this
.
tokenStylingRules
)
{
const
matchScore
=
rule
.
selector
.
match
(
classification
);
const
matchScore
=
rule
.
selector
.
match
(
type
,
modifiers
);
if
(
matchScore
>=
0
)
{
if
(
matchScore
>=
0
)
{
_processStyle
(
matchScore
,
rule
.
style
,
rule
);
_processStyle
(
matchScore
,
rule
.
style
,
rule
);
}
}
}
}
}
}
for
(
const
rule
of
this
.
customTokenStylingRules
)
{
for
(
const
rule
of
this
.
customTokenStylingRules
)
{
const
matchScore
=
rule
.
selector
.
match
(
classification
);
const
matchScore
=
rule
.
selector
.
match
(
type
,
modifiers
);
if
(
matchScore
>=
0
)
{
if
(
matchScore
>=
0
)
{
_processStyle
(
matchScore
,
rule
.
style
,
rule
);
_processStyle
(
matchScore
,
rule
.
style
,
rule
);
}
}
...
@@ -202,10 +202,7 @@ export class ColorThemeData implements IColorTheme {
...
@@ -202,10 +202,7 @@ export class ColorThemeData implements IColorTheme {
return
undefined
;
return
undefined
;
}
else
if
(
typeof
tokenStyleValue
===
'
string
'
)
{
}
else
if
(
typeof
tokenStyleValue
===
'
string
'
)
{
const
[
type
,
...
modifiers
]
=
tokenStyleValue
.
split
(
'
.
'
);
const
[
type
,
...
modifiers
]
=
tokenStyleValue
.
split
(
'
.
'
);
const
classification
=
tokenClassificationRegistry
.
getTokenClassification
(
type
,
modifiers
);
return
this
.
getTokenStyle
(
type
,
modifiers
);
if
(
classification
)
{
return
this
.
getTokenStyle
(
classification
);
}
}
else
if
(
typeof
tokenStyleValue
===
'
object
'
)
{
}
else
if
(
typeof
tokenStyleValue
===
'
object
'
)
{
return
tokenStyleValue
;
return
tokenStyleValue
;
}
}
...
@@ -243,11 +240,7 @@ export class ColorThemeData implements IColorTheme {
...
@@ -243,11 +240,7 @@ export class ColorThemeData implements IColorTheme {
}
}
public
getTokenStyleMetadata
(
type
:
string
,
modifiers
:
string
[],
useDefault
=
true
,
definitions
:
TokenStyleDefinitions
=
{}):
ITokenStyle
|
undefined
{
public
getTokenStyleMetadata
(
type
:
string
,
modifiers
:
string
[],
useDefault
=
true
,
definitions
:
TokenStyleDefinitions
=
{}):
ITokenStyle
|
undefined
{
const
classification
=
tokenClassificationRegistry
.
getTokenClassification
(
type
,
modifiers
);
const
style
=
this
.
getTokenStyle
(
type
,
modifiers
,
useDefault
,
definitions
);
if
(
!
classification
)
{
return
undefined
;
}
const
style
=
this
.
getTokenStyle
(
classification
,
useDefault
,
definitions
);
if
(
!
style
)
{
if
(
!
style
)
{
return
undefined
;
return
undefined
;
}
}
...
...
src/vs/workbench/services/themes/test/electron-browser/tokenStyleResolving.test.ts
浏览文件 @
2d584060
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
import
{
ColorThemeData
}
from
'
vs/workbench/services/themes/common/colorThemeData
'
;
import
{
ColorThemeData
}
from
'
vs/workbench/services/themes/common/colorThemeData
'
;
import
*
as
assert
from
'
assert
'
;
import
*
as
assert
from
'
assert
'
;
import
{
ITokenColorCustomizations
}
from
'
vs/workbench/services/themes/common/workbenchThemeService
'
;
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
{
Color
}
from
'
vs/base/common/color
'
;
import
{
isString
}
from
'
vs/base/common/types
'
;
import
{
isString
}
from
'
vs/base/common/types
'
;
import
{
FileService
}
from
'
vs/platform/files/common/fileService
'
;
import
{
FileService
}
from
'
vs/platform/files/common/fileService
'
;
...
@@ -18,8 +18,6 @@ import { getPathFromAmdModule } from 'vs/base/common/amd';
...
@@ -18,8 +18,6 @@ import { getPathFromAmdModule } from 'vs/base/common/amd';
import
{
ExtensionResourceLoaderService
}
from
'
vs/workbench/services/extensionResourceLoader/electron-browser/extensionResourceLoaderService
'
;
import
{
ExtensionResourceLoaderService
}
from
'
vs/workbench/services/extensionResourceLoader/electron-browser/extensionResourceLoaderService
'
;
import
{
ITokenStyle
}
from
'
vs/platform/theme/common/themeService
'
;
import
{
ITokenStyle
}
from
'
vs/platform/theme/common/themeService
'
;
let
tokenClassificationRegistry
=
getTokenClassificationRegistry
();
const
undefinedStyle
=
{
bold
:
undefined
,
underline
:
undefined
,
italic
:
undefined
};
const
undefinedStyle
=
{
bold
:
undefined
,
underline
:
undefined
,
italic
:
undefined
};
const
unsetStyle
=
{
bold
:
false
,
underline
:
false
,
italic
:
false
};
const
unsetStyle
=
{
bold
:
false
,
underline
:
false
,
italic
:
false
};
...
@@ -73,10 +71,7 @@ function assertTokenStyles(themeData: ColorThemeData, expected: { [qualifiedClas
...
@@ -73,10 +71,7 @@ function assertTokenStyles(themeData: ColorThemeData, expected: { [qualifiedClas
for
(
let
qualifiedClassifier
in
expected
)
{
for
(
let
qualifiedClassifier
in
expected
)
{
const
[
type
,
...
modifiers
]
=
qualifiedClassifier
.
split
(
'
.
'
);
const
[
type
,
...
modifiers
]
=
qualifiedClassifier
.
split
(
'
.
'
);
const
classification
=
tokenClassificationRegistry
.
getTokenClassification
(
type
,
modifiers
);
const
tokenStyle
=
themeData
.
getTokenStyle
(
type
,
modifiers
);
assert
.
ok
(
classification
,
'
Classification not found
'
);
const
tokenStyle
=
themeData
.
getTokenStyle
(
classification
!
);
const
expectedTokenStyle
=
expected
[
qualifiedClassifier
];
const
expectedTokenStyle
=
expected
[
qualifiedClassifier
];
assertTokenStyle
(
tokenStyle
,
expectedTokenStyle
,
qualifiedClassifier
);
assertTokenStyle
(
tokenStyle
,
expectedTokenStyle
,
qualifiedClassifier
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录