Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
3fefc611
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,发现更多精彩内容 >>
提交
3fefc611
编写于
8月 11, 2020
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ref count document data on extension host side
上级
98249fba
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
45 addition
and
38 deletion
+45
-38
src/vs/workbench/api/common/extHostDocuments.ts
src/vs/workbench/api/common/extHostDocuments.ts
+1
-1
src/vs/workbench/api/common/extHostDocumentsAndEditors.ts
src/vs/workbench/api/common/extHostDocumentsAndEditors.ts
+40
-23
src/vs/workbench/api/common/extHostNotebook.ts
src/vs/workbench/api/common/extHostNotebook.ts
+2
-12
src/vs/workbench/test/browser/api/extHostNotebook.test.ts
src/vs/workbench/test/browser/api/extHostNotebook.test.ts
+2
-2
未找到文件。
src/vs/workbench/api/common/extHostDocuments.ts
浏览文件 @
3fefc611
...
...
@@ -53,7 +53,7 @@ export class ExtHostDocuments implements ExtHostDocumentsShape {
}
public
getAllDocumentData
():
ExtHostDocumentData
[]
{
return
this
.
_documentsAndEditors
.
allDocuments
()
;
return
[...
this
.
_documentsAndEditors
.
allDocuments
()]
;
}
public
getDocumentData
(
resource
:
vscode
.
Uri
):
ExtHostDocumentData
|
undefined
{
...
...
src/vs/workbench/api/common/extHostDocumentsAndEditors.ts
浏览文件 @
3fefc611
...
...
@@ -16,6 +16,18 @@ import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters';
import
{
ILogService
}
from
'
vs/platform/log/common/log
'
;
import
{
ResourceMap
}
from
'
vs/base/common/map
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
Iterable
}
from
'
vs/base/common/iterator
'
;
class
Reference
<
T
>
{
private
_count
=
0
;
constructor
(
readonly
value
:
T
)
{
}
ref
()
{
this
.
_count
++
;
}
unref
()
{
return
--
this
.
_count
===
0
;
}
}
export
class
ExtHostDocumentsAndEditors
implements
ExtHostDocumentsAndEditorsShape
{
...
...
@@ -24,7 +36,7 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
private
_activeEditorId
:
string
|
null
=
null
;
private
readonly
_editors
=
new
Map
<
string
,
ExtHostTextEditor
>
();
private
readonly
_documents
=
new
ResourceMap
<
ExtHostDocumentData
>
();
private
readonly
_documents
=
new
ResourceMap
<
Reference
<
ExtHostDocumentData
>
>
();
private
readonly
_onDidAddDocuments
=
new
Emitter
<
ExtHostDocumentData
[]
>
();
private
readonly
_onDidRemoveDocuments
=
new
Emitter
<
ExtHostDocumentData
[]
>
();
...
...
@@ -51,9 +63,9 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
for
(
const
uriComponent
of
delta
.
removedDocuments
)
{
const
uri
=
URI
.
revive
(
uriComponent
);
const
data
=
this
.
_documents
.
get
(
uri
);
this
.
_documents
.
delete
(
uri
);
if
(
data
)
{
removedDocuments
.
push
(
data
);
if
(
data
?.
unref
())
{
this
.
_documents
.
delete
(
uri
);
removedDocuments
.
push
(
data
.
value
);
}
}
}
...
...
@@ -61,26 +73,31 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
if
(
delta
.
addedDocuments
)
{
for
(
const
data
of
delta
.
addedDocuments
)
{
const
resource
=
URI
.
revive
(
data
.
uri
);
const
existingDocumentData
=
this
.
_documents
.
get
(
resource
);
if
(
existingDocumentData
)
{
let
ref
=
this
.
_documents
.
get
(
resource
);
// double check -> only notebook cell documents should be
// referenced/opened more than once...
if
(
ref
)
{
if
(
resource
.
scheme
!==
Schemas
.
vscodeNotebookCell
)
{
throw
new
Error
(
`document '
${
resource
}
already exists!'`
);
}
existingDocumentData
.
onEvents
({
changes
:
[],
versionId
:
data
.
versionId
,
eol
:
data
.
EOL
});
continue
;
}
if
(
!
ref
)
{
ref
=
new
Reference
(
new
ExtHostDocumentData
(
this
.
_extHostRpc
.
getProxy
(
MainContext
.
MainThreadDocuments
),
resource
,
data
.
lines
,
data
.
EOL
,
data
.
modeId
,
data
.
versionId
,
data
.
isDirty
));
}
const
documentData
=
new
ExtHostDocumentData
(
this
.
_extHostRpc
.
getProxy
(
MainContext
.
MainThreadDocuments
),
resource
,
data
.
lines
,
data
.
EOL
,
data
.
modeId
,
data
.
versionId
,
data
.
isDirty
);
this
.
_documents
.
set
(
resource
,
documentData
);
addedDocuments
.
push
(
documentData
);
ref
.
ref
();
this
.
_documents
.
set
(
resource
,
ref
);
addedDocuments
.
push
(
ref
.
value
);
}
}
...
...
@@ -100,7 +117,7 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
assert
.
ok
(
this
.
_documents
.
has
(
resource
),
`document '
${
resource
}
' does not exist`
);
assert
.
ok
(
!
this
.
_editors
.
has
(
data
.
id
),
`editor '
${
data
.
id
}
' already exists!`
);
const
documentData
=
this
.
_documents
.
get
(
resource
)
!
;
const
documentData
=
this
.
_documents
.
get
(
resource
)
!
.
value
;
const
editor
=
new
ExtHostTextEditor
(
data
.
id
,
this
.
_extHostRpc
.
getProxy
(
MainContext
.
MainThreadTextEditors
),
...
...
@@ -140,11 +157,11 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
}
getDocument
(
uri
:
URI
):
ExtHostDocumentData
|
undefined
{
return
this
.
_documents
.
get
(
uri
);
return
this
.
_documents
.
get
(
uri
)
?.
value
;
}
allDocuments
():
ExtHostDocumentData
[]
{
return
[...
this
.
_documents
.
values
()]
;
allDocuments
():
Iterable
<
ExtHostDocumentData
>
{
return
Iterable
.
map
(
this
.
_documents
.
values
(),
ref
=>
ref
.
value
)
;
}
getEditor
(
id
:
string
):
ExtHostTextEditor
|
undefined
{
...
...
src/vs/workbench/api/common/extHostNotebook.ts
浏览文件 @
3fefc611
...
...
@@ -67,7 +67,7 @@ export class ExtHostCell extends Disposable implements vscode.NotebookCell {
modeId
:
cell
.
language
,
uri
:
cell
.
uri
,
isDirty
:
false
,
versionId
:
-
1
versionId
:
1
};
}
...
...
@@ -1523,19 +1523,9 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
const
document
=
this
.
_documents
.
get
(
revivedUriStr
);
if
(
document
)
{
// remove all documents that have not been opened by the renderer
// and have not yet been closed
const
removedCellDocuments
:
URI
[]
=
[];
for
(
let
cell
of
document
.
cells
)
{
if
(
this
.
_documentsAndEditors
.
getDocument
(
cell
.
uri
)?.
version
===
-
1
)
{
removedCellDocuments
.
push
(
cell
.
uri
);
}
}
document
.
dispose
();
this
.
_documents
.
delete
(
revivedUriStr
);
this
.
_documentsAndEditors
.
$acceptDocumentsAndEditorsDelta
({
removedDocuments
:
removedCellDocuments
});
this
.
_documentsAndEditors
.
$acceptDocumentsAndEditorsDelta
({
removedDocuments
:
document
.
cells
.
map
(
cell
=>
cell
.
uri
)
});
this
.
_onDidCloseNotebookDocument
.
fire
(
document
);
}
...
...
src/vs/workbench/test/browser/api/extHostNotebook.test.ts
浏览文件 @
3fefc611
...
...
@@ -96,12 +96,12 @@ suite('NotebookCell#Document', function () {
assert
.
ok
(
d1
);
assert
.
equal
(
d1
.
languageId
,
c1
.
language
);
assert
.
equal
(
d1
.
version
,
-
1
);
// we use -1 as signal that the document was created on the ext-host side
assert
.
equal
(
d1
.
version
,
1
);
const
d2
=
extHostDocuments
.
getDocument
(
c2
.
uri
);
assert
.
ok
(
d2
);
assert
.
equal
(
d2
.
languageId
,
c2
.
language
);
assert
.
equal
(
d2
.
version
,
-
1
);
assert
.
equal
(
d2
.
version
,
1
);
});
test
(
'
cell document goes when notebook closes
'
,
async
function
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录