Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
c185f7ab
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,发现更多精彩内容 >>
提交
c185f7ab
编写于
9月 21, 2020
作者:
R
rebornix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
command for fetching all notebook content providers.
上级
4a45c746
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
148 addition
and
32 deletion
+148
-32
src/vs/workbench/api/common/extHostApiCommands.ts
src/vs/workbench/api/common/extHostApiCommands.ts
+29
-0
src/vs/workbench/api/common/extHostTypeConverters.ts
src/vs/workbench/api/common/extHostTypeConverters.ts
+18
-0
src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts
...workbench/contrib/notebook/browser/contrib/coreActions.ts
+40
-2
src/vs/workbench/contrib/notebook/browser/extensionPoint.ts
src/vs/workbench/contrib/notebook/browser/extensionPoint.ts
+1
-2
src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts
...workbench/contrib/notebook/browser/notebookServiceImpl.ts
+15
-5
src/vs/workbench/contrib/notebook/common/notebookProvider.ts
src/vs/workbench/contrib/notebook/common/notebookProvider.ts
+44
-22
src/vs/workbench/contrib/notebook/common/notebookService.ts
src/vs/workbench/contrib/notebook/common/notebookService.ts
+1
-1
未找到文件。
src/vs/workbench/api/common/extHostApiCommands.ts
浏览文件 @
c185f7ab
...
...
@@ -19,6 +19,7 @@ import { EditorGroupLayout } from 'vs/workbench/services/editor/common/editorGro
import
{
isFalsyOrEmpty
}
from
'
vs/base/common/arrays
'
;
import
{
IRange
}
from
'
vs/editor/common/core/range
'
;
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
TransientMetadata
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
//#region --- NEW world
...
...
@@ -312,6 +313,12 @@ export class ExtHostApiCommands {
returns
:
'
A promise that resolves to an array of ColorPresentation objects.
'
});
this
.
_register
(
'
vscode.resolveNotebookContentProviders
'
,
this
.
_resolveNotebookContentProviders
,
{
description
:
'
Resolve Notebook Content Providers
'
,
args
:
[],
returns
:
'
A promise that resolves to an array of NotebookContentProvider static info objects.
'
});
// -----------------------------------------------------------------
// The following commands are registered on both sides separately.
//
...
...
@@ -480,6 +487,28 @@ export class ExtHostApiCommands {
item
.
command
?
this
.
_commands
.
converter
.
fromInternal
(
item
.
command
)
:
undefined
);
}));
}
private
_resolveNotebookContentProviders
():
Promise
<
{
viewType
:
string
;
displayName
:
string
;
filenamePattern
:
vscode
.
NotebookFilenamePattern
[];
options
:
vscode
.
NotebookDocumentContentOptions
;
}[]
|
undefined
>
{
return
this
.
_commands
.
executeCommand
<
{
viewType
:
string
;
displayName
:
string
;
options
:
{
transientOutputs
:
boolean
;
transientMetadata
:
TransientMetadata
};
filenamePattern
:
(
string
|
types
.
RelativePattern
|
{
include
:
string
|
types
.
RelativePattern
,
exclude
:
string
|
types
.
RelativePattern
})[]
}[]
>
(
'
_resolveNotebookContentProvider
'
)
.
then
(
tryMapWith
(
item
=>
{
return
{
viewType
:
item
.
viewType
,
displayName
:
item
.
displayName
,
options
:
{
transientOutputs
:
item
.
options
.
transientOutputs
,
transientMetadata
:
item
.
options
.
transientMetadata
},
filenamePattern
:
item
.
filenamePattern
.
map
(
pattern
=>
typeConverters
.
NotebookExclusiveDocumentPattern
.
to
(
pattern
))
};
}));
}
}
function
tryMapWith
<
T
,
R
>
(
f
:
(
x
:
T
)
=>
R
)
{
...
...
src/vs/workbench/api/common/extHostTypeConverters.ts
浏览文件 @
c185f7ab
...
...
@@ -1329,6 +1329,24 @@ export namespace NotebookExclusiveDocumentPattern {
}
export
function
to
(
pattern
:
string
|
types
.
RelativePattern
|
{
include
:
string
|
types
.
RelativePattern
,
exclude
:
string
|
types
.
RelativePattern
}):
{
include
:
vscode
.
GlobPattern
,
exclude
:
vscode
.
GlobPattern
}
|
vscode
.
GlobPattern
{
if
(
typeof
pattern
===
'
string
'
)
{
return
pattern
;
}
if
(
isRelativePattern
(
pattern
))
{
return
{
base
:
pattern
.
base
,
pattern
:
pattern
.
pattern
};
}
return
{
include
:
pattern
.
include
,
exclude
:
pattern
.
exclude
};
}
function
isExclusivePattern
(
obj
:
any
):
obj
is
{
include
:
types
.
RelativePattern
|
undefined
|
null
,
exclude
:
types
.
RelativePattern
|
undefined
|
null
}
{
const
ep
=
obj
as
{
include
:
vscode
.
GlobPattern
,
exclude
:
vscode
.
GlobPattern
};
const
include
=
GlobPattern
.
from
(
ep
.
include
);
...
...
src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts
浏览文件 @
c185f7ab
...
...
@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import
{
KeyChord
,
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
*
as
glob
from
'
vs/base/common/glob
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
EditorContextKeys
}
from
'
vs/editor/common/editorContextKeys
'
;
import
{
getIconClasses
}
from
'
vs/editor/common/services/getIconClasses
'
;
...
...
@@ -12,7 +13,7 @@ import { IModeService } from 'vs/editor/common/services/modeService';
import
{
localize
}
from
'
vs/nls
'
;
import
{
Action2
,
IAction2Options
,
MenuId
,
MenuItemAction
,
MenuRegistry
,
registerAction2
}
from
'
vs/platform/actions/common/actions
'
;
import
{
IClipboardService
}
from
'
vs/platform/clipboard/common/clipboardService
'
;
import
{
ICommandService
}
from
'
vs/platform/commands/common/commands
'
;
import
{
CommandsRegistry
,
ICommandService
}
from
'
vs/platform/commands/common/commands
'
;
import
{
ContextKeyExpr
,
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
InputFocusedContext
,
InputFocusedContextKey
}
from
'
vs/platform/contextkey/common/contextkeys
'
;
import
{
ServicesAccessor
}
from
'
vs/platform/instantiation/common/instantiation
'
;
...
...
@@ -20,7 +21,7 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis
import
{
IQuickInputService
,
IQuickPickItem
,
QuickPickInput
}
from
'
vs/platform/quickinput/common/quickInput
'
;
import
{
BaseCellRenderTemplate
,
CellEditState
,
CellFocusMode
,
ICellViewModel
,
INotebookEditor
,
NOTEBOOK_CELL_INPUT_COLLAPSED
,
NOTEBOOK_CELL_EDITABLE
,
NOTEBOOK_CELL_HAS_OUTPUTS
,
NOTEBOOK_CELL_LIST_FOCUSED
,
NOTEBOOK_CELL_MARKDOWN_EDIT_MODE
,
NOTEBOOK_CELL_OUTPUT_COLLAPSED
,
NOTEBOOK_CELL_TYPE
,
NOTEBOOK_EDITOR_EDITABLE
,
NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK
,
NOTEBOOK_EDITOR_FOCUSED
,
NOTEBOOK_EDITOR_RUNNABLE
,
NOTEBOOK_IS_ACTIVE_EDITOR
,
NOTEBOOK_OUTPUT_FOCUSED
,
EXPAND_CELL_CONTENT_COMMAND_ID
,
NOTEBOOK_CELL_EDITOR_FOCUSED
}
from
'
vs/workbench/contrib/notebook/browser/notebookBrowser
'
;
import
{
CellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel
'
;
import
{
CellEditType
,
CellKind
,
ICellRange
,
NotebookCellMetadata
,
NotebookCellRunState
,
NOTEBOOK_EDITOR_CURSOR_BOUNDARY
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
CellEditType
,
CellKind
,
ICellRange
,
isDocumentExcludePattern
,
NotebookCellMetadata
,
NotebookCellRunState
,
NOTEBOOK_EDITOR_CURSOR_BOUNDARY
,
TransientMetadata
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
INotebookService
}
from
'
vs/workbench/contrib/notebook/common/notebookService
'
;
import
{
IEditorGroupsService
}
from
'
vs/workbench/services/editor/common/editorGroupsService
'
;
import
{
IEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
...
...
@@ -1816,3 +1817,40 @@ registerAction2(class extends Action2 {
}
}
});
CommandsRegistry
.
registerCommand
(
'
_resolveNotebookContentProvider
'
,
(
accessor
,
args
):
{
viewType
:
string
;
displayName
:
string
;
options
:
{
transientOutputs
:
boolean
;
transientMetadata
:
TransientMetadata
};
filenamePattern
:
(
string
|
glob
.
IRelativePattern
|
{
include
:
string
|
glob
.
IRelativePattern
,
exclude
:
string
|
glob
.
IRelativePattern
})[]
}[]
=>
{
const
notebookService
=
accessor
.
get
<
INotebookService
>
(
INotebookService
);
const
contentProviders
=
notebookService
.
getContributedNotebookProviders
();
return
contentProviders
.
map
(
provider
=>
{
const
filenamePatterns
=
provider
.
selectors
.
map
(
selector
=>
{
if
(
typeof
selector
===
'
string
'
)
{
return
selector
;
}
if
(
glob
.
isRelativePattern
(
selector
))
{
return
selector
;
}
if
(
isDocumentExcludePattern
(
selector
))
{
return
{
include
:
selector
.
include
,
exclude
:
selector
.
exclude
};
}
return
null
;
}).
filter
(
pattern
=>
pattern
!==
null
)
as
(
string
|
glob
.
IRelativePattern
|
{
include
:
string
|
glob
.
IRelativePattern
,
exclude
:
string
|
glob
.
IRelativePattern
})[];
return
{
viewType
:
provider
.
id
,
displayName
:
provider
.
displayName
,
filenamePattern
:
filenamePatterns
,
options
:
{
transientMetadata
:
provider
.
options
.
transientMetadata
,
transientOutputs
:
provider
.
options
.
transientOutputs
}
};
});
});
src/vs/workbench/contrib/notebook/browser/extensionPoint.ts
浏览文件 @
c185f7ab
...
...
@@ -6,7 +6,6 @@
import
{
IJSONSchema
}
from
'
vs/base/common/jsonSchema
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
{
ExtensionsRegistry
}
from
'
vs/workbench/services/extensions/common/extensionsRegistry
'
;
import
{
NotebookSelector
}
from
'
vs/workbench/contrib/notebook/common/notebookProvider
'
;
import
{
NotebookEditorPriority
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
namespace
NotebookEditorContribution
{
...
...
@@ -19,7 +18,7 @@ namespace NotebookEditorContribution {
export
interface
INotebookEditorContribution
{
readonly
[
NotebookEditorContribution
.
viewType
]:
string
;
readonly
[
NotebookEditorContribution
.
displayName
]:
string
;
readonly
[
NotebookEditorContribution
.
selector
]?:
readonly
NotebookSelector
[];
readonly
[
NotebookEditorContribution
.
selector
]?:
readonly
{
filenamePattern
?:
string
;
excludeFileNamePattern
?:
string
;
}
[];
readonly
[
NotebookEditorContribution
.
priority
]?:
string
;
}
...
...
src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts
浏览文件 @
c185f7ab
...
...
@@ -569,20 +569,26 @@ export class NotebookService extends Disposable implements INotebookService, ICu
if
(
controller
.
viewOptions
&&
!
this
.
notebookProviderInfoStore
.
get
(
viewType
))
{
// register this content provider to the static contribution, if it does not exist
this
.
notebookProviderInfoStore
.
add
(
new
NotebookProviderInfo
({
const
info
=
new
NotebookProviderInfo
({
displayName
:
controller
.
viewOptions
.
displayName
,
id
:
viewType
,
priority
:
NotebookEditorPriority
.
default
,
selectors
:
controller
.
viewOptions
.
filenamePattern
.
map
(
pattern
=>
({
filenamePattern
:
pattern
}))
,
selectors
:
[]
,
providerExtensionId
:
extensionData
.
id
.
value
,
providerDescription
:
extensionData
.
description
,
providerDisplayName
:
extensionData
.
id
.
value
,
providerExtensionLocation
:
URI
.
revive
(
extensionData
.
location
),
dynamicContribution
:
true
,
exclusive
:
controller
.
viewOptions
.
exclusive
}));
});
info
.
update
({
selectors
:
controller
.
viewOptions
.
filenamePattern
});
info
.
update
({
options
:
controller
.
options
});
this
.
notebookProviderInfoStore
.
add
(
info
);
}
this
.
notebookProviderInfoStore
.
get
(
viewType
)?.
update
({
options
:
controller
.
options
});
this
.
_onDidChangeViewTypes
.
fire
();
return
toDisposable
(()
=>
{
this
.
_notebookProviders
.
delete
(
viewType
);
...
...
@@ -806,8 +812,12 @@ export class NotebookService extends Disposable implements INotebookService, ICu
return
this
.
notebookRenderersInfoStore
.
getContributedRenderer
(
mimeType
);
}
getContributedNotebookProviders
(
resource
:
URI
):
readonly
NotebookProviderInfo
[]
{
return
this
.
notebookProviderInfoStore
.
getContributedNotebook
(
resource
);
getContributedNotebookProviders
(
resource
?:
URI
):
readonly
NotebookProviderInfo
[]
{
if
(
resource
)
{
return
this
.
notebookProviderInfoStore
.
getContributedNotebook
(
resource
);
}
return
[...
this
.
notebookProviderInfoStore
];
}
getContributedNotebookProvider
(
viewType
:
string
):
NotebookProviderInfo
|
undefined
{
...
...
src/vs/workbench/contrib/notebook/common/notebookProvider.ts
浏览文件 @
c185f7ab
...
...
@@ -6,17 +6,14 @@
import
*
as
glob
from
'
vs/base/common/glob
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
basename
}
from
'
vs/base/common/path
'
;
import
{
INotebookExclusiveDocumentFilter
,
isDocumentExcludePattern
,
NotebookEditorPriority
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
INotebookExclusiveDocumentFilter
,
isDocumentExcludePattern
,
NotebookEditorPriority
,
TransientOptions
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
export
interface
NotebookSelector
{
readonly
filenamePattern
?:
string
|
glob
.
IRelativePattern
|
INotebookExclusiveDocumentFilter
;
readonly
excludeFileNamePattern
?:
string
;
}
export
type
NotebookSelector
=
string
|
glob
.
IRelativePattern
|
INotebookExclusiveDocumentFilter
;
export
interface
NotebookEditorDescriptor
{
readonly
id
:
string
;
readonly
displayName
:
string
;
readonly
selectors
:
readonly
NotebookSelector
[];
readonly
selectors
:
readonly
{
filenamePattern
?:
string
;
excludeFileNamePattern
?:
string
;
}
[];
readonly
priority
:
NotebookEditorPriority
;
readonly
providerExtensionId
?:
string
;
readonly
providerDescription
?:
string
;
...
...
@@ -26,11 +23,11 @@ export interface NotebookEditorDescriptor {
readonly
exclusive
:
boolean
;
}
export
class
NotebookProviderInfo
implements
NotebookEditorDescriptor
{
export
class
NotebookProviderInfo
{
readonly
id
:
string
;
readonly
displayName
:
string
;
readonly
selectors
:
readonly
NotebookSelector
[];
readonly
priority
:
NotebookEditorPriority
;
// it's optional as the memento might not have it
readonly
providerExtensionId
?:
string
;
...
...
@@ -39,11 +36,22 @@ export class NotebookProviderInfo implements NotebookEditorDescriptor {
readonly
providerExtensionLocation
:
URI
;
readonly
dynamicContribution
:
boolean
;
readonly
exclusive
:
boolean
;
private
_selectors
:
NotebookSelector
[];
get
selectors
()
{
return
this
.
_selectors
;
}
private
_options
:
TransientOptions
;
get
options
()
{
return
this
.
_options
;
}
constructor
(
descriptor
:
NotebookEditorDescriptor
)
{
this
.
id
=
descriptor
.
id
;
this
.
displayName
=
descriptor
.
displayName
;
this
.
selectors
=
descriptor
.
selectors
;
this
.
_selectors
=
descriptor
.
selectors
?.
map
(
selector
=>
({
include
:
selector
.
filenamePattern
,
exclude
:
selector
.
excludeFileNamePattern
||
''
}))
||
[];
this
.
priority
=
descriptor
.
priority
;
this
.
providerExtensionId
=
descriptor
.
providerExtensionId
;
this
.
providerDescription
=
descriptor
.
providerDescription
;
...
...
@@ -51,6 +59,20 @@ export class NotebookProviderInfo implements NotebookEditorDescriptor {
this
.
providerExtensionLocation
=
descriptor
.
providerExtensionLocation
;
this
.
dynamicContribution
=
descriptor
.
dynamicContribution
;
this
.
exclusive
=
descriptor
.
exclusive
;
this
.
_options
=
{
transientMetadata
:
{},
transientOutputs
:
false
};
}
update
(
args
:
{
selectors
?:
NotebookSelector
[];
options
?:
TransientOptions
})
{
if
(
args
.
selectors
)
{
this
.
_selectors
=
args
.
selectors
;
}
if
(
args
.
options
)
{
this
.
_options
=
args
.
options
;
}
}
matches
(
resource
:
URI
):
boolean
{
...
...
@@ -58,25 +80,25 @@ export class NotebookProviderInfo implements NotebookEditorDescriptor {
}
static
selectorMatches
(
selector
:
NotebookSelector
,
resource
:
URI
):
boolean
{
if
(
!
selector
.
filenamePattern
)
{
return
false
;
if
(
typeof
selector
===
'
string
'
)
{
// filenamePattern
if
(
glob
.
match
(
selector
.
toLowerCase
(),
basename
(
resource
.
fsPath
).
toLowerCase
()))
{
return
true
;
}
}
if
(
typeof
selector
.
filenamePattern
===
'
string
'
)
{
if
(
glob
.
match
(
selector
.
filenamePattern
.
toLowerCase
(),
basename
(
resource
.
fsPath
).
toLowerCase
()))
{
if
(
selector
.
excludeFileNamePattern
)
{
if
(
glob
.
match
(
selector
.
excludeFileNamePattern
.
toLowerCase
(),
basename
(
resource
.
fsPath
).
toLowerCase
()))
{
// should exclude
return
false
;
}
}
if
(
glob
.
isRelativePattern
(
selector
))
{
if
(
glob
.
match
(
selector
,
basename
(
resource
.
fsPath
).
toLowerCase
()))
{
return
true
;
}
}
let
filenamePattern
=
isDocumentExcludePattern
(
selector
.
filenamePattern
)
?
selector
.
filenamePattern
.
include
:
(
selector
.
filenamePattern
as
string
|
glob
.
IRelativePattern
);
let
excludeFilenamePattern
=
isDocumentExcludePattern
(
selector
.
filenamePattern
)
?
selector
.
filenamePattern
.
exclude
:
undefined
;
if
(
!
isDocumentExcludePattern
(
selector
))
{
return
false
;
}
let
filenamePattern
=
selector
.
include
;
let
excludeFilenamePattern
=
selector
.
exclude
;
if
(
glob
.
match
(
filenamePattern
,
basename
(
resource
.
fsPath
).
toLowerCase
()))
{
if
(
excludeFilenamePattern
)
{
...
...
src/vs/workbench/contrib/notebook/common/notebookService.ts
浏览文件 @
c185f7ab
...
...
@@ -59,7 +59,7 @@ export interface INotebookService {
resolveNotebook
(
viewType
:
string
,
uri
:
URI
,
forceReload
:
boolean
,
backupId
?:
string
):
Promise
<
NotebookTextModel
>
;
getNotebookTextModel
(
uri
:
URI
):
NotebookTextModel
|
undefined
;
getNotebookTextModels
():
Iterable
<
NotebookTextModel
>
;
getContributedNotebookProviders
(
resource
:
URI
):
readonly
NotebookProviderInfo
[];
getContributedNotebookProviders
(
resource
?
:
URI
):
readonly
NotebookProviderInfo
[];
getContributedNotebookProvider
(
viewType
:
string
):
NotebookProviderInfo
|
undefined
;
getNotebookProviderResourceRoots
():
URI
[];
destoryNotebookDocument
(
viewType
:
string
,
notebook
:
INotebookTextModel
):
void
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录