Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
517e4391
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,发现更多精彩内容 >>
提交
517e4391
编写于
1月 13, 2020
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
readonly semantic highlighting
上级
0fde639a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
61 addition
and
14 deletion
+61
-14
extensions/html-language-features/server/src/modes/javascriptSemanticTokens.ts
...age-features/server/src/modes/javascriptSemanticTokens.ts
+33
-7
extensions/html-language-features/server/src/test/semanticTokens.test.ts
...-language-features/server/src/test/semanticTokens.test.ts
+27
-7
src/vs/platform/theme/common/tokenClassificationRegistry.ts
src/vs/platform/theme/common/tokenClassificationRegistry.ts
+1
-0
未找到文件。
extensions/html-language-features/server/src/modes/javascriptSemanticTokens.ts
浏览文件 @
517e4391
...
...
@@ -20,9 +20,10 @@ export function getSemanticTokens(jsLanguageService: ts.LanguageService, current
if
(
node
.
kind
===
ts
.
SyntaxKind
.
Identifier
)
{
const
symbol
=
typeChecker
.
getSymbolAtLocation
(
node
);
if
(
symbol
)
{
const
decl
=
symbol
.
valueDeclaration
||
symbol
.
declarations
&&
symbol
.
declarations
[
0
];
if
(
decl
)
{
let
typeIdx
=
tokenFromDeclarationMapping
[
decl
.
kind
];
let
typeIdx
=
classifySymbol
(
symbol
);
if
(
typeIdx
!==
undefined
)
{
let
modifierSet
=
0
;
if
(
node
.
parent
)
{
const
parentTypeIdx
=
tokenFromDeclarationMapping
[
node
.
parent
.
kind
];
...
...
@@ -30,16 +31,19 @@ export function getSemanticTokens(jsLanguageService: ts.LanguageService, current
modifierSet
=
TokenModifier
.
declaration
;
}
}
const
modifiers
=
ts
.
getCombinedModifierFlags
(
decl
);
const
decl
=
symbol
.
valueDeclaration
;
const
modifiers
=
decl
?
ts
.
getCombinedModifierFlags
(
decl
)
:
0
;
const
nodeFlags
=
decl
?
ts
.
getCombinedNodeFlags
(
decl
)
:
0
;
if
(
modifiers
&
ts
.
ModifierFlags
.
Static
)
{
modifierSet
|=
TokenModifier
.
static
;
}
if
(
modifiers
&
ts
.
ModifierFlags
.
Async
)
{
modifierSet
|=
TokenModifier
.
async
;
}
if
(
typeIdx
!==
undefined
)
{
resultTokens
.
push
({
start
:
currentTextDocument
.
positionAt
(
node
.
getStart
()),
length
:
node
.
getWidth
(),
typeIdx
,
modifierSet
})
;
if
(
(
modifiers
&
ts
.
ModifierFlags
.
Readonly
)
||
(
nodeFlags
&
ts
.
NodeFlags
.
Const
)
)
{
modifierSet
|=
TokenModifier
.
readonly
;
}
resultTokens
.
push
({
start
:
currentTextDocument
.
positionAt
(
node
.
getStart
()),
length
:
node
.
getWidth
(),
typeIdx
,
modifierSet
});
}
}
}
...
...
@@ -55,6 +59,27 @@ export function getSemanticTokens(jsLanguageService: ts.LanguageService, current
return
resultTokens
;
}
function
classifySymbol
(
symbol
:
ts
.
Symbol
)
{
const
flags
=
symbol
.
getFlags
();
if
(
flags
&
ts
.
SymbolFlags
.
Class
)
{
return
TokenType
.
class
;
}
else
if
(
flags
&
ts
.
SymbolFlags
.
Enum
)
{
return
TokenType
.
enum
;
}
else
if
(
flags
&
ts
.
SymbolFlags
.
TypeAlias
)
{
return
TokenType
.
type
;
}
else
if
(
flags
&
ts
.
SymbolFlags
.
Type
)
{
if
(
flags
&
ts
.
SymbolFlags
.
Interface
)
{
return
TokenType
.
interface
;
}
if
(
flags
&
ts
.
SymbolFlags
.
TypeParameter
)
{
return
TokenType
.
typeParameter
;
}
}
const
decl
=
symbol
.
valueDeclaration
||
symbol
.
declarations
&&
symbol
.
declarations
[
0
];
return
tokenFromDeclarationMapping
[
decl
.
kind
];
}
export
function
getSemanticTokenLegend
()
{
return
{
types
:
tokenTypes
,
modifiers
:
tokenModifiers
};
...
...
@@ -62,7 +87,7 @@ export function getSemanticTokenLegend() {
const
tokenTypes
:
string
[]
=
[
'
class
'
,
'
enum
'
,
'
interface
'
,
'
namespace
'
,
'
typeParameter
'
,
'
type
'
,
'
parameter
'
,
'
variable
'
,
'
property
'
,
'
constant
'
,
'
function
'
,
'
member
'
];
const
tokenModifiers
:
string
[]
=
[
'
declaration
'
,
'
static
'
,
'
async
'
];
const
tokenModifiers
:
string
[]
=
[
'
declaration
'
,
'
static
'
,
'
async
'
,
'
readonly
'
];
const
enum
TokenType
{
'
class
'
=
0
,
...
...
@@ -84,6 +109,7 @@ const enum TokenModifier {
'
declaration
'
=
0x01
,
'
static
'
=
0x02
,
'
async
'
=
0x04
,
'
readonly
'
=
0x08
,
}
const
tokenFromDeclarationMapping
:
{
[
name
:
string
]:
TokenType
}
=
{
...
...
extensions/html-language-features/server/src/test/semanticTokens.test.ts
浏览文件 @
517e4391
...
...
@@ -55,7 +55,7 @@ suite('HTML Semantic Tokens', () => {
/*2*/
'
<script>
'
,
/*3*/
'
var x = 9, y1 = [x];
'
,
/*4*/
'
try {
'
,
/*5*/
'
for (const s of y1) { }
'
,
/*5*/
'
for (const s of y1) {
x = s
}
'
,
/*6*/
'
} catch (e) {
'
,
/*7*/
'
throw y1;
'
,
/*8*/
'
}
'
,
...
...
@@ -65,7 +65,7 @@ suite('HTML Semantic Tokens', () => {
];
assertTokens
(
input
,
[
t
(
3
,
6
,
1
,
'
variable.declaration
'
),
t
(
3
,
13
,
2
,
'
variable.declaration
'
),
t
(
3
,
19
,
1
,
'
variable
'
),
t
(
5
,
15
,
1
,
'
variable.declaration
'
),
t
(
5
,
20
,
2
,
'
variable
'
),
t
(
5
,
15
,
1
,
'
variable.declaration
.readonly
'
),
t
(
5
,
20
,
2
,
'
variable
'
),
t
(
5
,
26
,
1
,
'
variable
'
),
t
(
5
,
30
,
1
,
'
variable.readonly
'
),
t
(
6
,
11
,
1
,
'
variable.declaration
'
),
t
(
7
,
10
,
2
,
'
variable
'
)
]);
...
...
@@ -86,7 +86,7 @@ suite('HTML Semantic Tokens', () => {
];
assertTokens
(
input
,
[
t
(
3
,
11
,
3
,
'
function.declaration
'
),
t
(
3
,
15
,
2
,
'
parameter.declaration
'
),
t
(
4
,
11
,
3
,
'
function
'
),
t
(
4
,
15
,
4
,
'
variabl
e
'
),
t
(
4
,
20
,
3
,
'
member
'
),
t
(
4
,
24
,
2
,
'
parameter
'
),
t
(
4
,
11
,
3
,
'
function
'
),
t
(
4
,
15
,
4
,
'
interfac
e
'
),
t
(
4
,
20
,
3
,
'
member
'
),
t
(
4
,
24
,
2
,
'
parameter
'
),
t
(
6
,
6
,
6
,
'
variable
'
),
t
(
6
,
13
,
8
,
'
property
'
),
t
(
6
,
24
,
5
,
'
member
'
),
t
(
6
,
35
,
7
,
'
member
'
),
t
(
6
,
43
,
1
,
'
parameter.declaration
'
),
t
(
6
,
48
,
3
,
'
function
'
),
t
(
6
,
52
,
1
,
'
parameter
'
)
]);
});
...
...
@@ -134,8 +134,28 @@ suite('HTML Semantic Tokens', () => {
];
assertTokens
(
input
,
[
t
(
3
,
12
,
8
,
'
interface.declaration
'
),
t
(
3
,
23
,
1
,
'
property.declaration
'
),
t
(
3
,
34
,
1
,
'
property.declaration
'
),
t
(
4
,
8
,
1
,
'
variable.declaration
'
),
t
(
4
,
30
,
8
,
'
interface
'
),
t
(
5
,
8
,
3
,
'
variable.declaration
'
),
t
(
5
,
15
,
1
,
'
parameter.declaration
'
),
t
(
5
,
18
,
8
,
'
interface
'
),
t
(
5
,
31
,
1
,
'
parameter
'
),
t
(
5
,
33
,
1
,
'
property
'
),
t
(
5
,
37
,
1
,
'
parameter
'
),
t
(
5
,
39
,
1
,
'
property
'
)
t
(
4
,
8
,
1
,
'
variable.declaration.readonly
'
),
t
(
4
,
30
,
8
,
'
interface
'
),
t
(
5
,
8
,
3
,
'
variable.declaration.readonly
'
),
t
(
5
,
15
,
1
,
'
parameter.declaration
'
),
t
(
5
,
18
,
8
,
'
interface
'
),
t
(
5
,
31
,
1
,
'
parameter
'
),
t
(
5
,
33
,
1
,
'
property
'
),
t
(
5
,
37
,
1
,
'
parameter
'
),
t
(
5
,
39
,
1
,
'
property
'
)
]);
});
test
(
'
Readonly
'
,
()
=>
{
const
input
=
[
/*0*/
'
<html>
'
,
/*1*/
'
<head>
'
,
/*2*/
'
<script type="text/typescript">
'
,
/*3*/
'
const f = 9;
'
,
/*4*/
'
class A { static readonly t = 9; static url: URL; }
'
,
/*5*/
'
const enum E { A = 9, B = A + 1 }
'
,
/*6*/
'
const x = f + A.t + A.url.origin;
'
,
/*7*/
'
</script>
'
,
/*8*/
'
</head>
'
,
/*9*/
'
</html>
'
,
];
assertTokens
(
input
,
[
t
(
3
,
8
,
1
,
'
variable.declaration.readonly
'
),
t
(
4
,
8
,
1
,
'
class.declaration
'
),
t
(
4
,
28
,
1
,
'
property.declaration.static.readonly
'
),
t
(
4
,
42
,
3
,
'
property.declaration.static
'
),
t
(
4
,
47
,
3
,
'
interface
'
),
t
(
6
,
8
,
1
,
'
variable.declaration.readonly
'
),
t
(
6
,
12
,
1
,
'
variable.readonly
'
),
t
(
6
,
16
,
1
,
'
class
'
),
t
(
6
,
18
,
1
,
'
property.static.readonly
'
),
t
(
6
,
22
,
1
,
'
class
'
),
t
(
6
,
24
,
3
,
'
property.static
'
),
t
(
6
,
28
,
6
,
'
property.readonly
'
),
]);
});
...
...
@@ -154,9 +174,9 @@ suite('HTML Semantic Tokens', () => {
/*9*/
'
</html>
'
,
];
assertTokens
(
input
,
[
t
(
3
,
7
,
5
,
'
type.declaration
'
),
t
(
3
,
15
,
3
,
'
variabl
e
'
)
/* to investiagte */
,
t
(
3
,
7
,
5
,
'
type.declaration
'
),
t
(
3
,
15
,
3
,
'
interfac
e
'
)
/* to investiagte */
,
t
(
4
,
11
,
1
,
'
function.declaration
'
),
t
(
4
,
13
,
1
,
'
typeParameter.declaration
'
),
t
(
4
,
23
,
5
,
'
type
'
),
t
(
4
,
30
,
1
,
'
parameter.declaration
'
),
t
(
4
,
33
,
1
,
'
typeParameter
'
),
t
(
4
,
47
,
1
,
'
typeParameter
'
),
t
(
5
,
12
,
1
,
'
typeParameter
'
),
t
(
5
,
29
,
3
,
'
variabl
e
'
),
t
(
5
,
41
,
5
,
'
type
'
),
t
(
5
,
12
,
1
,
'
typeParameter
'
),
t
(
5
,
29
,
3
,
'
interfac
e
'
),
t
(
5
,
41
,
5
,
'
type
'
),
]);
});
...
...
src/vs/platform/theme/common/tokenClassificationRegistry.ts
浏览文件 @
517e4391
...
...
@@ -400,6 +400,7 @@ function registerDefaultClassifications(): void {
tokenClassificationRegistry
.
registerTokenModifier
(
'
deprecated
'
,
nls
.
localize
(
'
deprecated
'
,
"
Style to use for symbols that are deprecated.
"
),
undefined
);
tokenClassificationRegistry
.
registerTokenModifier
(
'
modification
'
,
nls
.
localize
(
'
modification
'
,
"
Style to use for write accesses.
"
),
undefined
);
tokenClassificationRegistry
.
registerTokenModifier
(
'
async
'
,
nls
.
localize
(
'
async
'
,
"
Style to use for symbols that are async.
"
),
undefined
);
tokenClassificationRegistry
.
registerTokenModifier
(
'
readonly
'
,
nls
.
localize
(
'
readonly
'
,
"
Style to use for symbols that are readonly.
"
),
undefined
);
}
export
function
getTokenClassificationRegistry
():
ITokenClassificationRegistry
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录