Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
661bc5da
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,发现更多精彩内容 >>
提交
661bc5da
编写于
1月 14, 2020
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
define constants in typescript-vscode-sh-plugin
上级
d5c8eac6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
53 addition
and
66 deletion
+53
-66
extensions/typescript-language-features/package.json
extensions/typescript-language-features/package.json
+1
-1
extensions/typescript-language-features/src/features/semanticTokens.ts
...pescript-language-features/src/features/semanticTokens.ts
+48
-60
extensions/typescript-language-features/src/utils/api.ts
extensions/typescript-language-features/src/utils/api.ts
+0
-1
extensions/typescript-language-features/yarn.lock
extensions/typescript-language-features/yarn.lock
+4
-4
未找到文件。
extensions/typescript-language-features/package.json
浏览文件 @
661bc5da
...
...
@@ -19,7 +19,7 @@
"jsonc-parser"
:
"^2.1.1"
,
"rimraf"
:
"^2.6.3"
,
"semver"
:
"5.5.1"
,
"typescript-vscode-sh-plugin"
:
"^0.
3.2
"
,
"typescript-vscode-sh-plugin"
:
"^0.
5.0
"
,
"vscode-extension-telemetry"
:
"0.1.1"
,
"vscode-nls"
:
"^4.0.0"
},
...
...
extensions/typescript-language-features/src/features/semanticTokens.ts
浏览文件 @
661bc5da
...
...
@@ -9,7 +9,10 @@ import * as Proto from '../protocol';
import
{
VersionDependentRegistration
}
from
'
../utils/dependentRegistration
'
;
import
API
from
'
../utils/api
'
;
const
minTypeScriptVersion
=
API
.
v370
;
// all constants are const
import
{
TokenType
,
TokenModifier
,
TokenEncodingConsts
,
VersionRequirement
}
from
'
typescript-vscode-sh-plugin/lib/constants
'
;
const
minTypeScriptVersion
=
API
.
fromVersionString
(
`
${
VersionRequirement
.
major
}
.
${
VersionRequirement
.
minor
}
`
);
export
function
register
(
selector
:
vscode
.
DocumentSelector
,
client
:
ITypeScriptServiceClient
)
{
return
new
VersionDependentRegistration
(
client
,
minTypeScriptVersion
,
()
=>
{
...
...
@@ -29,18 +32,16 @@ class SemanticTokensProvider implements vscode.SemanticTokensProvider {
}
getLegend
():
vscode
.
SemanticTokensLegend
{
const
tokenTypes
=
[];
for
(
let
i
=
0
;
i
<
VSCodeShPlugin
.
TokenType
.
_sentinel
;
i
++
)
{
tokenTypes
.
push
(
VSCodeShPlugin
.
TokenType
[
i
]);
if
(
tokenTypes
.
length
!==
TokenType
.
_
)
{
console
.
warn
(
'
typescript-vscode-sh-plugin has added new tokens types.
'
);
}
const
tokenModifiers
=
[];
for
(
let
i
=
0
;
i
<
VSCodeShPlugin
.
TokenModifier
.
_sentinel
;
i
++
)
{
tokenModifiers
.
push
(
VSCodeShPlugin
.
TokenModifier
[
i
]);
if
(
tokenModifiers
.
length
!==
TokenModifier
.
_
)
{
console
.
warn
(
'
typescript-vscode-sh-plugin has added new tokens modifiers.
'
);
}
return
new
vscode
.
SemanticTokensLegend
(
tokenTypes
,
tokenModifiers
);
}
async
provideSemanticTokens
(
document
:
vscode
.
TextDocument
,
_
options
:
vscode
.
SemanticTokensRequestOptions
,
token
:
vscode
.
CancellationToken
):
Promise
<
vscode
.
SemanticTokens
|
null
>
{
async
provideSemanticTokens
(
document
:
vscode
.
TextDocument
,
options
:
vscode
.
SemanticTokensRequestOptions
,
token
:
vscode
.
CancellationToken
):
Promise
<
vscode
.
SemanticTokens
|
null
>
{
const
file
=
this
.
client
.
toOpenedFilePath
(
document
);
if
(
!
file
)
{
return
null
;
...
...
@@ -51,8 +52,8 @@ class SemanticTokensProvider implements vscode.SemanticTokensProvider {
const
allTokenSpans
:
number
[][]
=
[];
let
requestArgs
:
ExperimentalProtocol
.
EncodedSemanticClassificationsRequestArgs
[]
=
[];
if
(
_
options
.
ranges
)
{
requestArgs
=
_
options
.
ranges
.
map
(
r
=>
{
const
start
=
document
.
offsetAt
(
r
.
start
);
const
length
=
document
.
offsetAt
(
r
.
end
)
-
start
;
return
{
file
,
start
,
length
};
});
if
(
options
.
ranges
)
{
requestArgs
=
options
.
ranges
.
map
(
r
=>
{
const
start
=
document
.
offsetAt
(
r
.
start
);
const
length
=
document
.
offsetAt
(
r
.
end
)
-
start
;
return
{
file
,
start
,
length
};
});
requestArgs
=
requestArgs
.
sort
((
a1
,
a2
)
=>
a1
.
start
-
a2
.
start
);
}
else
{
requestArgs
=
[{
file
,
start
:
0
,
length
:
document
.
getText
().
length
}];
// full document
...
...
@@ -81,10 +82,10 @@ class SemanticTokensProvider implements vscode.SemanticTokensProvider {
const
tsClassification
=
tokenSpan
[
i
++
];
let
tokenModifiers
=
0
;
let
tokenType
=
VSCodeShPlugin
.
getTokenTypeFromClassification
(
tsClassification
);
let
tokenType
=
getTokenTypeFromClassification
(
tsClassification
);
if
(
tokenType
!==
undefined
)
{
// it's a classification as returned by the typescript-vscode-sh-plugin
tokenModifiers
=
VSCodeShPlugin
.
getTokenModifierFromClassification
(
tsClassification
);
tokenModifiers
=
getTokenModifierFromClassification
(
tsClassification
);
}
else
{
// typescript-vscode-sh-plugin is not present
tokenType
=
tokenTypeMap
[
tsClassification
];
...
...
@@ -108,61 +109,48 @@ class SemanticTokensProvider implements vscode.SemanticTokensProvider {
}
}
namespace
VSCodeShPlugin
{
// typescript-vscode-sh-plugin encodes type and modifiers in the classification:
// TSClassification = (TokenType + 1) << 8 + TokenModifier
const
TokenTypeOffset
=
8
;
const
TokenModifierMask
=
(
1
<<
TokenTypeOffset
)
-
1
;
// 0xFF
export
function
getTokenTypeFromClassification
(
tsClassification
:
number
):
number
|
undefined
{
if
(
tsClassification
>
TokenModifierMask
)
{
return
(
tsClassification
>>
TokenTypeOffset
)
-
1
;
}
return
undefined
;
}
export
function
getTokenModifierFromClassification
(
tsClassification
:
number
)
{
return
tsClassification
&
TokenModifierMask
;
}
// typescript-vscode-sh-plugin encodes type and modifiers in the classification:
// TSClassification = (TokenType + 1) << 8 + TokenModifier
// Don't change TokenType and TokenModifier enums without adopting typescript-vscode-sh-plugin
export
enum
TokenType
{
'
class
'
,
'
enum
'
,
'
interface
'
,
'
namespace
'
,
'
typeParameter
'
,
'
type
'
,
'
parameter
'
,
'
variable
'
,
'
property
'
,
'
constant
'
,
'
function
'
,
'
member
'
,
_sentinel
function
getTokenTypeFromClassification
(
tsClassification
:
number
):
number
|
undefined
{
if
(
tsClassification
>
TokenEncodingConsts
.
modifierMask
)
{
return
(
tsClassification
>>
TokenEncodingConsts
.
typeOffset
)
-
1
;
}
return
undefined
;
}
export
enum
TokenModifier
{
'
declaration
'
,
'
static
'
,
'
async
'
,
'
readonly
'
,
_sentinel
}
function
getTokenModifierFromClassification
(
tsClassification
:
number
)
{
return
tsClassification
&
TokenEncodingConsts
.
modifierMask
;
}
// mapping for the original ExperimentalProtocol.ClassificationType from TypeScript (only used when plugin is not available)
const
tokenTypes
:
string
[]
=
[];
tokenTypes
[
TokenType
.
class
]
=
'
class
'
;
tokenTypes
[
TokenType
.
enum
]
=
'
enum
'
;
tokenTypes
[
TokenType
.
interface
]
=
'
interface
'
;
tokenTypes
[
TokenType
.
namespace
]
=
'
namespace
'
;
tokenTypes
[
TokenType
.
typeParameter
]
=
'
typeParameter
'
;
tokenTypes
[
TokenType
.
type
]
=
'
type
'
;
tokenTypes
[
TokenType
.
parameter
]
=
'
parameter
'
;
tokenTypes
[
TokenType
.
variable
]
=
'
variable
'
;
tokenTypes
[
TokenType
.
property
]
=
'
property
'
;
tokenTypes
[
TokenType
.
function
]
=
'
function
'
;
tokenTypes
[
TokenType
.
member
]
=
'
member
'
;
const
tokenModifiers
:
string
[]
=
[];
tokenModifiers
[
TokenModifier
.
async
]
=
'
async
'
;
tokenModifiers
[
TokenModifier
.
declaration
]
=
'
declaration
'
;
tokenModifiers
[
TokenModifier
.
readonly
]
=
'
readonly
'
;
tokenModifiers
[
TokenModifier
.
static
]
=
'
static
'
;
// mapping for the original ExperimentalProtocol.ClassificationType from TypeScript (only used when plugin is not available)
const
tokenTypeMap
:
number
[]
=
[];
tokenTypeMap
[
ExperimentalProtocol
.
ClassificationType
.
className
]
=
VSCodeShPlugin
.
TokenType
.
class
;
tokenTypeMap
[
ExperimentalProtocol
.
ClassificationType
.
enumName
]
=
VSCodeShPlugin
.
TokenType
.
enum
;
tokenTypeMap
[
ExperimentalProtocol
.
ClassificationType
.
interfaceName
]
=
VSCodeShPlugin
.
TokenType
.
interface
;
tokenTypeMap
[
ExperimentalProtocol
.
ClassificationType
.
moduleName
]
=
VSCodeShPlugin
.
TokenType
.
namespace
;
tokenTypeMap
[
ExperimentalProtocol
.
ClassificationType
.
typeParameterName
]
=
VSCodeShPlugin
.
TokenType
.
typeParameter
;
tokenTypeMap
[
ExperimentalProtocol
.
ClassificationType
.
typeAliasName
]
=
VSCodeShPlugin
.
TokenType
.
type
;
tokenTypeMap
[
ExperimentalProtocol
.
ClassificationType
.
parameterName
]
=
VSCodeShPlugin
.
TokenType
.
parameter
;
tokenTypeMap
[
ExperimentalProtocol
.
ClassificationType
.
className
]
=
TokenType
.
class
;
tokenTypeMap
[
ExperimentalProtocol
.
ClassificationType
.
enumName
]
=
TokenType
.
enum
;
tokenTypeMap
[
ExperimentalProtocol
.
ClassificationType
.
interfaceName
]
=
TokenType
.
interface
;
tokenTypeMap
[
ExperimentalProtocol
.
ClassificationType
.
moduleName
]
=
TokenType
.
namespace
;
tokenTypeMap
[
ExperimentalProtocol
.
ClassificationType
.
typeParameterName
]
=
TokenType
.
typeParameter
;
tokenTypeMap
[
ExperimentalProtocol
.
ClassificationType
.
typeAliasName
]
=
TokenType
.
type
;
tokenTypeMap
[
ExperimentalProtocol
.
ClassificationType
.
parameterName
]
=
TokenType
.
parameter
;
namespace
ExperimentalProtocol
{
...
...
extensions/typescript-language-features/src/utils/api.ts
浏览文件 @
661bc5da
...
...
@@ -31,7 +31,6 @@ export default class API {
public
static
readonly
v340
=
API
.
fromSimpleString
(
'
3.4.0
'
);
public
static
readonly
v345
=
API
.
fromSimpleString
(
'
3.4.5
'
);
public
static
readonly
v350
=
API
.
fromSimpleString
(
'
3.5.0
'
);
public
static
readonly
v370
=
API
.
fromSimpleString
(
'
3.7.0
'
);
public
static
readonly
v380
=
API
.
fromSimpleString
(
'
3.8.0
'
);
public
static
fromVersionString
(
versionString
:
string
):
API
{
...
...
extensions/typescript-language-features/yarn.lock
浏览文件 @
661bc5da
...
...
@@ -626,10 +626,10 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0:
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
integrity sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=
typescript-vscode-sh-plugin@^0.
3.2
:
version "0.
3.2
"
resolved "https://registry.yarnpkg.com/typescript-vscode-sh-plugin/-/typescript-vscode-sh-plugin-0.
3.2.tgz#bde9d0eba24ca5856024811fa354a9f5a7aeebe5
"
integrity sha512-
XsalETsSf3y7VWxk36plqHpsbl+TUDl278HEuhPHVBcNnwuTjcIq52J/CJw84xYmxmBcTIPUgIgLLS4OE5nX2A
==
typescript-vscode-sh-plugin@^0.
5.0
:
version "0.
5.0
"
resolved "https://registry.yarnpkg.com/typescript-vscode-sh-plugin/-/typescript-vscode-sh-plugin-0.
5.0.tgz#014dd928f2fa5000396147ed00792a2c901d97b9
"
integrity sha512-
MKqivbdkgllHS3Rab/zvXlGAxwCb1AHzgO/a8vmG6i5kExGIytwjUyXALdnnLUWS03B9eEJmIjzOz4y3MpgliQ
==
uri-js@^4.2.2:
version "4.2.2"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录