Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
27c96b7a
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,发现更多精彩内容 >>
提交
27c96b7a
编写于
7月 17, 2020
作者:
R
rebornix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
slim main thread notebook document
上级
2392bf40
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
43 addition
and
55 deletion
+43
-55
src/vs/workbench/api/browser/mainThreadNotebook.ts
src/vs/workbench/api/browser/mainThreadNotebook.ts
+26
-54
src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts
...kbench/contrib/notebook/common/model/notebookTextModel.ts
+17
-1
未找到文件。
src/vs/workbench/api/browser/mainThreadNotebook.ts
浏览文件 @
27c96b7a
...
...
@@ -3,10 +3,9 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
nls
from
'
vs/nls
'
;
import
*
as
DOM
from
'
vs/base/browser/dom
'
;
import
{
extHostNamedCustomer
}
from
'
vs/workbench/api/common/extHostCustomers
'
;
import
{
MainContext
,
MainThreadNotebookShape
,
NotebookExtensionDescription
,
IExtHostContext
,
ExtHostNotebookShape
,
ExtHostContext
,
INotebookDocumentsAndEditorsDelta
,
INotebookModelAddedData
}
from
'
../common/extHost.protocol
'
;
import
{
MainContext
,
MainThreadNotebookShape
,
NotebookExtensionDescription
,
IExtHostContext
,
ExtHostNotebookShape
,
ExtHostContext
,
INotebookDocumentsAndEditorsDelta
}
from
'
../common/extHost.protocol
'
;
import
{
Disposable
,
IDisposable
,
combinedDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
URI
,
UriComponents
}
from
'
vs/base/common/uri
'
;
import
{
INotebookService
,
IMainNotebookController
}
from
'
vs/workbench/contrib/notebook/common/notebookService
'
;
...
...
@@ -20,7 +19,7 @@ import { IAccessibilityService } from 'vs/platform/accessibility/common/accessib
import
{
IRelativePattern
}
from
'
vs/base/common/glob
'
;
import
{
ExtensionIdentifier
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IUndoRedoService
,
UndoRedoElementType
}
from
'
vs/platform/undoRedo/common/undoRedo
'
;
import
{
IUndoRedoService
}
from
'
vs/platform/undoRedo/common/undoRedo
'
;
import
{
ITextModelService
}
from
'
vs/editor/common/services/resolverService
'
;
import
{
Emitter
}
from
'
vs/base/common/event
'
;
...
...
@@ -69,26 +68,6 @@ export class MainThreadNotebookDocument extends Disposable {
}
}
async
spliceNotebookCellOutputs
(
cellHandle
:
number
,
splices
:
NotebookCellOutputsSplice
[])
{
await
this
.
notebookService
.
transformSpliceOutputs
(
this
.
textModel
,
splices
);
this
.
_textModel
.
$spliceNotebookCellOutputs
(
cellHandle
,
splices
);
}
handleEdit
(
editId
:
number
,
label
:
string
|
undefined
):
void
{
this
.
undoRedoService
.
pushElement
({
type
:
UndoRedoElementType
.
Resource
,
resource
:
this
.
_textModel
.
uri
,
label
:
label
??
nls
.
localize
(
'
defaultEditLabel
'
,
"
Edit
"
),
undo
:
async
()
=>
{
await
this
.
_proxy
.
$undoNotebook
(
this
.
_textModel
.
viewType
,
this
.
_textModel
.
uri
,
editId
,
this
.
_textModel
.
isDirty
);
},
redo
:
async
()
=>
{
await
this
.
_proxy
.
$redoNotebook
(
this
.
_textModel
.
viewType
,
this
.
_textModel
.
uri
,
editId
,
this
.
_textModel
.
isDirty
);
},
});
this
.
_textModel
.
setDirty
(
true
);
}
dispose
()
{
this
.
_textModel
.
dispose
();
super
.
dispose
();
...
...
@@ -337,10 +316,6 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
this
.
_updateState
(
notebookEditor
);
}
async
addNotebookDocument
(
data
:
INotebookModelAddedData
)
{
this
.
_updateState
();
}
private
_addNotebookEditor
(
e
:
IEditor
)
{
this
.
_toDisposeOnEditorRemove
.
set
(
e
.
getId
(),
combinedDisposable
(
e
.
onDidChangeModel
(()
=>
this
.
_updateState
()),
...
...
@@ -591,10 +566,19 @@ export class MainThreadNotebookController implements IMainNotebookController {
mainthreadNotebook
.
textModel
.
languages
=
data
.
languages
;
mainthreadNotebook
.
textModel
.
metadata
=
data
.
metadata
;
await
mainthreadNotebook
.
applyEdit
(
mainthreadNotebook
.
textModel
.
versionId
,
[
const
edits
:
ICellEditOperation
[]
=
[
{
editType
:
CellEditType
.
Delete
,
count
:
mainthreadNotebook
.
textModel
.
cells
.
length
,
index
:
0
},
{
editType
:
CellEditType
.
Insert
,
index
:
0
,
cells
:
data
.
cells
}
],
false
);
];
await
this
.
notebookService
.
transformEditsOutputs
(
mainthreadNotebook
.
textModel
,
edits
);
await
new
Promise
(
resolve
=>
{
DOM
.
scheduleAtNextAnimationFrame
(()
=>
{
const
ret
=
mainthreadNotebook
!
.
textModel
.
$applyEdit
(
mainthreadNotebook
!
.
textModel
.
versionId
,
edits
,
true
);
resolve
(
ret
);
});
});
}
return
mainthreadNotebook
.
textModel
;
}
...
...
@@ -618,28 +602,6 @@ export class MainThreadNotebookController implements IMainNotebookController {
document
.
textModel
.
insertTemplateCell
(
mainCell
);
}
await
this
.
_mainThreadNotebook
.
addNotebookDocument
({
viewType
:
document
.
viewType
,
handle
:
document
.
handle
,
uri
:
document
.
uri
,
metadata
:
document
.
textModel
.
metadata
,
versionId
:
document
.
textModel
.
versionId
,
cells
:
document
.
textModel
.
cells
.
map
(
cell
=>
({
handle
:
cell
.
handle
,
uri
:
cell
.
uri
,
source
:
cell
.
textBuffer
.
getLinesContent
(),
eol
:
cell
.
textBuffer
.
getEOL
(),
language
:
cell
.
language
,
cellKind
:
cell
.
cellKind
,
outputs
:
cell
.
outputs
,
metadata
:
cell
.
metadata
})),
attachedEditor
:
editorId
?
{
id
:
editorId
,
selections
:
document
.
textModel
.
selections
}
:
undefined
});
this
.
_proxy
.
$acceptEditorPropertiesChanged
(
uri
,
{
selections
:
null
,
metadata
:
document
.
textModel
.
metadata
});
return
document
.
textModel
;
...
...
@@ -653,7 +615,8 @@ export class MainThreadNotebookController implements IMainNotebookController {
let
mainthreadNotebook
=
this
.
_mapping
.
get
(
URI
.
from
(
resource
).
toString
());
if
(
mainthreadNotebook
)
{
return
await
mainthreadNotebook
.
applyEdit
(
modelVersionId
,
edits
,
true
);
await
this
.
notebookService
.
transformEditsOutputs
(
mainthreadNotebook
.
textModel
,
edits
);
return
mainthreadNotebook
.
textModel
.
$applyEdit
(
modelVersionId
,
edits
,
true
);
}
return
false
;
...
...
@@ -661,7 +624,10 @@ export class MainThreadNotebookController implements IMainNotebookController {
async
spliceNotebookCellOutputs
(
resource
:
UriComponents
,
cellHandle
:
number
,
splices
:
NotebookCellOutputsSplice
[],
renderers
:
number
[]):
Promise
<
void
>
{
let
mainthreadNotebook
=
this
.
_mapping
.
get
(
URI
.
from
(
resource
).
toString
());
await
mainthreadNotebook
?.
spliceNotebookCellOutputs
(
cellHandle
,
splices
);
if
(
mainthreadNotebook
)
{
await
this
.
notebookService
.
transformSpliceOutputs
(
mainthreadNotebook
.
textModel
,
splices
);
mainthreadNotebook
.
textModel
.
$spliceNotebookCellOutputs
(
cellHandle
,
splices
);
}
}
async
executeNotebookByAttachedKernel
(
viewType
:
string
,
uri
:
URI
,
token
:
CancellationToken
):
Promise
<
void
>
{
...
...
@@ -694,7 +660,13 @@ export class MainThreadNotebookController implements IMainNotebookController {
handleEdit
(
resource
:
UriComponents
,
editId
:
number
,
label
:
string
|
undefined
):
void
{
let
document
=
this
.
_mapping
.
get
(
URI
.
from
(
resource
).
toString
());
document
?.
handleEdit
(
editId
,
label
);
if
(
document
)
{
document
.
textModel
.
$handleEdit
(
label
,
()
=>
{
return
this
.
_proxy
.
$undoNotebook
(
document
!
.
textModel
.
viewType
,
document
!
.
textModel
.
uri
,
editId
,
document
!
.
textModel
.
isDirty
);
},
()
=>
{
return
this
.
_proxy
.
$redoNotebook
(
document
!
.
textModel
.
viewType
,
document
!
.
textModel
.
uri
,
editId
,
document
!
.
textModel
.
isDirty
);
});
}
}
updateLanguages
(
resource
:
UriComponents
,
languages
:
string
[])
{
...
...
src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts
浏览文件 @
27c96b7a
...
...
@@ -3,13 +3,14 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
nls
from
'
vs/nls
'
;
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
Disposable
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
NotebookCellTextModel
}
from
'
vs/workbench/contrib/notebook/common/model/notebookCellTextModel
'
;
import
{
INotebookTextModel
,
NotebookCellOutputsSplice
,
NotebookCellTextModelSplice
,
NotebookDocumentMetadata
,
NotebookCellMetadata
,
ICellEditOperation
,
CellEditType
,
CellUri
,
ICellInsertEdit
,
NotebookCellsChangedEvent
,
CellKind
,
IProcessedOutput
,
notebookDocumentMetadataDefaults
,
diff
,
ICellDeleteEdit
,
NotebookCellsChangeType
,
ICellDto2
,
IMainCellDto
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
ITextSnapshot
}
from
'
vs/editor/common/model
'
;
import
{
IUndoRedoService
}
from
'
vs/platform/undoRedo/common/undoRedo
'
;
import
{
IUndoRedoService
,
UndoRedoElementType
}
from
'
vs/platform/undoRedo/common/undoRedo
'
;
import
{
InsertCellEdit
,
DeleteCellEdit
,
MoveCellEdit
,
SpliceCellsEdit
}
from
'
vs/workbench/contrib/notebook/common/model/cellEdit
'
;
import
{
ITextModelService
}
from
'
vs/editor/common/services/resolverService
'
;
...
...
@@ -264,6 +265,21 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
return
true
;
}
$handleEdit
(
label
:
string
|
undefined
,
undo
:
()
=>
void
,
redo
:
()
=>
void
):
void
{
this
.
_undoService
.
pushElement
({
type
:
UndoRedoElementType
.
Resource
,
resource
:
this
.
uri
,
label
:
label
??
nls
.
localize
(
'
defaultEditLabel
'
,
"
Edit
"
),
undo
:
async
()
=>
{
undo
();
},
redo
:
async
()
=>
{
redo
();
},
});
this
.
setDirty
(
true
);
}
createSnapshot
(
preserveBOM
?:
boolean
):
ITextSnapshot
{
return
new
NotebookTextModelSnapshot
(
this
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录