Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
8c6c0232
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,发现更多精彩内容 >>
未验证
提交
8c6c0232
编写于
11月 22, 2019
作者:
A
Alexandru Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce a cache object for styling per semantic coloring provider
上级
1c98b5ec
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
61 addition
and
21 deletion
+61
-21
src/vs/editor/common/services/modelServiceImpl.ts
src/vs/editor/common/services/modelServiceImpl.ts
+61
-21
未找到文件。
src/vs/editor/common/services/modelServiceImpl.ts
浏览文件 @
8c6c0232
...
...
@@ -441,12 +441,14 @@ export interface ILineSequence {
class
SemanticColoringFeature
extends
Disposable
{
private
_watchers
:
Record
<
string
,
ModelSemanticColoring
>
;
private
_semanticStyling
:
SemanticStyling
;
constructor
(
modelService
:
IModelService
,
themeService
:
IThemeService
)
{
super
();
this
.
_watchers
=
Object
.
create
(
null
);
this
.
_semanticStyling
=
new
SemanticStyling
(
themeService
);
this
.
_register
(
modelService
.
onModelAdded
((
model
)
=>
{
this
.
_watchers
[
model
.
uri
.
toString
()]
=
new
ModelSemanticColoring
(
model
,
themeService
);
this
.
_watchers
[
model
.
uri
.
toString
()]
=
new
ModelSemanticColoring
(
model
,
themeService
,
this
.
_semanticStyling
);
}));
this
.
_register
(
modelService
.
onModelRemoved
((
model
)
=>
{
this
.
_watchers
[
model
.
uri
.
toString
()].
dispose
();
...
...
@@ -455,24 +457,72 @@ class SemanticColoringFeature extends Disposable {
}
}
class
SemanticStyling
{
private
readonly
_caches
:
WeakMap
<
SemanticColoringProvider
,
SemanticColoringProviderStyling
>
;
constructor
(
private
readonly
_themeService
:
IThemeService
)
{
this
.
_caches
=
new
WeakMap
<
SemanticColoringProvider
,
SemanticColoringProviderStyling
>
();
}
public
get
(
provider
:
SemanticColoringProvider
):
SemanticColoringProviderStyling
{
if
(
!
this
.
_caches
.
has
(
provider
))
{
this
.
_caches
.
set
(
provider
,
new
SemanticColoringProviderStyling
(
provider
.
getLegend
(),
this
.
_themeService
));
}
return
this
.
_caches
.
get
(
provider
)
!
;
}
}
const
enum
Constants
{
NO_STYLING
=
0b01111111111111111111111111111111
}
class
SemanticColoringProviderStyling
{
constructor
(
private
readonly
_legend
:
SemanticColoringLegend
,
private
readonly
_themeService
:
IThemeService
)
{
}
public
getMetadata
(
tokenTypeIndex
:
number
,
tokenModifierSet
:
number
):
number
{
const
tokenType
=
this
.
_legend
.
tokenTypes
[
tokenTypeIndex
];
const
tokenModifiers
:
string
[]
=
[];
for
(
let
modifierIndex
=
0
;
tokenModifierSet
!==
0
&&
modifierIndex
<
this
.
_legend
.
tokenModifiers
.
length
;
modifierIndex
++
)
{
if
(
tokenModifierSet
&
1
)
{
tokenModifiers
.
push
(
this
.
_legend
.
tokenModifiers
[
modifierIndex
]);
}
tokenModifierSet
=
tokenModifierSet
>>
1
;
}
const
metadata
=
this
.
_themeService
.
getTheme
().
getTokenStyleMetadata
(
tokenType
,
tokenModifiers
);
if
(
typeof
metadata
===
'
undefined
'
)
{
return
Constants
.
NO_STYLING
;
}
return
metadata
;
}
}
class
ModelSemanticColoring
extends
Disposable
{
private
_isDisposed
:
boolean
;
private
readonly
_model
:
ITextModel
;
private
readonly
_semanticStyling
:
SemanticStyling
;
private
readonly
_fetchSemanticTokens
:
RunOnceScheduler
;
private
_currentResponse
:
SemanticColoring
|
null
;
private
_currentRequestCancellationTokenSource
:
CancellationTokenSource
|
null
;
private
_themeService
:
IThemeService
;
constructor
(
model
:
ITextModel
,
themeService
:
IThemeService
)
{
constructor
(
model
:
ITextModel
,
themeService
:
IThemeService
,
stylingProvider
:
SemanticStyling
)
{
super
();
this
.
_isDisposed
=
false
;
this
.
_model
=
model
;
this
.
_semanticStyling
=
stylingProvider
;
this
.
_fetchSemanticTokens
=
this
.
_register
(
new
RunOnceScheduler
(()
=>
this
.
_fetchSemanticTokensNow
(),
500
));
this
.
_currentResponse
=
null
;
this
.
_currentRequestCancellationTokenSource
=
null
;
this
.
_themeService
=
themeService
;
this
.
_register
(
this
.
_model
.
onDidChangeContent
(
e
=>
this
.
_fetchSemanticTokens
.
schedule
()));
this
.
_register
(
SemanticColoringProviderRegistry
.
onDidChange
(
e
=>
this
.
_fetchSemanticTokens
.
schedule
()));
...
...
@@ -509,22 +559,22 @@ class ModelSemanticColoring extends Disposable {
pendingChanges
.
push
(
e
);
});
const
legend
=
provider
.
getLegend
(
);
const
styling
=
this
.
_semanticStyling
.
get
(
provider
);
const
request
=
Promise
.
resolve
(
provider
.
provideSemanticColoring
(
this
.
_model
,
this
.
_currentRequestCancellationTokenSource
.
token
));
request
.
then
((
res
)
=>
{
this
.
_currentRequestCancellationTokenSource
=
null
;
contentChangeListener
.
dispose
();
this
.
_setSemanticTokens
(
res
||
null
,
legend
,
pendingChanges
);
this
.
_setSemanticTokens
(
res
||
null
,
styling
,
pendingChanges
);
},
(
err
)
=>
{
errors
.
onUnexpectedError
(
err
);
this
.
_currentRequestCancellationTokenSource
=
null
;
contentChangeListener
.
dispose
();
this
.
_setSemanticTokens
(
null
,
legend
,
pendingChanges
);
this
.
_setSemanticTokens
(
null
,
styling
,
pendingChanges
);
});
}
private
_setSemanticTokens
(
tokens
:
SemanticColoring
|
null
,
legend
:
SemanticColoringLegend
,
pendingChanges
:
IModelContentChangedEvent
[]):
void
{
private
_setSemanticTokens
(
tokens
:
SemanticColoring
|
null
,
styling
:
SemanticColoringProviderStyling
,
pendingChanges
:
IModelContentChangedEvent
[]):
void
{
if
(
this
.
_currentResponse
)
{
this
.
_currentResponse
.
dispose
();
this
.
_currentResponse
=
null
;
...
...
@@ -554,19 +604,9 @@ class ModelSemanticColoring extends Disposable {
const
startCharacter
=
srcTokens
[
srcOffset
+
1
];
const
endCharacter
=
srcTokens
[
srcOffset
+
2
];
const
tokenTypeIndex
=
srcTokens
[
srcOffset
+
3
];
const
tokenType
=
legend
.
tokenTypes
[
tokenTypeIndex
];
let
tokenModifierSet
=
srcTokens
[
srcOffset
+
4
];
let
tokenModifiers
:
string
[]
=
[];
for
(
let
modifierIndex
=
0
;
tokenModifierSet
!==
0
&&
modifierIndex
<
legend
.
tokenModifiers
.
length
;
modifierIndex
++
)
{
if
(
tokenModifierSet
&
1
)
{
tokenModifiers
.
push
(
legend
.
tokenModifiers
[
modifierIndex
]);
}
tokenModifierSet
=
tokenModifierSet
>>
1
;
}
const
metadata
=
this
.
_themeService
.
getTheme
().
getTokenStyleMetadata
(
tokenType
,
tokenModifiers
);
if
(
metadata
!==
undefined
)
{
const
tokenModifierSet
=
srcTokens
[
srcOffset
+
4
];
const
metadata
=
styling
.
getMetadata
(
tokenTypeIndex
,
tokenModifierSet
);
if
(
metadata
!==
Constants
.
NO_STYLING
)
{
destTokens
[
destOffset
]
=
deltaLine
;
destTokens
[
destOffset
+
1
]
=
startCharacter
;
destTokens
[
destOffset
+
2
]
=
endCharacter
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录