Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
1b521798
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,发现更多精彩内容 >>
提交
1b521798
编写于
5月 05, 2020
作者:
R
rebornix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
notebook document creation in UI side
上级
0838431d
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
442 addition
and
93 deletion
+442
-93
extensions/vscode-notebook-tests/src/notebookTestMain.ts
extensions/vscode-notebook-tests/src/notebookTestMain.ts
+21
-8
src/vs/workbench/api/browser/mainThreadNotebook.ts
src/vs/workbench/api/browser/mainThreadNotebook.ts
+74
-26
src/vs/workbench/api/common/extHost.protocol.ts
src/vs/workbench/api/common/extHost.protocol.ts
+21
-6
src/vs/workbench/api/common/extHostNotebook.ts
src/vs/workbench/api/common/extHostNotebook.ts
+157
-38
src/vs/workbench/contrib/notebook/browser/notebookEditorInput.ts
...workbench/contrib/notebook/browser/notebookEditorInput.ts
+4
-0
src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts
...workbench/contrib/notebook/browser/notebookServiceImpl.ts
+41
-4
src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts
...kbench/contrib/notebook/common/model/notebookTextModel.ts
+48
-0
src/vs/workbench/contrib/notebook/common/notebookCommon.ts
src/vs/workbench/contrib/notebook/common/notebookCommon.ts
+8
-1
src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts
.../workbench/contrib/notebook/common/notebookEditorModel.ts
+59
-4
src/vs/workbench/contrib/notebook/common/notebookService.ts
src/vs/workbench/contrib/notebook/common/notebookService.ts
+6
-3
src/vs/workbench/test/browser/api/extHostNotebookConcatDocument.test.ts
...ch/test/browser/api/extHostNotebookConcatDocument.test.ts
+3
-3
未找到文件。
extensions/vscode-notebook-tests/src/notebookTestMain.ts
浏览文件 @
1b521798
...
@@ -6,12 +6,22 @@
...
@@ -6,12 +6,22 @@
import
*
as
vscode
from
'
vscode
'
;
import
*
as
vscode
from
'
vscode
'
;
export
function
activate
(
context
:
vscode
.
ExtensionContext
):
any
{
export
function
activate
(
context
:
vscode
.
ExtensionContext
):
any
{
context
.
subscriptions
.
push
(
vscode
.
notebook
.
registerNotebookProvider
(
'
notebookCoreTest
'
,
{
context
.
subscriptions
.
push
(
vscode
.
notebook
.
registerNotebookContentProvider
(
'
notebookCoreTest
'
,
{
resolveNotebook
:
async
(
editor
:
vscode
.
NotebookEditor
)
=>
{
onDidChangeNotebook
:
new
vscode
.
EventEmitter
<
void
>
().
event
,
await
editor
.
edit
(
eb
=>
{
openNotebook
:
async
(
_resource
:
vscode
.
Uri
)
=>
{
eb
.
insert
(
0
,
'
test
'
,
'
typescript
'
,
vscode
.
CellKind
.
Code
,
[],
{});
return
{
});
languages
:
[
'
typescript
'
],
return
;
metadata
:
{},
cells
:
[
{
source
:
'
test
'
,
language
:
'
typescript
'
,
cellKind
:
vscode
.
CellKind
.
Code
,
outputs
:
[],
metadata
:
{}
}
]
};
},
},
executeCell
:
async
(
_document
:
vscode
.
NotebookDocument
,
_cell
:
vscode
.
NotebookCell
|
undefined
,
_token
:
vscode
.
CancellationToken
)
=>
{
executeCell
:
async
(
_document
:
vscode
.
NotebookDocument
,
_cell
:
vscode
.
NotebookCell
|
undefined
,
_token
:
vscode
.
CancellationToken
)
=>
{
if
(
!
_cell
)
{
if
(
!
_cell
)
{
...
@@ -26,8 +36,11 @@ export function activate(context: vscode.ExtensionContext): any {
...
@@ -26,8 +36,11 @@ export function activate(context: vscode.ExtensionContext): any {
}];
}];
return
;
return
;
},
},
save
:
async
(
_document
:
vscode
.
NotebookDocument
)
=>
{
saveNotebook
:
async
(
_document
:
vscode
.
NotebookDocument
,
_cancellation
:
vscode
.
CancellationToken
)
=>
{
return
true
;
return
;
},
saveNotebookAs
:
async
(
_targetResource
:
vscode
.
Uri
,
_document
:
vscode
.
NotebookDocument
,
_cancellation
:
vscode
.
CancellationToken
)
=>
{
return
;
}
}
}));
}));
}
}
src/vs/workbench/api/browser/mainThreadNotebook.ts
浏览文件 @
1b521798
...
@@ -8,7 +8,7 @@ import { MainContext, MainThreadNotebookShape, NotebookExtensionDescription, IEx
...
@@ -8,7 +8,7 @@ import { MainContext, MainThreadNotebookShape, NotebookExtensionDescription, IEx
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
URI
,
UriComponents
}
from
'
vs/base/common/uri
'
;
import
{
URI
,
UriComponents
}
from
'
vs/base/common/uri
'
;
import
{
INotebookService
,
IMainNotebookController
}
from
'
vs/workbench/contrib/notebook/common/notebookService
'
;
import
{
INotebookService
,
IMainNotebookController
}
from
'
vs/workbench/contrib/notebook/common/notebookService
'
;
import
{
INotebookTextModel
,
INotebookMimeTypeSelector
,
NOTEBOOK_DISPLAY_ORDER
,
NotebookCellOutputsSplice
,
CellKind
,
NotebookDocumentMetadata
,
NotebookCellMetadata
,
ICellEditOperation
,
ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
INotebookTextModel
,
INotebookMimeTypeSelector
,
NOTEBOOK_DISPLAY_ORDER
,
NotebookCellOutputsSplice
,
CellKind
,
NotebookDocumentMetadata
,
NotebookCellMetadata
,
ICellEditOperation
,
ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER
,
CellEditType
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
NotebookTextModel
}
from
'
vs/workbench/contrib/notebook/common/model/notebookTextModel
'
;
import
{
NotebookTextModel
}
from
'
vs/workbench/contrib/notebook/common/model/notebookTextModel
'
;
import
{
IEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
...
@@ -84,7 +84,9 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
...
@@ -84,7 +84,9 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
registerListeners
()
{
registerListeners
()
{
this
.
_register
(
this
.
_notebookService
.
onDidChangeActiveEditor
(
e
=>
{
this
.
_register
(
this
.
_notebookService
.
onDidChangeActiveEditor
(
e
=>
{
this
.
_proxy
.
$updateActiveEditor
(
e
.
viewType
,
e
.
uri
);
this
.
_proxy
.
$acceptDocumentAndEditorsDelta
({
newActiveEditor
:
e
.
uri
});
}));
}));
const
updateOrder
=
()
=>
{
const
updateOrder
=
()
=>
{
...
@@ -116,8 +118,8 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
...
@@ -116,8 +118,8 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
this
.
_notebookService
.
unregisterNotebookRenderer
(
handle
);
this
.
_notebookService
.
unregisterNotebookRenderer
(
handle
);
}
}
async
$registerNotebookProvider
(
extension
:
NotebookExtensionDescription
,
viewType
:
string
):
Promise
<
void
>
{
async
$registerNotebookProvider
(
extension
:
NotebookExtensionDescription
,
viewType
:
string
,
v2
:
boolean
):
Promise
<
void
>
{
let
controller
=
new
MainThreadNotebookController
(
this
.
_proxy
,
this
,
viewType
);
let
controller
=
new
MainThreadNotebookController
(
this
.
_proxy
,
this
,
viewType
,
v2
);
this
.
_notebookProviders
.
set
(
viewType
,
controller
);
this
.
_notebookProviders
.
set
(
viewType
,
controller
);
this
.
_notebookService
.
registerNotebookController
(
viewType
,
extension
,
controller
);
this
.
_notebookService
.
registerNotebookController
(
viewType
,
extension
,
controller
);
return
;
return
;
...
@@ -129,11 +131,11 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
...
@@ -129,11 +131,11 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
return
;
return
;
}
}
async
$createNotebookDocument
(
handle
:
number
,
viewType
:
string
,
resource
:
UriComponents
):
Promise
<
void
>
{
async
$
_deprecated_
createNotebookDocument
(
handle
:
number
,
viewType
:
string
,
resource
:
UriComponents
):
Promise
<
void
>
{
let
controller
=
this
.
_notebookProviders
.
get
(
viewType
);
let
controller
=
this
.
_notebookProviders
.
get
(
viewType
);
if
(
controller
)
{
if
(
controller
)
{
controller
.
createNotebookDocument
(
handle
,
viewType
,
resource
);
controller
.
_deprecated_
createNotebookDocument
(
handle
,
viewType
,
resource
);
}
}
return
;
return
;
...
@@ -163,8 +165,8 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
...
@@ -163,8 +165,8 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
}
}
}
}
async
resolveNotebook
(
viewType
:
string
,
uri
:
URI
):
Promise
<
number
|
undefined
>
{
async
_deprecated_
resolveNotebook
(
viewType
:
string
,
uri
:
URI
):
Promise
<
number
|
undefined
>
{
let
handle
=
await
this
.
_proxy
.
$resolveNotebook
(
viewType
,
uri
);
let
handle
=
await
this
.
_proxy
.
$
_deprecated_
resolveNotebook
(
viewType
,
uri
);
return
handle
;
return
handle
;
}
}
...
@@ -195,15 +197,50 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
...
@@ -195,15 +197,50 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
export
class
MainThreadNotebookController
implements
IMainNotebookController
{
export
class
MainThreadNotebookController
implements
IMainNotebookController
{
private
_mapping
:
Map
<
string
,
MainThreadNotebookDocument
>
=
new
Map
();
private
_mapping
:
Map
<
string
,
MainThreadNotebookDocument
>
=
new
Map
();
static
documentHandle
:
number
=
0
;
constructor
(
constructor
(
private
readonly
_proxy
:
ExtHostNotebookShape
,
private
readonly
_proxy
:
ExtHostNotebookShape
,
private
_mainThreadNotebook
:
MainThreadNotebooks
,
private
_mainThreadNotebook
:
MainThreadNotebooks
,
private
_viewType
:
string
private
_viewType
:
string
,
public
readonly
v2
:
boolean
)
{
)
{
}
}
async
resolveNotebook
(
viewType
:
string
,
uri
:
URI
):
Promise
<
NotebookTextModel
|
undefined
>
{
async
createNotebook
(
viewType
:
string
,
uri
:
URI
,
forBackup
:
boolean
):
Promise
<
NotebookTextModel
|
undefined
>
{
let
mainthreadNotebook
=
this
.
_mapping
.
get
(
URI
.
from
(
uri
).
toString
());
if
(
mainthreadNotebook
)
{
return
mainthreadNotebook
.
textModel
;
}
let
document
=
new
MainThreadNotebookDocument
(
this
.
_proxy
,
MainThreadNotebookController
.
documentHandle
++
,
viewType
,
uri
);
await
this
.
createNotebookDocument
(
document
.
handle
,
document
.
viewType
,
document
.
uri
);
if
(
forBackup
)
{
return
document
.
textModel
;
}
// open notebook document
const
data
=
await
this
.
_proxy
.
$resolveNotebookData
(
viewType
,
uri
);
if
(
!
data
)
{
return
;
}
document
.
textModel
.
languages
=
data
.
languages
;
document
.
textModel
.
metadata
=
data
.
metadata
;
document
.
textModel
.
applyEdit
(
document
.
textModel
.
versionId
,
[
{
editType
:
CellEditType
.
Insert
,
index
:
0
,
cells
:
data
!
.
cells
}
]);
return
document
.
textModel
;
}
async
_deprecated_resolveNotebook
(
viewType
:
string
,
uri
:
URI
):
Promise
<
NotebookTextModel
|
undefined
>
{
// TODO: resolve notebook should wait for all notebook document destory operations to finish.
// TODO: resolve notebook should wait for all notebook document destory operations to finish.
let
mainthreadNotebook
=
this
.
_mapping
.
get
(
URI
.
from
(
uri
).
toString
());
let
mainthreadNotebook
=
this
.
_mapping
.
get
(
URI
.
from
(
uri
).
toString
());
...
@@ -211,7 +248,7 @@ export class MainThreadNotebookController implements IMainNotebookController {
...
@@ -211,7 +248,7 @@ export class MainThreadNotebookController implements IMainNotebookController {
return
mainthreadNotebook
.
textModel
;
return
mainthreadNotebook
.
textModel
;
}
}
let
notebookHandle
=
await
this
.
_mainThreadNotebook
.
resolveNotebook
(
viewType
,
uri
);
let
notebookHandle
=
await
this
.
_mainThreadNotebook
.
_deprecated_
resolveNotebook
(
viewType
,
uri
);
if
(
notebookHandle
!==
undefined
)
{
if
(
notebookHandle
!==
undefined
)
{
mainthreadNotebook
=
this
.
_mapping
.
get
(
URI
.
from
(
uri
).
toString
());
mainthreadNotebook
=
this
.
_mapping
.
get
(
URI
.
from
(
uri
).
toString
());
if
(
mainthreadNotebook
&&
mainthreadNotebook
.
textModel
.
cells
.
length
===
0
)
{
if
(
mainthreadNotebook
&&
mainthreadNotebook
.
textModel
.
cells
.
length
===
0
)
{
...
@@ -250,10 +287,35 @@ export class MainThreadNotebookController implements IMainNotebookController {
...
@@ -250,10 +287,35 @@ export class MainThreadNotebookController implements IMainNotebookController {
this
.
_proxy
.
$onDidReceiveMessage
(
uri
,
message
);
this
.
_proxy
.
$onDidReceiveMessage
(
uri
,
message
);
}
}
// Methods for ExtHost
async
createNotebookDocument
(
handle
:
number
,
viewType
:
string
,
resource
:
UriComponents
):
Promise
<
void
>
{
async
createNotebookDocument
(
handle
:
number
,
viewType
:
string
,
resource
:
UriComponents
):
Promise
<
void
>
{
let
document
=
new
MainThreadNotebookDocument
(
this
.
_proxy
,
handle
,
viewType
,
URI
.
revive
(
resource
));
let
document
=
new
MainThreadNotebookDocument
(
this
.
_proxy
,
handle
,
viewType
,
URI
.
revive
(
resource
));
this
.
_mapping
.
set
(
URI
.
revive
(
resource
).
toString
(),
document
);
this
.
_mapping
.
set
(
URI
.
revive
(
resource
).
toString
(),
document
);
await
this
.
_proxy
.
$acceptDocumentAndEditorsDelta
({
addedDocuments
:
[{
viewType
:
viewType
,
handle
:
document
.
handle
,
uri
:
resource
}]
});
}
async
removeNotebookDocument
(
notebook
:
INotebookTextModel
):
Promise
<
void
>
{
let
document
=
this
.
_mapping
.
get
(
URI
.
from
(
notebook
.
uri
).
toString
());
if
(
!
document
)
{
return
;
}
await
this
.
_proxy
.
$acceptDocumentAndEditorsDelta
({
removedDocuments
:
[
notebook
.
uri
]
});
document
.
dispose
();
this
.
_mapping
.
delete
(
URI
.
from
(
notebook
.
uri
).
toString
());
}
// Methods for ExtHost
async
_deprecated_createNotebookDocument
(
handle
:
number
,
viewType
:
string
,
resource
:
UriComponents
):
Promise
<
void
>
{
let
document
=
new
MainThreadNotebookDocument
(
this
.
_proxy
,
handle
,
viewType
,
URI
.
revive
(
resource
));
this
.
_mapping
.
set
(
URI
.
revive
(
resource
).
toString
(),
document
);
}
}
updateLanguages
(
resource
:
UriComponents
,
languages
:
string
[])
{
updateLanguages
(
resource
:
UriComponents
,
languages
:
string
[])
{
...
@@ -280,20 +342,6 @@ export class MainThreadNotebookController implements IMainNotebookController {
...
@@ -280,20 +342,6 @@ export class MainThreadNotebookController implements IMainNotebookController {
return
this
.
_proxy
.
$executeNotebook
(
this
.
_viewType
,
uri
,
handle
,
token
);
return
this
.
_proxy
.
$executeNotebook
(
this
.
_viewType
,
uri
,
handle
,
token
);
}
}
async
destoryNotebookDocument
(
notebook
:
INotebookTextModel
):
Promise
<
void
>
{
let
document
=
this
.
_mapping
.
get
(
URI
.
from
(
notebook
.
uri
).
toString
());
if
(
!
document
)
{
return
;
}
let
removeFromExtHost
=
await
this
.
_proxy
.
$destoryNotebookDocument
(
this
.
_viewType
,
notebook
.
uri
);
if
(
removeFromExtHost
)
{
document
.
dispose
();
this
.
_mapping
.
delete
(
URI
.
from
(
notebook
.
uri
).
toString
());
}
}
async
save
(
uri
:
URI
,
token
:
CancellationToken
):
Promise
<
boolean
>
{
async
save
(
uri
:
URI
,
token
:
CancellationToken
):
Promise
<
boolean
>
{
return
this
.
_proxy
.
$saveNotebook
(
this
.
_viewType
,
uri
,
token
);
return
this
.
_proxy
.
$saveNotebook
(
this
.
_viewType
,
uri
,
token
);
}
}
...
...
src/vs/workbench/api/common/extHost.protocol.ts
浏览文件 @
1b521798
...
@@ -51,7 +51,7 @@ import { TunnelDto } from 'vs/workbench/api/common/extHostTunnelService';
...
@@ -51,7 +51,7 @@ import { TunnelDto } from 'vs/workbench/api/common/extHostTunnelService';
import
{
TunnelOptions
}
from
'
vs/platform/remote/common/tunnel
'
;
import
{
TunnelOptions
}
from
'
vs/platform/remote/common/tunnel
'
;
import
{
Timeline
,
TimelineChangeEvent
,
TimelineOptions
,
TimelineProviderDescriptor
,
InternalTimelineOptions
}
from
'
vs/workbench/contrib/timeline/common/timeline
'
;
import
{
Timeline
,
TimelineChangeEvent
,
TimelineOptions
,
TimelineProviderDescriptor
,
InternalTimelineOptions
}
from
'
vs/workbench/contrib/timeline/common/timeline
'
;
import
{
revive
}
from
'
vs/base/common/marshalling
'
;
import
{
revive
}
from
'
vs/base/common/marshalling
'
;
import
{
INotebookMimeTypeSelector
,
IOutput
,
INotebookDisplayOrder
,
NotebookCellMetadata
,
NotebookDocumentMetadata
,
ICellEditOperation
,
NotebookCellsChangedEvent
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
INotebookMimeTypeSelector
,
IOutput
,
INotebookDisplayOrder
,
NotebookCellMetadata
,
NotebookDocumentMetadata
,
ICellEditOperation
,
NotebookCellsChangedEvent
,
NotebookDataDto
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
CallHierarchyItem
}
from
'
vs/workbench/contrib/callHierarchy/common/callHierarchy
'
;
import
{
CallHierarchyItem
}
from
'
vs/workbench/contrib/callHierarchy/common/callHierarchy
'
;
import
{
Dto
}
from
'
vs/base/common/types
'
;
import
{
Dto
}
from
'
vs/base/common/types
'
;
import
{
ISerializableEnvironmentVariableCollection
}
from
'
vs/workbench/contrib/terminal/common/environmentVariable
'
;
import
{
ISerializableEnvironmentVariableCollection
}
from
'
vs/workbench/contrib/terminal/common/environmentVariable
'
;
...
@@ -687,11 +687,11 @@ export type NotebookCellOutputsSplice = [
...
@@ -687,11 +687,11 @@ export type NotebookCellOutputsSplice = [
];
];
export
interface
MainThreadNotebookShape
extends
IDisposable
{
export
interface
MainThreadNotebookShape
extends
IDisposable
{
$registerNotebookProvider
(
extension
:
NotebookExtensionDescription
,
viewType
:
string
):
Promise
<
void
>
;
$registerNotebookProvider
(
extension
:
NotebookExtensionDescription
,
viewType
:
string
,
v2
:
boolean
):
Promise
<
void
>
;
$unregisterNotebookProvider
(
viewType
:
string
):
Promise
<
void
>
;
$unregisterNotebookProvider
(
viewType
:
string
):
Promise
<
void
>
;
$registerNotebookRenderer
(
extension
:
NotebookExtensionDescription
,
type
:
string
,
selectors
:
INotebookMimeTypeSelector
,
handle
:
number
,
preloads
:
UriComponents
[]):
Promise
<
void
>
;
$registerNotebookRenderer
(
extension
:
NotebookExtensionDescription
,
type
:
string
,
selectors
:
INotebookMimeTypeSelector
,
handle
:
number
,
preloads
:
UriComponents
[]):
Promise
<
void
>
;
$unregisterNotebookRenderer
(
handle
:
number
):
Promise
<
void
>
;
$unregisterNotebookRenderer
(
handle
:
number
):
Promise
<
void
>
;
$createNotebookDocument
(
handle
:
number
,
viewType
:
string
,
resource
:
UriComponents
):
Promise
<
void
>
;
$
_deprecated_
createNotebookDocument
(
handle
:
number
,
viewType
:
string
,
resource
:
UriComponents
):
Promise
<
void
>
;
$tryApplyEdits
(
viewType
:
string
,
resource
:
UriComponents
,
modelVersionId
:
number
,
edits
:
ICellEditOperation
[],
renderers
:
number
[]):
Promise
<
boolean
>
;
$tryApplyEdits
(
viewType
:
string
,
resource
:
UriComponents
,
modelVersionId
:
number
,
edits
:
ICellEditOperation
[],
renderers
:
number
[]):
Promise
<
boolean
>
;
$updateNotebookLanguages
(
viewType
:
string
,
resource
:
UriComponents
,
languages
:
string
[]):
Promise
<
void
>
;
$updateNotebookLanguages
(
viewType
:
string
,
resource
:
UriComponents
,
languages
:
string
[]):
Promise
<
void
>
;
$updateNotebookMetadata
(
viewType
:
string
,
resource
:
UriComponents
,
metadata
:
NotebookDocumentMetadata
):
Promise
<
void
>
;
$updateNotebookMetadata
(
viewType
:
string
,
resource
:
UriComponents
,
metadata
:
NotebookDocumentMetadata
):
Promise
<
void
>
;
...
@@ -1538,16 +1538,31 @@ export interface INotebookEditorPropertiesChangeData {
...
@@ -1538,16 +1538,31 @@ export interface INotebookEditorPropertiesChangeData {
selections
:
INotebookSelectionChangeEvent
|
null
;
selections
:
INotebookSelectionChangeEvent
|
null
;
}
}
export
interface
INotebookModelAddedData
{
uri
:
UriComponents
;
handle
:
number
;
// versionId: number;
viewType
:
string
;
}
export
interface
INotebookDocumentsAndEditorsDelta
{
removedDocuments
?:
UriComponents
[];
addedDocuments
?:
INotebookModelAddedData
[];
// removedEditors?: string[];
// addedEditors?: ITextEditorAddData[];
newActiveEditor
?:
UriComponents
|
null
;
}
export
interface
ExtHostNotebookShape
{
export
interface
ExtHostNotebookShape
{
$resolveNotebook
(
viewType
:
string
,
uri
:
UriComponents
):
Promise
<
number
|
undefined
>
;
$resolveNotebookData
(
viewType
:
string
,
uri
:
UriComponents
):
Promise
<
NotebookDataDto
|
undefined
>
;
$_deprecated_resolveNotebook
(
viewType
:
string
,
uri
:
UriComponents
):
Promise
<
number
|
undefined
>
;
$executeNotebook
(
viewType
:
string
,
uri
:
UriComponents
,
cellHandle
:
number
|
undefined
,
token
:
CancellationToken
):
Promise
<
void
>
;
$executeNotebook
(
viewType
:
string
,
uri
:
UriComponents
,
cellHandle
:
number
|
undefined
,
token
:
CancellationToken
):
Promise
<
void
>
;
$saveNotebook
(
viewType
:
string
,
uri
:
UriComponents
,
token
:
CancellationToken
):
Promise
<
boolean
>
;
$saveNotebook
(
viewType
:
string
,
uri
:
UriComponents
,
token
:
CancellationToken
):
Promise
<
boolean
>
;
$updateActiveEditor
(
viewType
:
string
,
uri
:
UriComponents
):
Promise
<
void
>
;
$destoryNotebookDocument
(
viewType
:
string
,
uri
:
UriComponents
):
Promise
<
boolean
>
;
$acceptDisplayOrder
(
displayOrder
:
INotebookDisplayOrder
):
void
;
$acceptDisplayOrder
(
displayOrder
:
INotebookDisplayOrder
):
void
;
$onDidReceiveMessage
(
uri
:
UriComponents
,
message
:
any
):
void
;
$onDidReceiveMessage
(
uri
:
UriComponents
,
message
:
any
):
void
;
$acceptModelChanged
(
uriComponents
:
UriComponents
,
event
:
NotebookCellsChangedEvent
):
void
;
$acceptModelChanged
(
uriComponents
:
UriComponents
,
event
:
NotebookCellsChangedEvent
):
void
;
$acceptEditorPropertiesChanged
(
uriComponents
:
UriComponents
,
data
:
INotebookEditorPropertiesChangeData
):
void
;
$acceptEditorPropertiesChanged
(
uriComponents
:
UriComponents
,
data
:
INotebookEditorPropertiesChangeData
):
void
;
$acceptDocumentAndEditorsDelta
(
delta
:
INotebookDocumentsAndEditorsDelta
):
Promise
<
void
>
;
}
}
export
interface
ExtHostStorageShape
{
export
interface
ExtHostStorageShape
{
...
...
src/vs/workbench/api/common/extHostNotebook.ts
浏览文件 @
1b521798
...
@@ -10,10 +10,10 @@ import { Disposable, DisposableStore, IDisposable } from 'vs/base/common/lifecyc
...
@@ -10,10 +10,10 @@ import { Disposable, DisposableStore, IDisposable } from 'vs/base/common/lifecyc
import
{
ISplice
}
from
'
vs/base/common/sequence
'
;
import
{
ISplice
}
from
'
vs/base/common/sequence
'
;
import
{
URI
,
UriComponents
}
from
'
vs/base/common/uri
'
;
import
{
URI
,
UriComponents
}
from
'
vs/base/common/uri
'
;
import
{
IExtensionDescription
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
IExtensionDescription
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
CellKind
,
CellOutputKind
,
ExtHostNotebookShape
,
IMainContext
,
MainContext
,
MainThreadNotebookShape
,
NotebookCellOutputsSplice
,
MainThreadDocumentsShape
,
INotebookEditorPropertiesChangeData
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
CellKind
,
CellOutputKind
,
ExtHostNotebookShape
,
IMainContext
,
MainContext
,
MainThreadNotebookShape
,
NotebookCellOutputsSplice
,
MainThreadDocumentsShape
,
INotebookEditorPropertiesChangeData
,
INotebookDocumentsAndEditorsDelta
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
ExtHostCommands
}
from
'
vs/workbench/api/common/extHostCommands
'
;
import
{
ExtHostCommands
}
from
'
vs/workbench/api/common/extHostCommands
'
;
import
{
ExtHostDocumentsAndEditors
}
from
'
vs/workbench/api/common/extHostDocumentsAndEditors
'
;
import
{
ExtHostDocumentsAndEditors
}
from
'
vs/workbench/api/common/extHostDocumentsAndEditors
'
;
import
{
CellEditType
,
CellUri
,
diff
,
ICellEditOperation
,
ICellInsertEdit
,
IErrorOutput
,
INotebookDisplayOrder
,
INotebookEditData
,
IOrderedMimeType
,
IStreamOutput
,
ITransformedDisplayOutputDto
,
mimeTypeSupportedByCore
,
NotebookCellsChangedEvent
,
NotebookCellsSplice2
,
sortMimeTypes
,
ICellDeleteEdit
,
notebookDocumentMetadataDefaults
,
NotebookCellsChangeType
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
CellEditType
,
CellUri
,
diff
,
ICellEditOperation
,
ICellInsertEdit
,
IErrorOutput
,
INotebookDisplayOrder
,
INotebookEditData
,
IOrderedMimeType
,
IStreamOutput
,
ITransformedDisplayOutputDto
,
mimeTypeSupportedByCore
,
NotebookCellsChangedEvent
,
NotebookCellsSplice2
,
sortMimeTypes
,
ICellDeleteEdit
,
notebookDocumentMetadataDefaults
,
NotebookCellsChangeType
,
NotebookDataDto
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
Disposable
as
VSCodeDisposable
}
from
'
./extHostTypes
'
;
import
{
Disposable
as
VSCodeDisposable
}
from
'
./extHostTypes
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
ExtHostDocumentData
}
from
'
vs/workbench/api/common/extHostDocumentData
'
;
import
{
ExtHostDocumentData
}
from
'
vs/workbench/api/common/extHostDocumentData
'
;
...
@@ -717,7 +717,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
...
@@ -717,7 +717,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
}
}
this
.
_notebookProviders
.
set
(
viewType
,
{
extension
,
provider
});
this
.
_notebookProviders
.
set
(
viewType
,
{
extension
,
provider
});
this
.
_proxy
.
$registerNotebookProvider
({
id
:
extension
.
identifier
,
location
:
extension
.
extensionLocation
},
viewType
);
this
.
_proxy
.
$registerNotebookProvider
({
id
:
extension
.
identifier
,
location
:
extension
.
extensionLocation
},
viewType
,
false
);
return
new
VSCodeDisposable
(()
=>
{
return
new
VSCodeDisposable
(()
=>
{
this
.
_notebookProviders
.
delete
(
viewType
);
this
.
_notebookProviders
.
delete
(
viewType
);
this
.
_proxy
.
$unregisterNotebookProvider
(
viewType
);
this
.
_proxy
.
$unregisterNotebookProvider
(
viewType
);
...
@@ -735,7 +735,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
...
@@ -735,7 +735,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
}
}
this
.
_notebookContentProviders
.
set
(
viewType
,
{
extension
,
provider
});
this
.
_notebookContentProviders
.
set
(
viewType
,
{
extension
,
provider
});
this
.
_proxy
.
$registerNotebookProvider
({
id
:
extension
.
identifier
,
location
:
extension
.
extensionLocation
},
viewType
);
this
.
_proxy
.
$registerNotebookProvider
({
id
:
extension
.
identifier
,
location
:
extension
.
extensionLocation
},
viewType
,
true
);
return
new
VSCodeDisposable
(()
=>
{
return
new
VSCodeDisposable
(()
=>
{
this
.
_notebookContentProviders
.
delete
(
viewType
);
this
.
_notebookContentProviders
.
delete
(
viewType
);
this
.
_proxy
.
$unregisterNotebookProvider
(
viewType
);
this
.
_proxy
.
$unregisterNotebookProvider
(
viewType
);
...
@@ -749,7 +749,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
...
@@ -749,7 +749,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
const
revivedUri
=
URI
.
revive
(
uri
);
const
revivedUri
=
URI
.
revive
(
uri
);
if
(
!
this
.
_documents
.
has
(
revivedUri
.
toString
()))
{
if
(
!
this
.
_documents
.
has
(
revivedUri
.
toString
()))
{
let
document
=
new
ExtHostNotebookDocument
(
this
.
_proxy
,
this
.
_documentsAndEditors
,
viewType
,
revivedUri
,
this
);
let
document
=
new
ExtHostNotebookDocument
(
this
.
_proxy
,
this
.
_documentsAndEditors
,
viewType
,
revivedUri
,
this
);
await
this
.
_proxy
.
$createNotebookDocument
(
await
this
.
_proxy
.
$
_deprecated_
createNotebookDocument
(
document
.
handle
,
document
.
handle
,
viewType
,
viewType
,
uri
uri
...
@@ -793,7 +793,104 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
...
@@ -793,7 +793,104 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
}
}
}
}
async
$resolveNotebook
(
viewType
:
string
,
uri
:
UriComponents
):
Promise
<
number
|
undefined
>
{
async
$resolveNotebookData
(
viewType
:
string
,
uri
:
UriComponents
):
Promise
<
NotebookDataDto
|
undefined
>
{
let
provider
=
this
.
_notebookContentProviders
.
get
(
viewType
);
let
document
=
this
.
_documents
.
get
(
URI
.
revive
(
uri
).
toString
());
if
(
provider
&&
document
)
{
const
rawCells
=
await
provider
.
provider
.
openNotebook
(
URI
.
revive
(
uri
));
const
renderers
=
new
Set
<
number
>
();
const
dto
=
{
metadata
:
{
...
notebookDocumentMetadataDefaults
,
...
rawCells
.
metadata
},
languages
:
rawCells
.
languages
,
cells
:
rawCells
.
cells
.
map
(
cell
=>
{
let
transformedOutputs
=
cell
.
outputs
.
map
(
output
=>
{
if
(
output
.
outputKind
===
CellOutputKind
.
Rich
)
{
// TODO display string[]
const
ret
=
this
.
_transformMimeTypes
(
document
!
,
(
rawCells
.
metadata
.
displayOrder
as
string
[])
||
[],
output
);
if
(
ret
.
orderedMimeTypes
[
ret
.
pickedMimeTypeIndex
].
isResolved
)
{
renderers
.
add
(
ret
.
orderedMimeTypes
[
ret
.
pickedMimeTypeIndex
].
rendererId
!
);
}
return
ret
;
}
else
{
return
output
as
IStreamOutput
|
IErrorOutput
;
}
});
return
{
language
:
cell
.
language
,
cellKind
:
cell
.
cellKind
,
metadata
:
cell
.
metadata
,
source
:
cell
.
source
,
outputs
:
transformedOutputs
};
})
};
return
dto
;
}
return
;
}
private
_transformMimeTypes
(
document
:
ExtHostNotebookDocument
,
displayOrder
:
string
[],
output
:
vscode
.
CellDisplayOutput
):
ITransformedDisplayOutputDto
{
let
mimeTypes
=
Object
.
keys
(
output
.
data
);
// TODO@rebornix, the document display order might be assigned a bit later. We need to postpone sending the outputs to the core side.
let
coreDisplayOrder
=
this
.
outputDisplayOrder
;
const
sorted
=
sortMimeTypes
(
mimeTypes
,
coreDisplayOrder
?.
userOrder
||
[],
displayOrder
,
coreDisplayOrder
?.
defaultOrder
||
[]);
let
orderMimeTypes
:
IOrderedMimeType
[]
=
[];
sorted
.
forEach
(
mimeType
=>
{
let
handlers
=
this
.
findBestMatchedRenderer
(
mimeType
);
if
(
handlers
.
length
)
{
let
renderedOutput
=
handlers
[
0
].
render
(
document
,
output
,
mimeType
);
orderMimeTypes
.
push
({
mimeType
:
mimeType
,
isResolved
:
true
,
rendererId
:
handlers
[
0
].
handle
,
output
:
renderedOutput
});
for
(
let
i
=
1
;
i
<
handlers
.
length
;
i
++
)
{
orderMimeTypes
.
push
({
mimeType
:
mimeType
,
isResolved
:
false
,
rendererId
:
handlers
[
i
].
handle
});
}
if
(
mimeTypeSupportedByCore
(
mimeType
))
{
orderMimeTypes
.
push
({
mimeType
:
mimeType
,
isResolved
:
false
,
rendererId
:
-
1
});
}
}
else
{
orderMimeTypes
.
push
({
mimeType
:
mimeType
,
isResolved
:
false
});
}
});
return
{
outputKind
:
output
.
outputKind
,
data
:
output
.
data
,
orderedMimeTypes
:
orderMimeTypes
,
pickedMimeTypeIndex
:
0
};
}
async
$_deprecated_resolveNotebook
(
viewType
:
string
,
uri
:
UriComponents
):
Promise
<
number
|
undefined
>
{
let
notebookFromNotebookContentProvider
=
await
this
.
_resolveNotebookFromContentProvider
(
viewType
,
uri
);
let
notebookFromNotebookContentProvider
=
await
this
.
_resolveNotebookFromContentProvider
(
viewType
,
uri
);
if
(
notebookFromNotebookContentProvider
!==
undefined
)
{
if
(
notebookFromNotebookContentProvider
!==
undefined
)
{
...
@@ -805,7 +902,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
...
@@ -805,7 +902,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
if
(
provider
)
{
if
(
provider
)
{
if
(
!
this
.
_documents
.
has
(
URI
.
revive
(
uri
).
toString
()))
{
if
(
!
this
.
_documents
.
has
(
URI
.
revive
(
uri
).
toString
()))
{
let
document
=
new
ExtHostNotebookDocument
(
this
.
_proxy
,
this
.
_documentsAndEditors
,
viewType
,
URI
.
revive
(
uri
),
this
);
let
document
=
new
ExtHostNotebookDocument
(
this
.
_proxy
,
this
.
_documentsAndEditors
,
viewType
,
URI
.
revive
(
uri
),
this
);
await
this
.
_proxy
.
$createNotebookDocument
(
await
this
.
_proxy
.
$
_deprecated_
createNotebookDocument
(
document
.
handle
,
document
.
handle
,
viewType
,
viewType
,
uri
uri
...
@@ -883,37 +980,6 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
...
@@ -883,37 +980,6 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
return
false
;
return
false
;
}
}
async
$updateActiveEditor
(
viewType
:
string
,
uri
:
UriComponents
):
Promise
<
void
>
{
this
.
_activeNotebookDocument
=
this
.
_documents
.
get
(
URI
.
revive
(
uri
).
toString
());
this
.
_activeNotebookEditor
=
this
.
_editors
.
get
(
URI
.
revive
(
uri
).
toString
())?.
editor
;
}
async
$destoryNotebookDocument
(
viewType
:
string
,
uri
:
UriComponents
):
Promise
<
boolean
>
{
let
provider
=
this
.
_notebookProviders
.
get
(
viewType
);
if
(
!
provider
)
{
return
false
;
}
let
document
=
this
.
_documents
.
get
(
URI
.
revive
(
uri
).
toString
());
if
(
document
)
{
document
.
dispose
();
this
.
_documents
.
delete
(
URI
.
revive
(
uri
).
toString
());
this
.
_onDidCloseNotebookDocument
.
fire
(
document
);
}
let
editor
=
this
.
_editors
.
get
(
URI
.
revive
(
uri
).
toString
());
if
(
editor
)
{
editor
.
editor
.
dispose
();
editor
.
onDidReceiveMessage
.
dispose
();
this
.
_editors
.
delete
(
URI
.
revive
(
uri
).
toString
());
}
return
true
;
}
$acceptDisplayOrder
(
displayOrder
:
INotebookDisplayOrder
):
void
{
$acceptDisplayOrder
(
displayOrder
:
INotebookDisplayOrder
):
void
{
this
.
_outputDisplayOrder
=
displayOrder
;
this
.
_outputDisplayOrder
=
displayOrder
;
}
}
...
@@ -957,4 +1023,57 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
...
@@ -957,4 +1023,57 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
}
}
}
}
}
}
async
$acceptDocumentAndEditorsDelta
(
delta
:
INotebookDocumentsAndEditorsDelta
)
{
if
(
delta
.
removedDocuments
)
{
delta
.
removedDocuments
.
forEach
((
uri
)
=>
{
let
document
=
this
.
_documents
.
get
(
URI
.
revive
(
uri
).
toString
());
if
(
document
)
{
document
.
dispose
();
this
.
_documents
.
delete
(
URI
.
revive
(
uri
).
toString
());
this
.
_onDidCloseNotebookDocument
.
fire
(
document
);
}
let
editor
=
this
.
_editors
.
get
(
URI
.
revive
(
uri
).
toString
());
if
(
editor
)
{
editor
.
editor
.
dispose
();
editor
.
onDidReceiveMessage
.
dispose
();
this
.
_editors
.
delete
(
URI
.
revive
(
uri
).
toString
());
}
});
}
if
(
delta
.
addedDocuments
)
{
delta
.
addedDocuments
.
forEach
(
modelData
=>
{
const
revivedUri
=
URI
.
revive
(
modelData
.
uri
);
const
viewType
=
modelData
.
viewType
;
if
(
!
this
.
_documents
.
has
(
revivedUri
.
toString
()))
{
let
document
=
new
ExtHostNotebookDocument
(
this
.
_proxy
,
this
.
_documentsAndEditors
,
viewType
,
revivedUri
,
this
);
this
.
_documents
.
set
(
revivedUri
.
toString
(),
document
);
}
const
onDidReceiveMessage
=
new
Emitter
<
any
>
();
let
editor
=
new
ExtHostNotebookEditor
(
viewType
,
`
${
ExtHostNotebookController
.
_handlePool
++
}
`
,
revivedUri
,
this
.
_proxy
,
onDidReceiveMessage
,
this
.
_documents
.
get
(
revivedUri
.
toString
())
!
,
this
.
_documentsAndEditors
);
// TODO, does it already exist?
this
.
_editors
.
set
(
revivedUri
.
toString
(),
{
editor
,
onDidReceiveMessage
});
});
}
if
(
delta
.
newActiveEditor
)
{
this
.
_activeNotebookDocument
=
this
.
_documents
.
get
(
URI
.
revive
(
delta
.
newActiveEditor
).
toString
());
this
.
_activeNotebookEditor
=
this
.
_editors
.
get
(
URI
.
revive
(
delta
.
newActiveEditor
).
toString
())?.
editor
;
}
}
}
}
src/vs/workbench/contrib/notebook/browser/notebookEditorInput.ts
浏览文件 @
1b521798
...
@@ -96,6 +96,10 @@ export class NotebookEditorInput extends EditorInput {
...
@@ -96,6 +96,10 @@ export class NotebookEditorInput extends EditorInput {
this
.
_onDidChangeDirty
.
fire
();
this
.
_onDidChangeDirty
.
fire
();
}));
}));
if
(
this
.
textModel
.
isDirty
())
{
this
.
_onDidChangeDirty
.
fire
();
}
return
this
.
textModel
;
return
this
.
textModel
;
}
}
...
...
src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts
浏览文件 @
1b521798
...
@@ -11,7 +11,7 @@ import { notebookProviderExtensionPoint, notebookRendererExtensionPoint } from '
...
@@ -11,7 +11,7 @@ import { notebookProviderExtensionPoint, notebookRendererExtensionPoint } from '
import
{
NotebookProviderInfo
}
from
'
vs/workbench/contrib/notebook/common/notebookProvider
'
;
import
{
NotebookProviderInfo
}
from
'
vs/workbench/contrib/notebook/common/notebookProvider
'
;
import
{
NotebookExtensionDescription
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
NotebookExtensionDescription
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
INotebookTextModel
,
INotebookMimeTypeSelector
,
INotebookRendererInfo
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
INotebookTextModel
,
INotebookMimeTypeSelector
,
INotebookRendererInfo
,
NotebookDocumentMetadata
,
CellEditType
,
ICellDto2
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
IExtensionService
}
from
'
vs/workbench/services/extensions/common/extensions
'
;
import
{
IExtensionService
}
from
'
vs/workbench/services/extensions/common/extensions
'
;
import
{
NotebookOutputRendererInfo
}
from
'
vs/workbench/contrib/notebook/common/notebookOutputRenderer
'
;
import
{
NotebookOutputRendererInfo
}
from
'
vs/workbench/contrib/notebook/common/notebookOutputRenderer
'
;
import
{
Iterable
}
from
'
vs/base/common/iterator
'
;
import
{
Iterable
}
from
'
vs/base/common/iterator
'
;
...
@@ -202,13 +202,13 @@ export class NotebookService extends Disposable implements INotebookService, ICu
...
@@ -202,13 +202,13 @@ export class NotebookService extends Disposable implements INotebookService, ICu
return
;
return
;
}
}
async
resolveNotebook
(
viewType
:
string
,
uri
:
URI
):
Promise
<
NotebookTextModel
|
undefined
>
{
async
createNotebookFromBackup
(
viewType
:
string
,
uri
:
URI
,
metadata
:
NotebookDocumentMetadata
,
cells
:
ICellDto2
[]
):
Promise
<
NotebookTextModel
|
undefined
>
{
const
provider
=
this
.
_notebookProviders
.
get
(
viewType
);
const
provider
=
this
.
_notebookProviders
.
get
(
viewType
);
if
(
!
provider
)
{
if
(
!
provider
)
{
return
undefined
;
return
undefined
;
}
}
const
notebookModel
=
await
provider
.
controller
.
resolveNotebook
(
viewType
,
uri
);
const
notebookModel
=
await
provider
.
controller
.
createNotebook
(
viewType
,
uri
,
true
);
if
(
!
notebookModel
)
{
if
(
!
notebookModel
)
{
return
undefined
;
return
undefined
;
}
}
...
@@ -219,6 +219,43 @@ export class NotebookService extends Disposable implements INotebookService, ICu
...
@@ -219,6 +219,43 @@ export class NotebookService extends Disposable implements INotebookService, ICu
notebookModel
,
notebookModel
,
(
model
)
=>
this
.
_onWillDispose
(
model
),
(
model
)
=>
this
.
_onWillDispose
(
model
),
);
);
this
.
_models
[
modelId
]
=
modelData
;
notebookModel
.
metadata
=
metadata
;
notebookModel
.
languages
=
[];
notebookModel
.
applyEdit
(
notebookModel
.
versionId
,
[
{
editType
:
CellEditType
.
Insert
,
index
:
0
,
cells
:
cells
}
]);
return
modelData
.
model
;
}
async
resolveNotebook
(
viewType
:
string
,
uri
:
URI
):
Promise
<
NotebookTextModel
|
undefined
>
{
const
provider
=
this
.
_notebookProviders
.
get
(
viewType
);
if
(
!
provider
)
{
return
undefined
;
}
let
notebookModel
:
NotebookTextModel
|
undefined
;
if
(
provider
.
controller
.
v2
)
{
notebookModel
=
await
provider
.
controller
.
createNotebook
(
viewType
,
uri
,
false
);
}
else
{
notebookModel
=
await
provider
.
controller
.
_deprecated_resolveNotebook
(
viewType
,
uri
);
}
// new notebook model created
const
modelId
=
MODEL_ID
(
uri
);
const
modelData
=
new
ModelData
(
notebookModel
!
,
(
model
)
=>
this
.
_onWillDispose
(
model
),
);
this
.
_models
[
modelId
]
=
modelData
;
this
.
_models
[
modelId
]
=
modelData
;
return
modelData
.
model
;
return
modelData
.
model
;
}
}
...
@@ -265,7 +302,7 @@ export class NotebookService extends Disposable implements INotebookService, ICu
...
@@ -265,7 +302,7 @@ export class NotebookService extends Disposable implements INotebookService, ICu
let
provider
=
this
.
_notebookProviders
.
get
(
viewType
);
let
provider
=
this
.
_notebookProviders
.
get
(
viewType
);
if
(
provider
)
{
if
(
provider
)
{
provider
.
controller
.
destory
NotebookDocument
(
notebook
);
provider
.
controller
.
remove
NotebookDocument
(
notebook
);
}
}
}
}
...
...
src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts
浏览文件 @
1b521798
...
@@ -8,6 +8,7 @@ import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
...
@@ -8,6 +8,7 @@ import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
NotebookCellTextModel
}
from
'
vs/workbench/contrib/notebook/common/model/notebookCellTextModel
'
;
import
{
NotebookCellTextModel
}
from
'
vs/workbench/contrib/notebook/common/model/notebookCellTextModel
'
;
import
{
INotebookTextModel
,
NotebookCellOutputsSplice
,
NotebookCellTextModelSplice
,
NotebookDocumentMetadata
,
NotebookCellMetadata
,
ICellEditOperation
,
CellEditType
,
CellUri
,
ICellInsertEdit
,
NotebookCellsChangedEvent
,
CellKind
,
IOutput
,
notebookDocumentMetadataDefaults
,
diff
,
ICellDeleteEdit
,
NotebookCellsChangeType
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
INotebookTextModel
,
NotebookCellOutputsSplice
,
NotebookCellTextModelSplice
,
NotebookDocumentMetadata
,
NotebookCellMetadata
,
ICellEditOperation
,
CellEditType
,
CellUri
,
ICellInsertEdit
,
NotebookCellsChangedEvent
,
CellKind
,
IOutput
,
notebookDocumentMetadataDefaults
,
diff
,
ICellDeleteEdit
,
NotebookCellsChangeType
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
ITextSnapshot
}
from
'
vs/editor/common/model
'
;
function
compareRangesUsingEnds
(
a
:
[
number
,
number
],
b
:
[
number
,
number
]):
number
{
function
compareRangesUsingEnds
(
a
:
[
number
,
number
],
b
:
[
number
,
number
]):
number
{
if
(
a
[
1
]
===
b
[
1
])
{
if
(
a
[
1
]
===
b
[
1
])
{
...
@@ -17,6 +18,49 @@ function compareRangesUsingEnds(a: [number, number], b: [number, number]): numbe
...
@@ -17,6 +18,49 @@ function compareRangesUsingEnds(a: [number, number], b: [number, number]): numbe
return
a
[
1
]
-
b
[
1
];
return
a
[
1
]
-
b
[
1
];
}
}
export
class
NotebookTextModelSnapshot
implements
ITextSnapshot
{
// private readonly _pieces: Ce[] = [];
private
_index
:
number
=
-
1
;
constructor
(
private
_model
:
NotebookTextModel
)
{
// for (let i = 0; i < this._model.cells.length; i++) {
// const cell = this._model.cells[i];
// this._pieces.push(this._model.cells[i].textBuffer.createSnapshot(true));
// }
}
read
():
string
|
null
{
if
(
this
.
_index
===
-
1
)
{
this
.
_index
++
;
return
`{ "metadata":
${
JSON
.
stringify
(
this
.
_model
.
metadata
)}
, "cells": [`
;
}
if
(
this
.
_index
<
this
.
_model
.
cells
.
length
)
{
const
cell
=
this
.
_model
.
cells
[
this
.
_index
];
const
data
=
{
source
:
cell
.
getValue
(),
metadata
:
cell
.
metadata
,
cellKind
:
cell
.
cellKind
,
language
:
cell
.
language
};
const
rawStr
=
JSON
.
stringify
(
data
);
const
isLastCell
=
this
.
_index
===
this
.
_model
.
cells
.
length
-
1
;
this
.
_index
++
;
return
isLastCell
?
rawStr
:
(
rawStr
+
'
,
'
);
}
else
if
(
this
.
_index
===
this
.
_model
.
cells
.
length
)
{
this
.
_index
++
;
return
`]}`
;
}
else
{
return
null
;
}
}
}
export
class
NotebookTextModel
extends
Disposable
implements
INotebookTextModel
{
export
class
NotebookTextModel
extends
Disposable
implements
INotebookTextModel
{
private
static
_cellhandlePool
:
number
=
0
;
private
static
_cellhandlePool
:
number
=
0
;
...
@@ -142,6 +186,10 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
...
@@ -142,6 +186,10 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
return
true
;
return
true
;
}
}
createSnapshot
(
preserveBOM
?:
boolean
):
ITextSnapshot
{
return
new
NotebookTextModelSnapshot
(
this
);
}
private
_increaseVersionId
():
void
{
private
_increaseVersionId
():
void
{
this
.
_versionId
=
this
.
_versionId
+
1
;
this
.
_versionId
=
this
.
_versionId
+
1
;
}
}
...
...
src/vs/workbench/contrib/notebook/common/notebookCommon.ts
浏览文件 @
1b521798
...
@@ -273,7 +273,7 @@ export enum CellEditType {
...
@@ -273,7 +273,7 @@ export enum CellEditType {
}
}
export
interface
ICellDto2
{
export
interface
ICellDto2
{
source
:
string
[];
source
:
string
|
string
[];
language
:
string
;
language
:
string
;
cellKind
:
CellKind
;
cellKind
:
CellKind
;
outputs
:
IOutput
[];
outputs
:
IOutput
[];
...
@@ -300,6 +300,13 @@ export interface INotebookEditData {
...
@@ -300,6 +300,13 @@ export interface INotebookEditData {
renderers
:
number
[];
renderers
:
number
[];
}
}
export
interface
NotebookDataDto
{
readonly
cells
:
ICellDto2
[];
readonly
languages
:
string
[];
readonly
metadata
:
NotebookDocumentMetadata
;
}
export
namespace
CellUri
{
export
namespace
CellUri
{
export
const
scheme
=
'
vscode-notebook
'
;
export
const
scheme
=
'
vscode-notebook
'
;
...
...
src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts
浏览文件 @
1b521798
...
@@ -15,6 +15,8 @@ import { URI } from 'vs/base/common/uri';
...
@@ -15,6 +15,8 @@ import { URI } from 'vs/base/common/uri';
import
{
IWorkingCopyService
,
IWorkingCopy
,
IWorkingCopyBackup
}
from
'
vs/workbench/services/workingCopy/common/workingCopyService
'
;
import
{
IWorkingCopyService
,
IWorkingCopy
,
IWorkingCopyBackup
}
from
'
vs/workbench/services/workingCopy/common/workingCopyService
'
;
import
{
basename
}
from
'
vs/base/common/resources
'
;
import
{
basename
}
from
'
vs/base/common/resources
'
;
import
{
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
import
{
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
import
{
IBackupFileService
}
from
'
vs/workbench/services/backup/common/backup
'
;
import
{
DefaultEndOfLine
,
ITextBuffer
,
EndOfLinePreference
}
from
'
vs/editor/common/model
'
;
export
interface
INotebookEditorModelManager
{
export
interface
INotebookEditorModelManager
{
models
:
NotebookEditorModel
[];
models
:
NotebookEditorModel
[];
...
@@ -47,7 +49,8 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
...
@@ -47,7 +49,8 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
public
readonly
resource
:
URI
,
public
readonly
resource
:
URI
,
public
readonly
viewType
:
string
,
public
readonly
viewType
:
string
,
@
INotebookService
private
readonly
notebookService
:
INotebookService
,
@
INotebookService
private
readonly
notebookService
:
INotebookService
,
@
IWorkingCopyService
private
readonly
workingCopyService
:
IWorkingCopyService
@
IWorkingCopyService
private
readonly
workingCopyService
:
IWorkingCopyService
,
@
IBackupFileService
private
readonly
backupFileService
:
IBackupFileService
)
{
)
{
super
();
super
();
this
.
_register
(
this
.
workingCopyService
.
registerWorkingCopy
(
this
));
this
.
_register
(
this
.
workingCopyService
.
registerWorkingCopy
(
this
));
...
@@ -56,7 +59,7 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
...
@@ -56,7 +59,7 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
capabilities
=
0
;
capabilities
=
0
;
async
backup
():
Promise
<
IWorkingCopyBackup
>
{
async
backup
():
Promise
<
IWorkingCopyBackup
>
{
return
{};
return
{
content
:
this
.
_notebook
.
createSnapshot
(
true
)
};
}
}
async
revert
(
options
?:
IRevertOptions
|
undefined
):
Promise
<
void
>
{
async
revert
(
options
?:
IRevertOptions
|
undefined
):
Promise
<
void
>
{
...
@@ -64,20 +67,72 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
...
@@ -64,20 +67,72 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
}
}
async
load
():
Promise
<
NotebookEditorModel
>
{
async
load
():
Promise
<
NotebookEditorModel
>
{
if
(
this
.
isResolved
())
{
return
this
;
}
const
backup
=
await
this
.
backupFileService
.
resolve
(
this
.
resource
);
if
(
this
.
isResolved
())
{
return
this
;
// Make sure meanwhile someone else did not succeed in loading
}
if
(
backup
)
{
try
{
return
await
this
.
loadFromBackup
(
backup
.
value
.
create
(
DefaultEndOfLine
.
LF
));
}
catch
(
error
)
{
// this.logService.error('[text file model] load() from backup', error); // ignore error and continue to load as file below
}
}
return
this
.
loadFromProvider
();
}
private
async
loadFromBackup
(
content
:
ITextBuffer
):
Promise
<
NotebookEditorModel
>
{
const
fullRange
=
content
.
getRangeAt
(
0
,
content
.
getLength
());
const
data
=
JSON
.
parse
(
content
.
getValueInRange
(
fullRange
,
EndOfLinePreference
.
LF
));
const
notebook
=
await
this
.
notebookService
.
createNotebookFromBackup
(
this
.
viewType
!
,
this
.
resource
,
data
.
metadata
,
data
.
cells
);
this
.
_notebook
=
notebook
!
;
this
.
_name
=
basename
(
this
.
_notebook
!
.
uri
);
this
.
_register
(
this
.
_notebook
.
onDidChangeContent
(()
=>
{
this
.
setDirty
(
true
);
this
.
_onDidChangeContent
.
fire
();
}));
await
this
.
backupFileService
.
discardBackup
(
this
.
resource
);
this
.
setDirty
(
true
);
return
this
;
}
private
async
loadFromProvider
()
{
const
notebook
=
await
this
.
notebookService
.
resolveNotebook
(
this
.
viewType
!
,
this
.
resource
);
const
notebook
=
await
this
.
notebookService
.
resolveNotebook
(
this
.
viewType
!
,
this
.
resource
);
this
.
_notebook
=
notebook
!
;
this
.
_notebook
=
notebook
!
;
this
.
_name
=
basename
(
this
.
_notebook
!
.
uri
);
this
.
_name
=
basename
(
this
.
_notebook
!
.
uri
);
this
.
_register
(
this
.
_notebook
.
onDidChangeContent
(()
=>
{
this
.
_register
(
this
.
_notebook
.
onDidChangeContent
(()
=>
{
this
.
_dirty
=
true
;
this
.
setDirty
(
true
);
this
.
_onDidChangeDirty
.
fire
();
this
.
_onDidChangeContent
.
fire
();
this
.
_onDidChangeContent
.
fire
();
}));
}));
return
this
;
return
this
;
}
}
isResolved
():
boolean
{
return
!!
this
.
_notebook
;
}
setDirty
(
newState
:
boolean
)
{
if
(
this
.
_dirty
!==
newState
)
{
this
.
_dirty
=
newState
;
this
.
_onDidChangeDirty
.
fire
();
}
}
isDirty
()
{
isDirty
()
{
return
this
.
_dirty
;
return
this
.
_dirty
;
}
}
...
...
src/vs/workbench/contrib/notebook/common/notebookService.ts
浏览文件 @
1b521798
...
@@ -8,7 +8,7 @@ import { URI } from 'vs/base/common/uri';
...
@@ -8,7 +8,7 @@ import { URI } from 'vs/base/common/uri';
import
{
NotebookProviderInfo
}
from
'
vs/workbench/contrib/notebook/common/notebookProvider
'
;
import
{
NotebookProviderInfo
}
from
'
vs/workbench/contrib/notebook/common/notebookProvider
'
;
import
{
NotebookExtensionDescription
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
NotebookExtensionDescription
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
Event
}
from
'
vs/base/common/event
'
;
import
{
Event
}
from
'
vs/base/common/event
'
;
import
{
INotebookTextModel
,
INotebookMimeTypeSelector
,
INotebookRendererInfo
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
INotebookTextModel
,
INotebookMimeTypeSelector
,
INotebookRendererInfo
,
NotebookDocumentMetadata
,
ICellDto2
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
NotebookTextModel
}
from
'
vs/workbench/contrib/notebook/common/model/notebookTextModel
'
;
import
{
NotebookTextModel
}
from
'
vs/workbench/contrib/notebook/common/model/notebookTextModel
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
NotebookCellTextModel
}
from
'
vs/workbench/contrib/notebook/common/model/notebookCellTextModel
'
;
import
{
NotebookCellTextModel
}
from
'
vs/workbench/contrib/notebook/common/model/notebookCellTextModel
'
;
...
@@ -17,11 +17,13 @@ import { INotebookEditorModelManager } from 'vs/workbench/contrib/notebook/commo
...
@@ -17,11 +17,13 @@ import { INotebookEditorModelManager } from 'vs/workbench/contrib/notebook/commo
export
const
INotebookService
=
createDecorator
<
INotebookService
>
(
'
notebookService
'
);
export
const
INotebookService
=
createDecorator
<
INotebookService
>
(
'
notebookService
'
);
export
interface
IMainNotebookController
{
export
interface
IMainNotebookController
{
resolveNotebook
(
viewType
:
string
,
uri
:
URI
):
Promise
<
NotebookTextModel
|
undefined
>
;
v2
:
boolean
;
createNotebook
(
viewType
:
string
,
uri
:
URI
,
fromBackup
:
boolean
):
Promise
<
NotebookTextModel
|
undefined
>
;
_deprecated_resolveNotebook
(
viewType
:
string
,
uri
:
URI
):
Promise
<
NotebookTextModel
|
undefined
>
;
executeNotebook
(
viewType
:
string
,
uri
:
URI
,
token
:
CancellationToken
):
Promise
<
void
>
;
executeNotebook
(
viewType
:
string
,
uri
:
URI
,
token
:
CancellationToken
):
Promise
<
void
>
;
onDidReceiveMessage
(
uri
:
URI
,
message
:
any
):
void
;
onDidReceiveMessage
(
uri
:
URI
,
message
:
any
):
void
;
executeNotebookCell
(
uri
:
URI
,
handle
:
number
,
token
:
CancellationToken
):
Promise
<
void
>
;
executeNotebookCell
(
uri
:
URI
,
handle
:
number
,
token
:
CancellationToken
):
Promise
<
void
>
;
destory
NotebookDocument
(
notebook
:
INotebookTextModel
):
Promise
<
void
>
;
remove
NotebookDocument
(
notebook
:
INotebookTextModel
):
Promise
<
void
>
;
save
(
uri
:
URI
,
token
:
CancellationToken
):
Promise
<
boolean
>
;
save
(
uri
:
URI
,
token
:
CancellationToken
):
Promise
<
boolean
>
;
}
}
...
@@ -36,6 +38,7 @@ export interface INotebookService {
...
@@ -36,6 +38,7 @@ export interface INotebookService {
unregisterNotebookRenderer
(
handle
:
number
):
void
;
unregisterNotebookRenderer
(
handle
:
number
):
void
;
getRendererInfo
(
handle
:
number
):
INotebookRendererInfo
|
undefined
;
getRendererInfo
(
handle
:
number
):
INotebookRendererInfo
|
undefined
;
resolveNotebook
(
viewType
:
string
,
uri
:
URI
):
Promise
<
NotebookTextModel
|
undefined
>
;
resolveNotebook
(
viewType
:
string
,
uri
:
URI
):
Promise
<
NotebookTextModel
|
undefined
>
;
createNotebookFromBackup
(
viewType
:
string
,
uri
:
URI
,
metadata
:
NotebookDocumentMetadata
,
cells
:
ICellDto2
[]):
Promise
<
NotebookTextModel
|
undefined
>
;
executeNotebook
(
viewType
:
string
,
uri
:
URI
):
Promise
<
void
>
;
executeNotebook
(
viewType
:
string
,
uri
:
URI
):
Promise
<
void
>
;
executeNotebookCell
(
viewType
:
string
,
uri
:
URI
,
handle
:
number
,
token
:
CancellationToken
):
Promise
<
void
>
;
executeNotebookCell
(
viewType
:
string
,
uri
:
URI
,
handle
:
number
,
token
:
CancellationToken
):
Promise
<
void
>
;
...
...
src/vs/workbench/test/browser/api/extHostNotebookConcatDocument.test.ts
浏览文件 @
1b521798
...
@@ -41,7 +41,7 @@ suite('NotebookConcatDocument', function () {
...
@@ -41,7 +41,7 @@ suite('NotebookConcatDocument', function () {
rpcProtocol
.
set
(
MainContext
.
MainThreadNotebook
,
new
class
extends
mock
<
MainThreadNotebookShape
>
()
{
rpcProtocol
.
set
(
MainContext
.
MainThreadNotebook
,
new
class
extends
mock
<
MainThreadNotebookShape
>
()
{
async
$registerNotebookProvider
()
{
}
async
$registerNotebookProvider
()
{
}
async
$unregisterNotebookProvider
()
{
}
async
$unregisterNotebookProvider
()
{
}
async
$createNotebookDocument
()
{
}
async
$
_deprecated_
createNotebookDocument
()
{
}
});
});
extHostDocumentsAndEditors
=
new
ExtHostDocumentsAndEditors
(
rpcProtocol
,
new
NullLogService
());
extHostDocumentsAndEditors
=
new
ExtHostDocumentsAndEditors
(
rpcProtocol
,
new
NullLogService
());
extHostDocuments
=
new
ExtHostDocuments
(
rpcProtocol
,
extHostDocumentsAndEditors
);
extHostDocuments
=
new
ExtHostDocuments
(
rpcProtocol
,
extHostDocumentsAndEditors
);
...
@@ -49,7 +49,7 @@ suite('NotebookConcatDocument', function () {
...
@@ -49,7 +49,7 @@ suite('NotebookConcatDocument', function () {
let
reg
=
extHostNotebooks
.
registerNotebookProvider
(
nullExtensionDescription
,
'
test
'
,
new
class
extends
mock
<
vscode
.
NotebookProvider
>
()
{
let
reg
=
extHostNotebooks
.
registerNotebookProvider
(
nullExtensionDescription
,
'
test
'
,
new
class
extends
mock
<
vscode
.
NotebookProvider
>
()
{
async
resolveNotebook
()
{
}
async
resolveNotebook
()
{
}
});
});
await
extHostNotebooks
.
$resolveNotebook
(
'
test
'
,
notebookUri
);
await
extHostNotebooks
.
$
_deprecated_
resolveNotebook
(
'
test
'
,
notebookUri
);
extHostNotebooks
.
$acceptModelChanged
(
notebookUri
,
{
extHostNotebooks
.
$acceptModelChanged
(
notebookUri
,
{
kind
:
NotebookCellsChangeType
.
ModelChange
,
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
0
,
versionId
:
0
,
...
@@ -62,7 +62,7 @@ suite('NotebookConcatDocument', function () {
...
@@ -62,7 +62,7 @@ suite('NotebookConcatDocument', function () {
outputs
:
[],
outputs
:
[],
}]]]
}]]]
});
});
await
extHostNotebooks
.
$
updateActiveEditor
(
'
test
'
,
notebookUri
);
await
extHostNotebooks
.
$
acceptDocumentAndEditorsDelta
({
newActiveEditor
:
notebookUri
}
);
notebook
=
extHostNotebooks
.
activeNotebookDocument
!
;
notebook
=
extHostNotebooks
.
activeNotebookDocument
!
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录