Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
02f0509f
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,发现更多精彩内容 >>
未验证
提交
02f0509f
编写于
9月 28, 2020
作者:
J
Johannes Rieken
提交者:
GitHub
9月 28, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #107426 from microsoft/joh/cell-output
proposal for NotebookCellOutput
上级
71ca6f50
4482c879
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
136 addition
and
9 deletion
+136
-9
extensions/vscode-notebook-tests/src/notebook.test.ts
extensions/vscode-notebook-tests/src/notebook.test.ts
+28
-0
src/vs/vscode.proposed.d.ts
src/vs/vscode.proposed.d.ts
+23
-2
src/vs/workbench/api/common/extHost.api.impl.ts
src/vs/workbench/api/common/extHost.api.impl.ts
+3
-1
src/vs/workbench/api/common/extHostNotebookEditor.ts
src/vs/workbench/api/common/extHostNotebookEditor.ts
+8
-2
src/vs/workbench/api/common/extHostTypeConverters.ts
src/vs/workbench/api/common/extHostTypeConverters.ts
+17
-1
src/vs/workbench/api/common/extHostTypes.ts
src/vs/workbench/api/common/extHostTypes.ts
+57
-3
未找到文件。
extensions/vscode-notebook-tests/src/notebook.test.ts
浏览文件 @
02f0509f
...
...
@@ -417,6 +417,34 @@ 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
([
new
vscode
.
NotebookCellOutputItem
(
'
application/foo
'
,
'
bar
'
),
new
vscode
.
NotebookCellOutputItem
(
'
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
,
1
);
// consuming is OLD api (for now)
const
[
output
]
=
document
.
cells
[
0
].
outputs
;
assert
.
strictEqual
(
output
.
outputKind
,
vscode
.
CellOutputKind
.
Rich
);
assert
.
strictEqual
((
<
vscode
.
CellDisplayOutput
>
output
).
data
[
'
application/foo
'
],
'
bar
'
);
assert
.
deepStrictEqual
((
<
vscode
.
CellDisplayOutput
>
output
).
data
[
'
application/json
'
],
{
data
:
true
});
assert
.
deepStrictEqual
((
<
vscode
.
CellDisplayOutput
>
output
).
metadata
,
{
custom
:
{
'
application/json
'
:
{
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
浏览文件 @
02f0509f
...
...
@@ -1226,6 +1226,27 @@ declare module 'vscode' {
export
type
CellOutput
=
CellStreamOutput
|
CellErrorOutput
|
CellDisplayOutput
;
export
class
NotebookCellOutputItem
{
readonly
mime
:
string
;
readonly
value
:
unknown
;
readonly
metadata
?:
Record
<
string
,
string
|
number
|
boolean
>
;
constructor
(
mime
:
string
,
value
:
unknown
,
metadata
?:
Record
<
string
,
string
|
number
|
boolean
>
);
}
//TODO@jrieken add id?
export
class
NotebookCellOutput
{
readonly
outputs
:
NotebookCellOutputItem
[];
readonly
metadata
?:
Record
<
string
,
string
|
number
|
boolean
>
;
constructor
(
outputs
:
NotebookCellOutputItem
[],
metadata
?:
Record
<
string
,
string
|
number
|
boolean
>
);
//TODO@jrieken HACK to workaround dependency issues...
toJSON
():
any
;
}
export
enum
NotebookCellRunState
{
Running
=
1
,
Idle
=
2
,
...
...
@@ -1407,14 +1428,14 @@ declare module 'vscode' {
export
interface
WorkspaceEdit
{
replaceNotebookMetadata
(
uri
:
Uri
,
value
:
NotebookDocumentMetadata
):
void
;
replaceNotebookCells
(
uri
:
Uri
,
start
:
number
,
end
:
number
,
cells
:
NotebookCellData
[],
metadata
?:
WorkspaceEditEntryMetadata
):
void
;
replaceNotebookCellOutput
(
uri
:
Uri
,
index
:
number
,
outputs
:
CellOutput
[],
metadata
?:
WorkspaceEditEntryMetadata
):
void
;
replaceNotebookCellOutput
(
uri
:
Uri
,
index
:
number
,
outputs
:
(
NotebookCellOutput
|
CellOutput
)
[],
metadata
?:
WorkspaceEditEntryMetadata
):
void
;
replaceNotebookCellMetadata
(
uri
:
Uri
,
index
:
number
,
cellMetadata
:
NotebookCellMetadata
,
metadata
?:
WorkspaceEditEntryMetadata
):
void
;
}
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
浏览文件 @
02f0509f
...
...
@@ -1147,7 +1147,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
NotebookCellRunState
:
extHostTypes
.
NotebookCellRunState
,
NotebookRunState
:
extHostTypes
.
NotebookRunState
,
NotebookCellStatusBarAlignment
:
extHostTypes
.
NotebookCellStatusBarAlignment
,
NotebookEditorRevealType
:
extHostTypes
.
NotebookEditorRevealType
NotebookEditorRevealType
:
extHostTypes
.
NotebookEditorRevealType
,
NotebookCellOutput
:
extHostTypes
.
NotebookCellOutput
,
NotebookCellOutputItem
:
extHostTypes
.
NotebookCellOutputItem
,
};
};
}
...
...
src/vs/workbench/api/common/extHostNotebookEditor.ts
浏览文件 @
02f0509f
...
...
@@ -54,12 +54,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
(
output
.
toJSON
());
}
else
{
return
addIdToOutput
(
output
);
}
})
});
}
...
...
src/vs/workbench/api/common/extHostTypeConverters.ts
浏览文件 @
02f0509f
...
...
@@ -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
;
...
...
@@ -1297,6 +1297,22 @@ export namespace LogLevel {
}
}
export
namespace
NotebookCellOutput
{
export
function
from
(
output
:
types
.
NotebookCellOutput
):
IDisplayOutput
{
return
output
.
toJSON
();
}
}
export
namespace
NotebookCellOutputItem
{
export
function
from
(
output
:
types
.
NotebookCellOutputItem
):
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
浏览文件 @
02f0509f
...
...
@@ -14,7 +14,7 @@ import { URI } from 'vs/base/common/uri';
import
{
generateUuid
}
from
'
vs/base/common/uuid
'
;
import
{
FileSystemProviderErrorCode
,
markAsFileSystemProviderError
}
from
'
vs/platform/files/common/files
'
;
import
{
RemoteAuthorityResolverErrorCode
}
from
'
vs/platform/remote/common/remoteAuthorityResolver
'
;
import
{
addIdToOutput
,
CellEditType
,
ICellEditOperation
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
addIdToOutput
,
CellEditType
,
ICellEditOperation
,
IDisplayOutput
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
type
*
as
vscode
from
'
vscode
'
;
function
es5ClassCompat
(
target
:
Function
):
any
{
...
...
@@ -641,8 +641,18 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit {
}
}
replaceNotebookCellOutput
(
uri
:
URI
,
index
:
number
,
outputs
:
vscode
.
CellOutput
[],
metadata
?:
vscode
.
WorkspaceEditEntryMetadata
):
void
{
this
.
_edits
.
push
({
_type
:
FileEditType
.
Cell
,
metadata
,
uri
,
edit
:
{
editType
:
CellEditType
.
Output
,
index
,
outputs
:
outputs
.
map
(
output
=>
addIdToOutput
(
output
))
}
});
replaceNotebookCellOutput
(
uri
:
URI
,
index
:
number
,
outputs
:
(
vscode
.
NotebookCellOutput
|
vscode
.
CellOutput
)[],
metadata
?:
vscode
.
WorkspaceEditEntryMetadata
):
void
{
this
.
_edits
.
push
({
_type
:
FileEditType
.
Cell
,
metadata
,
uri
,
edit
:
{
editType
:
CellEditType
.
Output
,
index
,
outputs
:
outputs
.
map
(
output
=>
{
if
(
NotebookCellOutput
.
isNotebookCellOutput
(
output
))
{
return
addIdToOutput
(
output
.
toJSON
());
}
else
{
return
addIdToOutput
(
output
);
}
})
}
});
}
replaceNotebookCellMetadata
(
uri
:
URI
,
index
:
number
,
cellMetadata
:
vscode
.
NotebookCellMetadata
,
metadata
?:
vscode
.
WorkspaceEditEntryMetadata
):
void
{
...
...
@@ -2772,6 +2782,50 @@ export enum ColorThemeKind {
//#region Notebook
export
class
NotebookCellOutputItem
{
static
isNotebookCellOutputItem
(
obj
:
unknown
):
obj
is
vscode
.
NotebookCellOutputItem
{
return
obj
instanceof
NotebookCellOutputItem
;
}
constructor
(
readonly
mime
:
string
,
readonly
value
:
unknown
,
// JSON'able
readonly
metadata
?:
Record
<
string
,
string
|
number
|
boolean
>
)
{
}
}
export
class
NotebookCellOutput
{
static
isNotebookCellOutput
(
obj
:
unknown
):
obj
is
vscode
.
NotebookCellOutput
{
return
obj
instanceof
NotebookCellOutput
;
}
constructor
(
readonly
outputs
:
NotebookCellOutputItem
[],
readonly
metadata
?:
Record
<
string
,
string
|
number
|
boolean
>
)
{
}
toJSON
():
IDisplayOutput
{
let
data
:
{
[
key
:
string
]:
unknown
;
}
=
{};
let
custom
:
{
[
key
:
string
]:
unknown
;
}
=
{};
let
hasMetadata
=
false
;
for
(
let
item
of
this
.
outputs
)
{
data
[
item
.
mime
]
=
item
.
value
;
if
(
item
.
metadata
)
{
custom
[
item
.
mime
]
=
item
.
metadata
;
hasMetadata
=
true
;
}
}
return
{
outputKind
:
CellOutputKind
.
Rich
,
data
,
metadata
:
hasMetadata
?
{
custom
}
:
undefined
};
}
}
export
enum
CellKind
{
Markdown
=
1
,
Code
=
2
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录