Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
d1354bb2
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,发现更多精彩内容 >>
提交
d1354bb2
编写于
3月 11, 2020
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adopt CellUri
上级
ae4a4f88
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
42 addition
and
107 deletion
+42
-107
src/vs/workbench/api/common/extHostNotebook.ts
src/vs/workbench/api/common/extHostNotebook.ts
+20
-62
src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts
...rkbench/contrib/notebook/browser/notebook.contribution.ts
+20
-11
src/vs/workbench/contrib/notebook/common/notebookCommon.ts
src/vs/workbench/contrib/notebook/common/notebookCommon.ts
+0
-27
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
+2
-7
未找到文件。
src/vs/workbench/api/common/extHostNotebook.ts
浏览文件 @
d1354bb2
...
...
@@ -12,7 +12,7 @@ import { DisposableStore, Disposable } from 'vs/base/common/lifecycle';
import
{
readonly
}
from
'
vs/base/common/errors
'
;
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
ExtHostDocumentsAndEditors
}
from
'
vs/workbench/api/common/extHostDocumentsAndEditors
'
;
import
{
INotebookDisplayOrder
,
parseCellUri
,
parseCellHandle
,
ITransformedDisplayOutputDto
,
IOrderedMimeType
,
IStreamOutput
,
IErrorOutput
,
mimeTypeSupportedByCore
,
IOutput
,
sortMimeTypes
,
diff
,
generateCellPath
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
INotebookDisplayOrder
,
ITransformedDisplayOutputDto
,
IOrderedMimeType
,
IStreamOutput
,
IErrorOutput
,
mimeTypeSupportedByCore
,
IOutput
,
sortMimeTypes
,
diff
,
CellUri
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
ISplice
}
from
'
vs/base/common/sequence
'
;
export
class
ExtHostCell
implements
vscode
.
NotebookCell
{
...
...
@@ -312,17 +312,15 @@ export class ExtHostNotebookDocument extends Disposable implements vscode.Notebo
return
this
.
cells
.
find
(
cell
=>
cell
.
handle
===
cellHandle
);
}
attachCellTextDocument
(
cellHandle
:
number
,
textDocument
:
vscode
.
TextDocument
)
{
let
cell
=
this
.
cells
.
find
(
cell
=>
cell
.
handle
===
cellHandle
);
attachCellTextDocument
(
textDocument
:
vscode
.
TextDocument
)
{
let
cell
=
this
.
cells
.
find
(
cell
=>
cell
.
uri
.
toString
()
===
textDocument
.
uri
.
toString
());
if
(
cell
)
{
cell
.
attachTextDocument
(
textDocument
);
}
}
detachCellTextDocument
(
cellHandle
:
number
,
textDocument
:
vscode
.
TextDocument
)
{
let
cell
=
this
.
cells
.
find
(
cell
=>
cell
.
handle
===
cellHandle
);
detachCellTextDocument
(
textDocument
:
vscode
.
TextDocument
)
{
let
cell
=
this
.
cells
.
find
(
cell
=>
cell
.
uri
.
toString
()
===
textDocument
.
uri
.
toString
());
if
(
cell
)
{
cell
.
detachTextDocument
(
textDocument
);
}
...
...
@@ -342,44 +340,22 @@ export class ExtHostNotebookEditor extends Disposable implements vscode.Notebook
)
{
super
();
this
.
_register
(
this
.
_documentsAndEditors
.
onDidAddDocuments
(
documents
=>
{
for
(
const
data
of
documents
)
{
let
textDocument
=
data
.
document
;
let
parsedCellUri
=
parseCellUri
(
textDocument
.
uri
);
if
(
!
parsedCellUri
)
{
continue
;
}
let
notebookUri
=
parsedCellUri
.
notebook
;
let
cellFsPath
=
textDocument
.
uri
.
fsPath
;
const
cellHandle
=
parseCellHandle
(
cellFsPath
);
if
(
cellHandle
!==
undefined
)
{
if
(
this
.
document
.
uri
.
fsPath
===
notebookUri
.
fsPath
)
{
document
.
attachCellTextDocument
(
cellHandle
,
textDocument
);
for
(
const
{
document
:
textDocument
}
of
documents
)
{
let
data
=
CellUri
.
parse
(
textDocument
.
uri
);
if
(
data
)
{
if
(
this
.
document
.
uri
.
toString
()
===
data
.
notebook
.
toString
())
{
document
.
attachCellTextDocument
(
textDocument
);
}
}
}
}));
this
.
_register
(
this
.
_documentsAndEditors
.
onDidRemoveDocuments
(
documents
=>
{
for
(
const
data
of
documents
)
{
let
textDocument
=
data
.
document
;
let
parsedCellUri
=
parseCellUri
(
textDocument
.
uri
);
if
(
!
parsedCellUri
)
{
continue
;
}
let
notebookUri
=
parsedCellUri
.
notebook
;
let
cellFsPath
=
textDocument
.
uri
.
fsPath
;
const
cellHandle
=
parseCellHandle
(
cellFsPath
);
if
(
cellHandle
!==
undefined
)
{
if
(
this
.
document
.
uri
.
fsPath
===
notebookUri
.
fsPath
)
{
document
.
detachCellTextDocument
(
cellHandle
,
textDocument
);
for
(
const
{
document
:
textDocument
}
of
documents
)
{
let
data
=
CellUri
.
parse
(
textDocument
.
uri
);
if
(
data
)
{
if
(
this
.
document
.
uri
.
toString
()
===
data
.
notebook
.
toString
())
{
document
.
detachCellTextDocument
(
textDocument
);
}
}
}
...
...
@@ -388,12 +364,7 @@ export class ExtHostNotebookEditor extends Disposable implements vscode.Notebook
createCell
(
content
:
string
,
language
:
string
,
type
:
CellKind
,
outputs
:
vscode
.
CellOutput
[]):
vscode
.
NotebookCell
{
const
handle
=
ExtHostNotebookEditor
.
_cellhandlePool
++
;
const
uri
=
URI
.
from
({
scheme
:
'
vscode-notebook
'
,
authority
:
this
.
document
.
viewType
,
path
:
generateCellPath
(
type
,
handle
),
query
:
this
.
document
.
uri
.
toString
()
});
const
uri
=
CellUri
.
generate
(
this
.
document
.
uri
,
handle
);
const
cell
=
new
ExtHostCell
(
handle
,
uri
,
content
,
type
,
language
,
outputs
);
return
cell
;
}
...
...
@@ -568,27 +539,14 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
document
?.
insertCell
(
index
,
rawCell
!
);
let
allDocuments
=
this
.
_documentsAndEditors
.
allDocuments
();
for
(
let
i
=
0
;
i
<
allDocuments
.
length
;
i
++
)
{
let
textDocument
=
allDocuments
[
i
].
document
;
let
parsedCellUri
=
parseCellUri
(
textDocument
.
uri
);
if
(
!
parsedCellUri
)
{
continue
;
}
let
notebookUri
=
parsedCellUri
.
notebook
;
let
cellFsPath
=
textDocument
.
uri
.
fsPath
;
const
cellHandle
=
parseCellHandle
(
cellFsPath
);
if
(
cellHandle
!==
undefined
)
{
if
(
uri
.
fsPath
===
notebookUri
.
fsPath
&&
Number
(
cellHandle
)
===
rawCell
.
handle
)
{
for
(
let
{
document
:
textDocument
}
of
allDocuments
)
{
let
data
=
CellUri
.
parse
(
textDocument
.
uri
);
if
(
data
)
{
if
(
uri
.
toString
()
===
data
.
notebook
.
toString
()
&&
textDocument
.
uri
.
toString
()
===
rawCell
.
uri
.
toString
())
{
rawCell
.
attachTextDocument
(
textDocument
);
}
}
}
return
{
uri
:
rawCell
.
uri
,
handle
:
rawCell
.
handle
,
...
...
src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts
浏览文件 @
d1354bb2
...
...
@@ -27,9 +27,8 @@ import { IModeService } from 'vs/editor/common/services/modeService';
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
assertType
}
from
'
vs/base/common/types
'
;
import
{
parse
}
from
'
vs/base/common/marshalling
'
;
import
{
parse
CellUri
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
CellUri
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
ResourceMap
}
from
'
vs/base/common/map
'
;
import
{
isFalsyOrEmpty
}
from
'
vs/base/common/arrays
'
;
// Output renderers registration
...
...
@@ -40,6 +39,7 @@ import 'vs/workbench/contrib/notebook/browser/view/output/transforms/richTransfo
// Actions
import
'
vs/workbench/contrib/notebook/browser/contrib/notebookActions
'
;
import
{
basename
}
from
'
vs/base/common/resources
'
;
import
{
NotebookProviderInfo
}
from
'
vs/workbench/contrib/notebook/common/notebookProvider
'
;
Registry
.
as
<
IEditorRegistry
>
(
EditorExtensions
.
Editors
).
registerEditor
(
EditorDescriptor
.
create
(
...
...
@@ -86,6 +86,10 @@ Registry.as<IEditorInputFactoryRegistry>(EditorInputExtensions.EditorInputFactor
}
);
function
getFirstNotebookInfo
(
notebookService
:
INotebookService
,
uri
:
URI
):
NotebookProviderInfo
|
undefined
{
return
notebookService
.
getContributedNotebookProviders
(
uri
)[
0
];
}
export
class
NotebookContribution
implements
IWorkbenchContribution
{
private
_resourceMapping
=
new
ResourceMap
<
NotebookEditorInput
>
();
...
...
@@ -111,18 +115,18 @@ export class NotebookContribution implements IWorkbenchContribution {
return
undefined
;
}
const
data
=
parseCellUri
(
resource
);
if
(
data
)
{
let
info
:
NotebookProviderInfo
|
undefined
;
const
data
=
CellUri
.
parse
(
resource
);
if
(
data
&&
(
info
=
getFirstNotebookInfo
(
this
.
notebookService
,
data
.
notebook
)))
{
// cell-uri -> open (container) notebook
const
name
=
basename
(
data
.
notebook
);
const
input
=
this
.
instantiationService
.
createInstance
(
NotebookEditorInput
,
data
.
notebook
,
name
,
data
.
viewType
);
const
input
=
this
.
instantiationService
.
createInstance
(
NotebookEditorInput
,
data
.
notebook
,
name
,
info
.
id
);
this
.
_resourceMapping
.
set
(
resource
,
input
);
return
{
override
:
this
.
editorService
.
openEditor
(
input
,
new
NotebookEditorOptions
({
...
options
,
forceReload
:
true
,
cellOptions
:
{
resource
,
options
}
}),
group
)
};
}
const
notebookProviders
=
this
.
notebookService
.
getContributedNotebookProviders
(
resource
);
const
viewType
=
!
isFalsyOrEmpty
(
notebookProviders
)
?
notebookProviders
[
0
].
id
:
undefined
;
if
(
viewType
===
undefined
)
{
info
=
getFirstNotebookInfo
(
this
.
notebookService
,
resource
);
if
(
!
info
)
{
return
undefined
;
}
...
...
@@ -134,7 +138,7 @@ export class NotebookContribution implements IWorkbenchContribution {
}
}
const
input
=
this
.
instantiationService
.
createInstance
(
NotebookEditorInput
,
resource
,
originalInput
.
getName
(),
viewType
);
const
input
=
this
.
instantiationService
.
createInstance
(
NotebookEditorInput
,
resource
,
originalInput
.
getName
(),
info
.
id
);
this
.
_resourceMapping
.
set
(
resource
,
input
);
return
{
override
:
this
.
editorService
.
openEditor
(
input
,
options
,
group
)
};
...
...
@@ -163,11 +167,16 @@ class CellContentProvider implements ITextModelContentProvider {
if
(
existing
)
{
return
existing
;
}
const
data
=
parseCellUri
(
resource
);
const
data
=
CellUri
.
parse
(
resource
);
// const data = parseCellUri(resource);
if
(
!
data
)
{
return
null
;
}
const
notebook
=
await
this
.
_notebookService
.
resolveNotebook
(
data
.
viewType
,
data
.
notebook
);
const
info
=
getFirstNotebookInfo
(
this
.
_notebookService
,
data
.
notebook
);
if
(
!
info
)
{
return
null
;
}
const
notebook
=
await
this
.
_notebookService
.
resolveNotebook
(
info
.
id
,
data
.
notebook
);
if
(
!
notebook
)
{
return
null
;
}
...
...
src/vs/workbench/contrib/notebook/common/notebookCommon.ts
浏览文件 @
d1354bb2
...
...
@@ -171,22 +171,6 @@ export type NotebookCellOutputsSplice = [
IOutput
[]
];
export
function
parseCellUri
(
resource
:
URI
):
{
viewType
:
string
,
notebook
:
URI
}
|
undefined
{
//vscode-notebook://<viewType>/cell_<cellHandle>.ext
if
(
resource
.
scheme
!==
'
vscode-notebook
'
)
{
return
undefined
;
}
// @todo Jo,Peng: `authority` will be transformed to lower case in `URI.toString()`, so we won't retrive the same viewType later on.
const
viewType
=
resource
.
authority
;
const
notebook
=
URI
.
parse
(
resource
.
query
);
return
{
viewType
,
notebook
};
}
export
function
generateCellPath
(
cellKind
:
CellKind
,
cellHandle
:
number
):
string
{
return
`/cell_
${
cellHandle
}${
cellKind
===
CellKind
.
Markdown
?
'
.md
'
:
''
}
`
;
}
export
namespace
CellUri
{
export
const
scheme
=
'
vscode-notebook
'
;
...
...
@@ -214,17 +198,6 @@ export namespace CellUri {
}
}
export
function
parseCellHandle
(
path
:
string
):
number
|
undefined
{
const
regex
=
new
RegExp
(
/cell_
(\d
*
)(\.)?
/g
);
let
matches
=
regex
.
exec
(
path
);
if
(
matches
&&
matches
.
length
>
1
)
{
return
Number
(
matches
[
1
]);
}
return
;
}
export
function
mimeTypeSupportedByCore
(
mimeType
:
string
)
{
if
([
'
application/json
'
,
...
...
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
浏览文件 @
d1354bb2
...
...
@@ -7,7 +7,7 @@ import { Emitter, Event } from 'vs/base/common/event';
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
PieceTreeTextBufferFactory
}
from
'
vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBufferBuilder
'
;
import
{
CellKind
,
generateCellPath
,
ICell
,
INotebook
,
IOutput
,
NotebookCellOutputsSplice
,
NotebookCellsSplice
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
CellKind
,
ICell
,
INotebook
,
IOutput
,
NotebookCellOutputsSplice
,
NotebookCellsSplice
,
CellUri
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
NotebookViewModel
,
IModelDecorationsChangeAccessor
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
CellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel
'
;
...
...
@@ -45,12 +45,7 @@ export class TestCell implements ICell {
outputs
:
IOutput
[]
)
{
this
.
_outputs
=
outputs
;
this
.
uri
=
URI
.
from
({
scheme
:
'
vscode-notebook
'
,
authority
:
viewType
,
path
:
generateCellPath
(
cellKind
,
handle
),
query
:
''
});
this
.
uri
=
CellUri
.
generate
(
URI
.
parse
(
'
test:///fake/notebook
'
),
handle
);
}
resolveTextBufferFactory
():
PieceTreeTextBufferFactory
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录