Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d6aa8f54
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,发现更多精彩内容 >>
提交
d6aa8f54
编写于
12月 12, 2019
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixes
上级
03e79666
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
18 deletion
+17
-18
extensions/html-language-features/server/src/modes/javascriptMode.ts
...html-language-features/server/src/modes/javascriptMode.ts
+17
-18
未找到文件。
extensions/html-language-features/server/src/modes/javascriptMode.ts
浏览文件 @
d6aa8f54
...
...
@@ -17,6 +17,7 @@ import * as ts from 'typescript';
import
{
join
}
from
'
path
'
;
const
FILE_NAME
=
'
vscode://javascript/1
'
;
// the same 'file' is used for all contents
const
TS_FILE_NAME
=
'
vscode://javascript/2.ts
'
;
const
JS_WORD_REGEX
=
/
(
-
?\d
*
\.\d\w
*
)
|
([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]
+
)
/g
;
let
jquery_d_ts
=
join
(
__dirname
,
'
../lib/jquery.d.ts
'
);
// when packaged
...
...
@@ -29,21 +30,19 @@ export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocume
let
compilerOptions
:
ts
.
CompilerOptions
=
{
allowNonTsExtensions
:
true
,
allowJs
:
true
,
lib
:
[
'
lib.es6.d.ts
'
],
target
:
ts
.
ScriptTarget
.
Latest
,
moduleResolution
:
ts
.
ModuleResolutionKind
.
Classic
};
let
currentTextDocument
:
TextDocument
;
let
currentScriptKind
:
ts
.
ScriptKind
;
let
scriptFileVersion
:
number
=
0
;
function
updateCurrentTextDocument
(
doc
:
TextDocument
,
scriptKind
=
ts
.
ScriptKind
.
JS
)
{
function
updateCurrentTextDocument
(
doc
:
TextDocument
)
{
if
(
!
currentTextDocument
||
doc
.
uri
!==
currentTextDocument
.
uri
||
doc
.
version
!==
currentTextDocument
.
version
)
{
currentTextDocument
=
jsDocuments
.
get
(
doc
);
scriptFileVersion
++
;
}
currentScriptKind
=
scriptKind
;
}
const
host
:
ts
.
LanguageServiceHost
=
{
getCompilationSettings
:
()
=>
compilerOptions
,
getScriptFileNames
:
()
=>
[
FILE_NAME
,
jquery_d_ts
],
getScriptKind
:
(
fileName
)
=>
fileName
===
FILE_NAME
?
currentScriptKind
:
ts
.
ScriptKind
.
JS
,
getScriptFileNames
:
()
=>
[
FILE_NAME
,
TS_FILE_NAME
,
jquery_d_ts
],
getScriptKind
:
(
fileName
)
=>
fileName
===
TS_FILE_NAME
?
ts
.
ScriptKind
.
TS
:
ts
.
ScriptKind
.
JS
,
getScriptVersion
:
(
fileName
:
string
)
=>
{
if
(
fileName
===
FILE_NAME
)
{
if
(
fileName
===
FILE_NAME
||
fileName
===
TS_FILE_NAME
)
{
return
String
(
scriptFileVersion
);
}
return
'
1
'
;
// default lib an jquery.d.ts are static
...
...
@@ -51,7 +50,7 @@ export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocume
getScriptSnapshot
:
(
fileName
:
string
)
=>
{
let
text
=
''
;
if
(
startsWith
(
fileName
,
'
vscode:
'
))
{
if
(
fileName
===
FILE_NAME
)
{
if
(
fileName
===
FILE_NAME
||
fileName
===
TS_FILE_NAME
)
{
text
=
currentTextDocument
.
getText
();
}
}
else
{
...
...
@@ -317,7 +316,7 @@ export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocume
jsDocuments
.
onDocumentRemoved
(
document
);
},
getSemanticTokens
(
document
:
TextDocument
,
ranges
:
Range
[]
|
undefined
):
number
[]
{
updateCurrentTextDocument
(
document
,
ts
.
ScriptKind
.
TS
);
updateCurrentTextDocument
(
document
);
if
(
!
ranges
)
{
ranges
=
[
Range
.
create
(
Position
.
create
(
0
,
0
),
document
.
positionAt
(
document
.
getText
().
length
))];
}
...
...
@@ -325,7 +324,7 @@ export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocume
for
(
let
range
of
ranges
)
{
const
start
=
document
.
offsetAt
(
range
.
start
),
length
=
document
.
offsetAt
(
range
.
end
)
-
start
;
const
tokens
=
jsLanguageService
.
getSemanticClassifications
(
FILE_NAME
,
{
start
,
length
});
const
tokens
=
jsLanguageService
.
getSemanticClassifications
(
TS_
FILE_NAME
,
{
start
,
length
});
let
prefLine
=
0
;
let
prevChar
=
0
;
...
...
@@ -333,7 +332,7 @@ export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocume
for
(
let
token
of
tokens
)
{
const
m
=
tokenMapping
[
token
.
classificationType
];
if
(
m
)
{
const
startPos
=
d
ocument
.
positionAt
(
token
.
textSpan
.
start
);
const
startPos
=
currentTextD
ocument
.
positionAt
(
token
.
textSpan
.
start
);
if
(
prefLine
!==
startPos
.
line
)
{
prevChar
=
0
;
}
...
...
@@ -361,16 +360,16 @@ export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocume
};
}
const
tokenTypes
:
string
[]
=
[
'
class
es
'
,
'
enums
'
,
'
interfaces
'
,
'
namespaces
'
,
'
parameterTypes
'
,
'
types
'
,
'
parameters
'
];
const
tokenTypes
:
string
[]
=
[
'
class
'
,
'
enum
'
,
'
interface
'
,
'
namespace
'
,
'
parameterType
'
,
'
type
'
,
'
parameter
'
];
const
tokenModifiers
:
string
[]
=
[];
const
tokenMapping
:
{
[
name
:
string
]:
string
}
=
{
[
ts
.
ClassificationTypeNames
.
className
]:
'
class
es
'
,
[
ts
.
ClassificationTypeNames
.
enumName
]:
'
enum
s
'
,
[
ts
.
ClassificationTypeNames
.
interfaceName
]:
'
interface
s
'
,
[
ts
.
ClassificationTypeNames
.
moduleName
]:
'
namespace
s
'
,
[
ts
.
ClassificationTypeNames
.
typeParameterName
]:
'
parameterType
s
'
,
[
ts
.
ClassificationTypeNames
.
typeAliasName
]:
'
type
s
'
,
[
ts
.
ClassificationTypeNames
.
parameterName
]:
'
parameter
s
'
[
ts
.
ClassificationTypeNames
.
className
]:
'
class
'
,
[
ts
.
ClassificationTypeNames
.
enumName
]:
'
enum
'
,
[
ts
.
ClassificationTypeNames
.
interfaceName
]:
'
interface
'
,
[
ts
.
ClassificationTypeNames
.
moduleName
]:
'
namespace
'
,
[
ts
.
ClassificationTypeNames
.
typeParameterName
]:
'
parameterType
'
,
[
ts
.
ClassificationTypeNames
.
typeAliasName
]:
'
type
'
,
[
ts
.
ClassificationTypeNames
.
parameterName
]:
'
parameter
'
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录