Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
b297be52
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,发现更多精彩内容 >>
提交
b297be52
编写于
9月 25, 2020
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new proposal for NotebookCellOutput, partial implementation
上级
ea78dd7b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
76 addition
and
5 deletion
+76
-5
extensions/vscode-notebook-tests/src/notebook.test.ts
extensions/vscode-notebook-tests/src/notebook.test.ts
+31
-0
src/vs/vscode.proposed.d.ts
src/vs/vscode.proposed.d.ts
+10
-1
src/vs/workbench/api/common/extHost.api.impl.ts
src/vs/workbench/api/common/extHost.api.impl.ts
+2
-1
src/vs/workbench/api/common/extHostNotebookEditor.ts
src/vs/workbench/api/common/extHostNotebookEditor.ts
+9
-2
src/vs/workbench/api/common/extHostTypeConverters.ts
src/vs/workbench/api/common/extHostTypeConverters.ts
+11
-1
src/vs/workbench/api/common/extHostTypes.ts
src/vs/workbench/api/common/extHostTypes.ts
+13
-0
未找到文件。
extensions/vscode-notebook-tests/src/notebook.test.ts
浏览文件 @
b297be52
...
...
@@ -417,6 +417,37 @@ suite('Notebook API tests', () => {
await
saveAllFilesAndCloseAll
(
resource
);
});
test
(
'
edit API (replaceOutput, USE NotebookCellOutput-type)
'
,
async
function
()
{
assertInitalState
();
const
resource
=
await
createRandomFile
(
''
,
undefined
,
'
first
'
,
'
.vsctestnb
'
);
await
vscode
.
commands
.
executeCommand
(
'
vscode.openWith
'
,
resource
,
'
notebookCoreTest
'
);
await
vscode
.
notebook
.
activeNotebookEditor
!
.
edit
(
editBuilder
=>
{
editBuilder
.
replaceCellOutput
(
0
,
[
new
vscode
.
NotebookCellOutput
(
'
application/foo
'
,
'
bar
'
),
new
vscode
.
NotebookCellOutput
(
'
application/json
'
,
{
data
:
true
},
{
metadata
:
true
}),
]);
});
const
document
=
vscode
.
notebook
.
activeNotebookEditor
?.
document
!
;
assert
.
strictEqual
(
document
.
isDirty
,
true
);
assert
.
strictEqual
(
document
.
cells
.
length
,
1
);
assert
.
strictEqual
(
document
.
cells
[
0
].
outputs
.
length
,
2
);
// consuming is OLD api
const
[
one
,
two
]
=
document
.
cells
[
0
].
outputs
;
assert
.
strictEqual
(
one
.
outputKind
,
vscode
.
CellOutputKind
.
Rich
);
assert
.
strictEqual
((
<
vscode
.
CellDisplayOutput
>
one
).
data
[
'
application/foo
'
],
'
bar
'
);
assert
.
strictEqual
((
<
vscode
.
CellDisplayOutput
>
one
).
metadata
,
undefined
);
assert
.
strictEqual
(
two
.
outputKind
,
vscode
.
CellOutputKind
.
Rich
);
assert
.
deepStrictEqual
((
<
vscode
.
CellDisplayOutput
>
two
).
data
[
'
application/json
'
],
{
data
:
true
});
assert
.
deepStrictEqual
((
<
vscode
.
CellDisplayOutput
>
two
).
metadata
,
{
custom
:
{
metadata
:
true
}
});
await
saveAllFilesAndCloseAll
(
undefined
);
});
test
(
'
edit API (replaceOutput)
'
,
async
function
()
{
assertInitalState
();
const
resource
=
await
createRandomFile
(
''
,
undefined
,
'
first
'
,
'
.vsctestnb
'
);
...
...
src/vs/vscode.proposed.d.ts
浏览文件 @
b297be52
...
...
@@ -1237,6 +1237,15 @@ declare module 'vscode' {
export
type
CellOutput
=
CellStreamOutput
|
CellErrorOutput
|
CellDisplayOutput
;
export
class
NotebookCellOutput
{
readonly
mime
:
string
;
readonly
value
:
unknown
;
readonly
metadata
?:
Record
<
string
,
string
|
number
|
boolean
>
;
constructor
(
mime
:
string
,
value
:
unknown
,
metadata
?:
Record
<
string
,
string
|
number
|
boolean
>
);
}
export
enum
NotebookCellRunState
{
Running
=
1
,
Idle
=
2
,
...
...
@@ -1425,7 +1434,7 @@ declare module 'vscode' {
export
interface
NotebookEditorEdit
{
replaceMetadata
(
value
:
NotebookDocumentMetadata
):
void
;
replaceCells
(
start
:
number
,
end
:
number
,
cells
:
NotebookCellData
[]):
void
;
replaceCellOutput
(
index
:
number
,
outputs
:
CellOutput
[]):
void
;
replaceCellOutput
(
index
:
number
,
outputs
:
(
NotebookCellOutput
|
CellOutput
)
[]):
void
;
replaceCellMetadata
(
index
:
number
,
metadata
:
NotebookCellMetadata
):
void
;
}
...
...
src/vs/workbench/api/common/extHost.api.impl.ts
浏览文件 @
b297be52
...
...
@@ -1147,7 +1147,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
NotebookCellRunState
:
extHostTypes
.
NotebookCellRunState
,
NotebookRunState
:
extHostTypes
.
NotebookRunState
,
NotebookCellStatusBarAlignment
:
extHostTypes
.
NotebookCellStatusBarAlignment
,
NotebookEditorRevealType
:
extHostTypes
.
NotebookEditorRevealType
NotebookEditorRevealType
:
extHostTypes
.
NotebookEditorRevealType
,
NotebookCellOutput
:
extHostTypes
.
NotebookCellOutput
,
};
};
}
...
...
src/vs/workbench/api/common/extHostNotebookEditor.ts
浏览文件 @
b297be52
...
...
@@ -7,6 +7,7 @@ import { readonly } from 'vs/base/common/errors';
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
MainThreadNotebookShape
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
NotebookCellOutput
}
from
'
vs/workbench/api/common/extHostTypeConverters
'
;
import
*
as
extHostTypes
from
'
vs/workbench/api/common/extHostTypes
'
;
import
{
addIdToOutput
,
CellEditType
,
ICellEditOperation
,
ICellReplaceEdit
,
INotebookEditData
,
notebookDocumentMetadataDefaults
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
*
as
vscode
from
'
vscode
'
;
...
...
@@ -54,12 +55,18 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit {
});
}
replaceCellOutput
(
index
:
number
,
outputs
:
vscode
.
CellOutput
[]):
void
{
replaceCellOutput
(
index
:
number
,
outputs
:
(
vscode
.
NotebookCellOutput
|
vscode
.
CellOutput
)
[]):
void
{
this
.
_throwIfFinalized
();
this
.
_collectedEdits
.
push
({
editType
:
CellEditType
.
Output
,
index
,
outputs
:
outputs
.
map
(
output
=>
addIdToOutput
(
output
))
outputs
:
outputs
.
map
(
output
=>
{
if
(
extHostTypes
.
NotebookCellOutput
.
isNotebookCellOutput
(
output
))
{
return
addIdToOutput
(
NotebookCellOutput
.
from
(
output
));
}
else
{
return
addIdToOutput
(
output
);
}
})
});
}
...
...
src/vs/workbench/api/common/extHostTypeConverters.ts
浏览文件 @
b297be52
...
...
@@ -32,7 +32,7 @@ import { coalesce, isNonEmptyArray } from 'vs/base/common/arrays';
import
{
RenderLineNumbersType
}
from
'
vs/editor/common/config/editorOptions
'
;
import
{
CommandsConverter
}
from
'
vs/workbench/api/common/extHostCommands
'
;
import
{
ExtHostNotebookController
}
from
'
vs/workbench/api/common/extHostNotebook
'
;
import
{
INotebookDecorationRenderOptions
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
CellOutputKind
,
IDisplayOutput
,
INotebookDecorationRenderOptions
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
export
interface
PositionLike
{
line
:
number
;
...
...
@@ -1295,6 +1295,16 @@ export namespace LogLevel {
}
}
export
namespace
NotebookCellOutput
{
export
function
from
(
output
:
types
.
NotebookCellOutput
):
IDisplayOutput
{
return
{
outputKind
:
CellOutputKind
.
Rich
,
data
:
{
[
output
.
mime
]:
output
.
value
},
metadata
:
output
.
metadata
&&
{
custom
:
output
.
metadata
}
};
}
}
export
namespace
NotebookExclusiveDocumentPattern
{
export
function
from
(
pattern
:
{
include
:
vscode
.
GlobPattern
|
undefined
,
exclude
:
vscode
.
GlobPattern
|
undefined
}):
{
include
:
string
|
types
.
RelativePattern
|
undefined
,
exclude
:
string
|
types
.
RelativePattern
|
undefined
};
export
function
from
(
pattern
:
vscode
.
GlobPattern
):
string
|
types
.
RelativePattern
;
...
...
src/vs/workbench/api/common/extHostTypes.ts
浏览文件 @
b297be52
...
...
@@ -2765,6 +2765,19 @@ export enum ColorThemeKind {
//#region Notebook
export
class
NotebookCellOutput
{
static
isNotebookCellOutput
(
obj
:
unknown
):
obj
is
vscode
.
NotebookCellOutput
{
return
obj
instanceof
NotebookCellOutput
;
}
constructor
(
readonly
mime
:
string
,
readonly
value
:
unknown
,
// JSON'able
readonly
metadata
?:
Record
<
string
,
string
|
number
|
boolean
>
)
{
}
}
export
enum
CellKind
{
Markdown
=
1
,
Code
=
2
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录