Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
a73ca964
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,发现更多精彩内容 >>
提交
a73ca964
编写于
1月 15, 2019
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adopt more async/await
上级
924b7a1f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
46 addition
and
44 deletion
+46
-44
src/vs/workbench/services/textMate/electron-browser/TMSyntax.ts
.../workbench/services/textMate/electron-browser/TMSyntax.ts
+46
-44
未找到文件。
src/vs/workbench/services/textMate/electron-browser/TMSyntax.ts
浏览文件 @
a73ca964
...
...
@@ -229,39 +229,42 @@ export class TextMateService extends Disposable implements ITextMateService {
}
}
private
async
_createGrammarRegistry
():
Promise
<
[
Registry
,
StackElement
]
>
{
const
{
Registry
,
INITIAL
,
parseRawGrammar
}
=
await
import
(
'
vscode-textmate
'
);
const
grammarRegistry
=
new
Registry
({
loadGrammar
:
async
(
scopeName
:
string
)
=>
{
const
location
=
this
.
_scopeRegistry
.
getGrammarLocation
(
scopeName
);
if
(
!
location
)
{
this
.
_logService
.
trace
(
`No grammar found for scope
${
scopeName
}
`
);
return
null
;
}
try
{
const
content
=
await
this
.
_fileService
.
resolveContent
(
location
,
{
encoding
:
'
utf8
'
});
return
parseRawGrammar
(
content
.
value
,
location
.
path
);
}
catch
(
e
)
{
this
.
_logService
.
error
(
`Unable to load and parse grammar for scope
${
scopeName
}
from
${
location
}
`
,
e
);
return
null
;
}
},
getInjections
:
(
scopeName
:
string
)
=>
{
const
scopeParts
=
scopeName
.
split
(
'
.
'
);
let
injections
:
string
[]
=
[];
for
(
let
i
=
1
;
i
<=
scopeParts
.
length
;
i
++
)
{
const
subScopeName
=
scopeParts
.
slice
(
0
,
i
).
join
(
'
.
'
);
injections
=
[...
injections
,
...
this
.
_injections
[
subScopeName
]];
}
return
injections
;
}
});
this
.
_updateTheme
(
grammarRegistry
);
this
.
_themeService
.
onDidColorThemeChange
((
e
)
=>
this
.
_updateTheme
(
grammarRegistry
));
return
<
[
Registry
,
StackElement
]
>
[
grammarRegistry
,
INITIAL
];
}
private
_getOrCreateGrammarRegistry
():
Promise
<
[
Registry
,
StackElement
]
>
{
if
(
!
this
.
_grammarRegistry
)
{
this
.
_grammarRegistry
=
import
(
'
vscode-textmate
'
).
then
(({
Registry
,
INITIAL
,
parseRawGrammar
})
=>
{
const
grammarRegistry
=
new
Registry
({
loadGrammar
:
(
scopeName
:
string
)
=>
{
const
location
=
this
.
_scopeRegistry
.
getGrammarLocation
(
scopeName
);
if
(
!
location
)
{
this
.
_logService
.
trace
(
`No grammar found for scope
${
scopeName
}
`
);
return
null
;
}
return
this
.
_fileService
.
resolveContent
(
location
,
{
encoding
:
'
utf8
'
}).
then
(
content
=>
{
return
parseRawGrammar
(
content
.
value
,
location
.
path
);
},
e
=>
{
this
.
_logService
.
error
(
`Unable to load and parse grammar for scope
${
scopeName
}
from
${
location
}
`
,
e
);
return
null
;
});
},
getInjections
:
(
scopeName
:
string
)
=>
{
const
scopeParts
=
scopeName
.
split
(
'
.
'
);
let
injections
:
string
[]
=
[];
for
(
let
i
=
1
;
i
<=
scopeParts
.
length
;
i
++
)
{
const
subScopeName
=
scopeParts
.
slice
(
0
,
i
).
join
(
'
.
'
);
injections
=
[...
injections
,
...
this
.
_injections
[
subScopeName
]];
}
return
injections
;
}
});
this
.
_updateTheme
(
grammarRegistry
);
this
.
_themeService
.
onDidColorThemeChange
((
e
)
=>
this
.
_updateTheme
(
grammarRegistry
));
return
<
[
Registry
,
StackElement
]
>
[
grammarRegistry
,
INITIAL
];
});
this
.
_grammarRegistry
=
this
.
_createGrammarRegistry
();
}
return
this
.
_grammarRegistry
;
}
...
...
@@ -384,11 +387,12 @@ export class TextMateService extends Disposable implements ITextMateService {
return
result
;
}
public
createGrammar
(
modeId
:
string
):
Promise
<
IGrammar
>
{
return
this
.
_createGrammar
(
modeId
).
then
(
r
=>
r
.
grammar
);
public
async
createGrammar
(
modeId
:
string
):
Promise
<
IGrammar
>
{
const
{
grammar
}
=
await
this
.
_createGrammar
(
modeId
);
return
grammar
;
}
private
_createGrammar
(
modeId
:
string
):
Promise
<
ICreateGrammarResult
>
{
private
async
_createGrammar
(
modeId
:
string
):
Promise
<
ICreateGrammarResult
>
{
const
scopeName
=
this
.
_languageToScope
.
get
(
modeId
);
if
(
typeof
scopeName
!==
'
string
'
)
{
// No TM grammar defined
...
...
@@ -412,17 +416,15 @@ export class TextMateService extends Disposable implements ITextMateService {
let
languageId
=
this
.
_modeService
.
getLanguageIdentifier
(
modeId
)
!
.
id
;
let
containsEmbeddedLanguages
=
(
Object
.
keys
(
embeddedLanguages
).
length
>
0
);
return
this
.
_getOrCreateGrammarRegistry
().
then
((
_res
)
=>
{
const
[
grammarRegistry
,
initialState
]
=
_res
;
return
grammarRegistry
.
loadGrammarWithConfiguration
(
scopeName
,
languageId
,
{
embeddedLanguages
,
tokenTypes
:
languageRegistration
.
tokenTypes
}).
then
(
grammar
=>
{
return
{
languageId
:
languageId
,
grammar
:
grammar
,
initialState
:
initialState
,
containsEmbeddedLanguages
:
containsEmbeddedLanguages
};
});
});
const
[
grammarRegistry
,
initialState
]
=
await
this
.
_getOrCreateGrammarRegistry
();
const
grammar
=
await
grammarRegistry
.
loadGrammarWithConfiguration
(
scopeName
,
languageId
,
{
embeddedLanguages
,
tokenTypes
:
languageRegistration
.
tokenTypes
});
return
{
languageId
:
languageId
,
grammar
:
grammar
,
initialState
:
initialState
,
containsEmbeddedLanguages
:
containsEmbeddedLanguages
};
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录