Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/notebook/browser/controller/apiActions.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as glob from '../../../../../base/common/glob.js';
7
import { URI, UriComponents } from '../../../../../base/common/uri.js';
8
import { CommandsRegistry } from '../../../../../platform/commands/common/commands.js';
9
import { isDocumentExcludePattern, TransientCellMetadata, TransientDocumentMetadata } from '../../common/notebookCommon.js';
10
import { INotebookKernelService } from '../../common/notebookKernelService.js';
11
import { INotebookService } from '../../common/notebookService.js';
12
13
CommandsRegistry.registerCommand('_resolveNotebookContentProvider', (accessor): {
14
viewType: string;
15
displayName: string;
16
options: { transientOutputs: boolean; transientCellMetadata: TransientCellMetadata; transientDocumentMetadata: TransientDocumentMetadata };
17
filenamePattern: (string | glob.IRelativePattern | { include: string | glob.IRelativePattern; exclude: string | glob.IRelativePattern })[];
18
}[] => {
19
const notebookService = accessor.get<INotebookService>(INotebookService);
20
const contentProviders = notebookService.getContributedNotebookTypes();
21
return contentProviders.map(provider => {
22
const filenamePatterns = provider.selectors.map(selector => {
23
if (typeof selector === 'string') {
24
return selector;
25
}
26
27
if (glob.isRelativePattern(selector)) {
28
return selector;
29
}
30
31
if (isDocumentExcludePattern(selector)) {
32
return {
33
include: selector.include,
34
exclude: selector.exclude
35
};
36
}
37
38
return null;
39
}).filter(pattern => pattern !== null) as (string | glob.IRelativePattern | { include: string | glob.IRelativePattern; exclude: string | glob.IRelativePattern })[];
40
41
return {
42
viewType: provider.id,
43
displayName: provider.displayName,
44
filenamePattern: filenamePatterns,
45
options: {
46
transientCellMetadata: provider.options.transientCellMetadata,
47
transientDocumentMetadata: provider.options.transientDocumentMetadata,
48
transientOutputs: provider.options.transientOutputs
49
}
50
};
51
});
52
});
53
54
CommandsRegistry.registerCommand('_resolveNotebookKernels', async (accessor, args: {
55
viewType: string;
56
uri: UriComponents;
57
}): Promise<{
58
id?: string;
59
label: string;
60
description?: string;
61
detail?: string;
62
isPreferred?: boolean;
63
preloads?: URI[];
64
}[]> => {
65
const notebookKernelService = accessor.get(INotebookKernelService);
66
const uri = URI.revive(args.uri as UriComponents);
67
const kernels = notebookKernelService.getMatchingKernel({ uri, notebookType: args.viewType });
68
69
return kernels.all.map(provider => ({
70
id: provider.id,
71
label: provider.label,
72
description: provider.description,
73
detail: provider.detail,
74
isPreferred: false, // todo@jrieken,@rebornix
75
preloads: provider.preloadUris,
76
}));
77
});
78
79