Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
77b395f1
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,发现更多精彩内容 >>
提交
77b395f1
编写于
1月 22, 2020
作者:
R
rebornix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update notebook test extension for new API.
上级
55d21402
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
109 addition
and
127 deletion
+109
-127
extensions/notebook-test/src/notebookProvider.ts
extensions/notebook-test/src/notebookProvider.ts
+106
-126
src/vs/workbench/api/common/extHostNotebook.ts
src/vs/workbench/api/common/extHostNotebook.ts
+3
-1
未找到文件。
extensions/notebook-test/src/notebookProvider.ts
浏览文件 @
77b395f1
...
...
@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import
*
as
vscode
from
'
vscode
'
;
import
*
as
path
from
'
path
'
;
export
class
Cell
{
public
outputs
:
vscode
.
CellOutput
[]
=
[];
...
...
@@ -47,17 +48,49 @@ export class Cell {
export
class
JupyterNotebook
{
public
mapping
:
Map
<
number
,
any
>
=
new
Map
();
private
preloadScript
=
false
;
constructor
(
private
_extensionPath
:
string
,
public
document
:
vscode
.
NotebookDocument
,
editor
:
vscode
.
NotebookEditor
,
notebookJSON
:
any
notebookJSON
:
any
,
private
fillOutputs
:
boolean
)
{
let
cells
=
notebookJSON
.
cells
.
map
(((
raw_cell
:
any
)
=>
{
let
outputs
=
[];
if
(
fillOutputs
)
{
outputs
=
raw_cell
.
outputs
;
}
if
(
!
this
.
preloadScript
)
{
let
containHTML
=
this
.
containHTML
(
raw_cell
);
if
(
containHTML
)
{
this
.
preloadScript
=
true
;
const
scriptPathOnDisk
=
vscode
.
Uri
.
file
(
path
.
join
(
this
.
_extensionPath
,
'
dist
'
,
'
ipywidgets.js
'
)
);
let
scriptUri
=
scriptPathOnDisk
.
with
({
scheme
:
'
vscode-resource
'
});
outputs
.
unshift
(
{
'
output_type
'
:
'
display_data
'
,
'
data
'
:
{
'
text/html
'
:
[
`<script src="
${
scriptUri
}
"></script>\n`
,
]
}
}
);
}
}
let
managedCell
=
editor
.
createCell
(
raw_cell
.
source
?
raw_cell
.
source
.
join
(
''
)
:
''
,
notebookJSON
.
metadata
.
language_info
.
name
,
raw_cell
.
cell_type
,
[]
outputs
);
this
.
mapping
.
set
(
managedCell
.
handle
,
raw_cell
);
...
...
@@ -67,13 +100,79 @@ export class JupyterNotebook {
editor
.
document
.
cells
=
cells
;
}
execute
(
cell
:
vscode
.
NotebookCell
|
undefined
)
{
execute
(
document
:
vscode
.
NotebookDocument
,
cell
:
vscode
.
NotebookCell
|
undefined
)
{
if
(
cell
)
{
let
rawCell
=
this
.
mapping
.
get
(
cell
.
handle
);
if
(
!
this
.
preloadScript
)
{
let
containHTML
=
this
.
containHTML
(
rawCell
);
if
(
containHTML
)
{
this
.
preloadScript
=
true
;
const
scriptPathOnDisk
=
vscode
.
Uri
.
file
(
path
.
join
(
this
.
_extensionPath
,
'
dist
'
,
'
ipywidgets.js
'
)
);
let
scriptUri
=
scriptPathOnDisk
.
with
({
scheme
:
'
vscode-resource
'
});
rawCell
.
outputs
.
unshift
(
{
'
output_type
'
:
'
display_data
'
,
'
data
'
:
{
'
text/html
'
:
[
`<script src="
${
scriptUri
}
"></script>\n`
,
]
}
}
);
}
}
cell
.
outputs
=
rawCell
.
outputs
;
}
else
{
if
(
!
this
.
fillOutputs
)
{
for
(
let
i
=
0
;
i
<
document
.
cells
.
length
;
i
++
)
{
let
cell
=
document
.
cells
[
i
];
let
rawCell
=
this
.
mapping
.
get
(
cell
.
handle
);
if
(
!
this
.
preloadScript
)
{
let
containHTML
=
this
.
containHTML
(
rawCell
);
if
(
containHTML
)
{
this
.
preloadScript
=
true
;
const
scriptPathOnDisk
=
vscode
.
Uri
.
file
(
path
.
join
(
this
.
_extensionPath
,
'
dist
'
,
'
ipywidgets.js
'
)
);
let
scriptUri
=
scriptPathOnDisk
.
with
({
scheme
:
'
vscode-resource
'
});
rawCell
.
outputs
.
unshift
(
{
'
output_type
'
:
'
display_data
'
,
'
data
'
:
{
'
text/html
'
:
[
`<script src="
${
scriptUri
}
"></script>\n`
,
]
}
}
);
}
}
cell
.
outputs
=
rawCell
.
outputs
;
}
this
.
fillOutputs
=
true
;
}
}
}
containHTML
(
rawCell
:
any
)
{
return
rawCell
.
outputs
&&
rawCell
.
outputs
.
some
((
output
:
any
)
=>
{
if
(
output
.
output_type
===
'
display_data
'
&&
output
.
data
[
'
text/html
'
])
{
return
true
;
}
return
false
;
});
}
}
export
class
NotebookProvider
implements
vscode
.
NotebookProvider
{
...
...
@@ -88,7 +187,7 @@ export class NotebookProvider implements vscode.NotebookProvider {
try
{
let
content
=
await
vscode
.
workspace
.
fs
.
readFile
(
editor
.
document
.
uri
);
let
jupyterNotebook
=
new
JupyterNotebook
(
editor
.
document
,
editor
,
JSON
.
parse
(
content
.
toString
())
);
let
jupyterNotebook
=
new
JupyterNotebook
(
this
.
_extensionPath
,
editor
.
document
,
editor
,
JSON
.
parse
(
content
.
toString
()),
this
.
fillOutputs
);
this
.
_notebooks
.
set
(
editor
.
document
.
uri
.
toString
(),
jupyterNotebook
);
}
catch
{
...
...
@@ -99,130 +198,11 @@ export class NotebookProvider implements vscode.NotebookProvider {
let
jupyterNotebook
=
this
.
_notebooks
.
get
(
document
.
uri
.
toString
());
if
(
jupyterNotebook
)
{
jupyterNotebook
.
execute
(
cell
);
jupyterNotebook
.
execute
(
document
,
cell
);
}
}
// async resolveNotebook2(resource: vscode.Uri): Promise<vscode.NotebookDocument | undefined> {
// if (this._notebooks.has(resource.fsPath)) {
// let notebook = this._notebooks.get(resource.fsPath);
// if (!this.fillOutputs) {
// notebook?.cells.forEach(cell => {
// cell.clearOutputs();
// });
// }
// return notebook;
// }
// let content = await vscode.workspace.fs.readFile(resource);
// try {
// let notebookJSON = JSON.parse(content.toString());
// let notebook = new JupyterNotebook(
// notebookJSON.metadata,
// notebookJSON.cells.map((rawCell: any) => {
// return new Cell(
// rawCell.source,
// rawCell.cell_type,
// rawCell.outputs
// );
// })
// );
// if (this.fillOutputs) {
// let preloadScript = false;
// notebook!.cells.forEach(cell => {
// if (cell.outputsFullFilled()) {
// return;
// }
// if (!preloadScript) {
// let containHTML = cell.containHTML();
// if (containHTML) {
// preloadScript = true;
// const scriptPathOnDisk = vscode.Uri.file(
// path.join(this._extensionPath, 'dist', 'ipywidgets.js')
// );
// let scriptUri = scriptPathOnDisk.with({ scheme: 'vscode-resource' });
// cell.insertDependencies(
// {
// 'output_type': 'display_data',
// 'data': {
// 'text/html': [
// `<script src="${scriptUri}"></script>\n`,
// ]
// }
// }
// );
// cell.fillInOutputs();
// } else {
// cell.fillInOutputs();
// }
// } else {
// cell.fillInOutputs();
// }
// });
// }
// this._notebooks.set(resource.fsPath, notebook);
// return Promise.resolve(notebook);
// } catch {
// return Promise.resolve(undefined);
// }
// }
async
executeNotebook
(
resource
:
vscode
.
Uri
):
Promise
<
void
>
{
if
(
this
.
fillOutputs
)
{
return
;
}
// if (this._notebooks.has(resource.fsPath)) {
// let notebook = this._notebooks.get(resource.fsPath);
// let preloadScript = false;
// notebook!.cells.forEach(cell => {
// if (cell.outputsFullFilled()) {
// return;
// }
// if (!preloadScript) {
// let containHTML = cell.containHTML();
// if (containHTML) {
// preloadScript = true;
// const scriptPathOnDisk = vscode.Uri.file(
// path.join(this._extensionPath, 'dist', 'ipywidgets.js')
// );
// let scriptUri = scriptPathOnDisk.with({ scheme: 'vscode-resource' });
// cell.insertDependencies(
// {
// 'output_type': 'display_data',
// 'data': {
// 'text/html': [
// `<script src="${scriptUri}"></script>\n`,
// ]
// }
// }
// );
// cell.fillInOutputs();
// } else {
// cell.fillInOutputs();
// }
// } else {
// cell.fillInOutputs();
// }
// });
// this._onDidChangeNotebook.fire({ resource, notebook: notebook! });
// }
return
;
async
save
(
document
:
vscode
.
NotebookDocument
):
Promise
<
boolean
>
{
return
true
;
}
}
\ No newline at end of file
src/vs/workbench/api/common/extHostNotebook.ts
浏览文件 @
77b395f1
...
...
@@ -302,7 +302,9 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
let
provider
=
this
.
_notebookProviders
.
get
(
viewType
);
if
(
provider
)
{
// return provider.provider.executeNotebook(uri);
let
document
=
this
.
_documents
.
get
(
URI
.
revive
(
uri
).
toString
());
return
provider
.
provider
.
executeCell
(
document
!
,
undefined
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录