Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
8f8634b7
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
8f8634b7
编写于
4月 30, 2021
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
💄
don't use object as map
上级
bc52e4d9
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
27 addition
and
46 deletion
+27
-46
src/vs/workbench/api/browser/mainThreadDocuments.ts
src/vs/workbench/api/browser/mainThreadDocuments.ts
+27
-46
未找到文件。
src/vs/workbench/api/browser/mainThreadDocuments.ts
浏览文件 @
8f8634b7
...
...
@@ -20,6 +20,7 @@ import { IWorkingCopyFileService } from 'vs/workbench/services/workingCopy/commo
import
{
IUriIdentityService
}
from
'
vs/workbench/services/uriIdentity/common/uriIdentity
'
;
import
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
IPathService
}
from
'
vs/workbench/services/path/common/pathService
'
;
import
{
ResourceMap
}
from
'
vs/base/common/map
'
;
export
class
BoundModelReferenceCollection
{
...
...
@@ -105,52 +106,39 @@ export class MainThreadDocuments extends Disposable implements MainThreadDocumen
private
_onIsCaughtUpWithContentChanges
=
this
.
_register
(
new
Emitter
<
URI
>
());
public
readonly
onIsCaughtUpWithContentChanges
=
this
.
_onIsCaughtUpWithContentChanges
.
event
;
private
readonly
_modelService
:
IModelService
;
private
readonly
_textModelResolverService
:
ITextModelService
;
private
readonly
_textFileService
:
ITextFileService
;
private
readonly
_fileService
:
IFileService
;
private
readonly
_environmentService
:
IWorkbenchEnvironmentService
;
private
readonly
_uriIdentityService
:
IUriIdentityService
;
private
_modelTrackers
:
{
[
modelUrl
:
string
]:
ModelTracker
;
};
private
readonly
_proxy
:
ExtHostDocumentsShape
;
private
readonly
_modelIsSynced
=
new
Set
<
string
>
();
private
readonly
_modelTrackers
=
new
ResourceMap
<
ModelTracker
>
();
private
readonly
_modelIsSynced
=
new
ResourceMap
<
void
>
();
private
readonly
_modelReferenceCollection
:
BoundModelReferenceCollection
;
constructor
(
documentsAndEditors
:
MainThreadDocumentsAndEditors
,
extHostContext
:
IExtHostContext
,
@
IModelService
modelService
:
IModelService
,
@
ITextFileService
textFileService
:
ITextFileService
,
@
IFileService
fileService
:
IFileService
,
@
ITextModelService
textModelResolverService
:
ITextModelService
,
@
IWorkbenchEnvironmentService
environmentService
:
IWorkbenchEnvironmentService
,
@
IUriIdentityService
uriIdentityService
:
IUriIdentityService
,
@
IModelService
private
readonly
_
modelService
:
IModelService
,
@
ITextFileService
private
readonly
_
textFileService
:
ITextFileService
,
@
IFileService
private
readonly
_
fileService
:
IFileService
,
@
ITextModelService
private
readonly
_
textModelResolverService
:
ITextModelService
,
@
IWorkbenchEnvironmentService
private
readonly
_
environmentService
:
IWorkbenchEnvironmentService
,
@
IUriIdentityService
private
readonly
_
uriIdentityService
:
IUriIdentityService
,
@
IWorkingCopyFileService
workingCopyFileService
:
IWorkingCopyFileService
,
@
IPathService
private
readonly
_pathService
:
IPathService
)
{
super
();
this
.
_modelService
=
modelService
;
this
.
_textModelResolverService
=
textModelResolverService
;
this
.
_textFileService
=
textFileService
;
this
.
_fileService
=
fileService
;
this
.
_environmentService
=
environmentService
;
this
.
_uriIdentityService
=
uriIdentityService
;
this
.
_modelReferenceCollection
=
this
.
_register
(
new
BoundModelReferenceCollection
(
uriIdentityService
.
extUri
));
this
.
_modelReferenceCollection
=
this
.
_register
(
new
BoundModelReferenceCollection
(
_
uriIdentityService
.
extUri
));
this
.
_proxy
=
extHostContext
.
getProxy
(
ExtHostContext
.
ExtHostDocuments
);
this
.
_register
(
documentsAndEditors
.
onDocumentAdd
(
models
=>
models
.
forEach
(
this
.
_onModelAdded
,
this
)));
this
.
_register
(
documentsAndEditors
.
onDocumentRemove
(
urls
=>
urls
.
forEach
(
this
.
_onModelRemoved
,
this
)));
this
.
_register
(
modelService
.
onModelModeChanged
(
this
.
_onModelModeChanged
,
this
));
this
.
_register
(
_
modelService
.
onModelModeChanged
(
this
.
_onModelModeChanged
,
this
));
this
.
_register
(
textFileService
.
files
.
onDidSave
(
e
=>
{
this
.
_register
(
_
textFileService
.
files
.
onDidSave
(
e
=>
{
if
(
this
.
_shouldHandleFileEvent
(
e
.
model
.
resource
))
{
this
.
_proxy
.
$acceptModelSaved
(
e
.
model
.
resource
);
}
}));
this
.
_register
(
textFileService
.
files
.
onDidChangeDirty
(
m
=>
{
this
.
_register
(
_
textFileService
.
files
.
onDidChangeDirty
(
m
=>
{
if
(
this
.
_shouldHandleFileEvent
(
m
.
resource
))
{
this
.
_proxy
.
$acceptDirtyStateChanged
(
m
.
resource
,
m
.
isDirty
());
}
...
...
@@ -167,22 +155,18 @@ export class MainThreadDocuments extends Disposable implements MainThreadDocumen
}
}
}));
this
.
_modelTrackers
=
Object
.
create
(
null
);
}
public
override
dispose
():
void
{
Object
.
keys
(
this
.
_modelTrackers
).
forEach
((
modelUrl
)
=>
{
this
.
_modelTrackers
[
modelUrl
].
dispose
();
});
this
.
_modelTrackers
=
Object
.
create
(
null
);
dispose
(
this
.
_modelTrackers
.
values
());
this
.
_modelTrackers
.
clear
();
super
.
dispose
();
}
public
isCaughtUpWithContentChanges
(
resource
:
URI
):
boolean
{
const
modelUrl
=
resource
.
toString
(
);
if
(
t
his
.
_modelTrackers
[
modelUrl
]
)
{
return
t
his
.
_modelTrackers
[
modelUrl
]
.
isCaughtUpWithContentChanges
();
const
tracker
=
this
.
_modelTrackers
.
get
(
resource
);
if
(
t
racker
)
{
return
t
racker
.
isCaughtUpWithContentChanges
();
}
return
true
;
}
...
...
@@ -198,28 +182,25 @@ export class MainThreadDocuments extends Disposable implements MainThreadDocumen
// don't synchronize too large models
return
;
}
const
modelUrl
=
model
.
uri
;
this
.
_modelIsSynced
.
add
(
modelUrl
.
toString
());
this
.
_modelTrackers
[
modelUrl
.
toString
()]
=
new
ModelTracker
(
model
,
this
.
_onIsCaughtUpWithContentChanges
,
this
.
_proxy
,
this
.
_textFileService
);
this
.
_modelIsSynced
.
set
(
model
.
uri
,
undefined
);
this
.
_modelTrackers
.
set
(
model
.
uri
,
new
ModelTracker
(
model
,
this
.
_onIsCaughtUpWithContentChanges
,
this
.
_proxy
,
this
.
_textFileService
));
}
private
_onModelModeChanged
(
event
:
{
model
:
ITextModel
;
oldModeId
:
string
;
}):
void
{
let
{
model
}
=
event
;
const
modelUrl
=
model
.
uri
;
if
(
!
this
.
_modelIsSynced
.
has
(
modelUrl
.
toString
()))
{
if
(
!
this
.
_modelIsSynced
.
has
(
model
.
uri
))
{
return
;
}
this
.
_proxy
.
$acceptModelModeChanged
(
model
.
uri
,
model
.
getLanguageIdentifier
().
language
);
}
private
_onModelRemoved
(
modelUrl
:
URI
):
void
{
const
strModelUrl
=
modelUrl
.
toString
();
if
(
!
this
.
_modelIsSynced
.
has
(
strModelUrl
))
{
if
(
!
this
.
_modelIsSynced
.
has
(
modelUrl
))
{
return
;
}
this
.
_modelIsSynced
.
delete
(
strM
odelUrl
);
this
.
_modelTrackers
[
strModelUrl
]
.
dispose
();
delete
this
.
_modelTrackers
[
strModelUrl
]
;
this
.
_modelIsSynced
.
delete
(
m
odelUrl
);
this
.
_modelTrackers
.
get
(
modelUrl
)
!
.
dispose
();
this
.
_modelTrackers
.
delete
(
modelUrl
)
;
}
// --- from extension host process
...
...
@@ -252,7 +233,7 @@ export class MainThreadDocuments extends Disposable implements MainThreadDocumen
return
Promise
.
reject
(
new
Error
(
`cannot open
${
canonicalUri
.
toString
()}
`
));
}
else
if
(
!
extUri
.
isEqual
(
documentUri
,
canonicalUri
))
{
return
Promise
.
reject
(
new
Error
(
`cannot open
${
canonicalUri
.
toString
()}
. Detail: Actual document opened as
${
documentUri
.
toString
()}
`
));
}
else
if
(
!
this
.
_modelIsSynced
.
has
(
canonicalUri
.
toString
()
))
{
}
else
if
(
!
this
.
_modelIsSynced
.
has
(
canonicalUri
))
{
return
Promise
.
reject
(
new
Error
(
`cannot open
${
canonicalUri
.
toString
()}
. Detail: Files above 50MB cannot be synchronized with extensions.`
));
}
else
{
return
canonicalUri
;
...
...
@@ -291,7 +272,7 @@ export class MainThreadDocuments extends Disposable implements MainThreadDocumen
}).
then
(
model
=>
{
const
resource
=
model
.
resource
;
if
(
!
this
.
_modelIsSynced
.
has
(
resource
.
toString
()
))
{
if
(
!
this
.
_modelIsSynced
.
has
(
resource
))
{
throw
new
Error
(
`expected URI
${
resource
.
toString
()}
to have come to LIFE`
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录