Path: blob/main/src/vs/workbench/contrib/notebook/browser/controller/apiActions.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as glob from '../../../../../base/common/glob.js';6import { URI, UriComponents } from '../../../../../base/common/uri.js';7import { CommandsRegistry } from '../../../../../platform/commands/common/commands.js';8import { isDocumentExcludePattern, TransientCellMetadata, TransientDocumentMetadata } from '../../common/notebookCommon.js';9import { INotebookKernelService } from '../../common/notebookKernelService.js';10import { INotebookService } from '../../common/notebookService.js';1112CommandsRegistry.registerCommand('_resolveNotebookContentProvider', (accessor): {13viewType: string;14displayName: string;15options: { transientOutputs: boolean; transientCellMetadata: TransientCellMetadata; transientDocumentMetadata: TransientDocumentMetadata };16filenamePattern: (string | glob.IRelativePattern | { include: string | glob.IRelativePattern; exclude: string | glob.IRelativePattern })[];17}[] => {18const notebookService = accessor.get<INotebookService>(INotebookService);19const contentProviders = notebookService.getContributedNotebookTypes();20return contentProviders.map(provider => {21const filenamePatterns = provider.selectors.map(selector => {22if (typeof selector === 'string') {23return selector;24}2526if (glob.isRelativePattern(selector)) {27return selector;28}2930if (isDocumentExcludePattern(selector)) {31return {32include: selector.include,33exclude: selector.exclude34};35}3637return null;38}).filter(pattern => pattern !== null) as (string | glob.IRelativePattern | { include: string | glob.IRelativePattern; exclude: string | glob.IRelativePattern })[];3940return {41viewType: provider.id,42displayName: provider.displayName,43filenamePattern: filenamePatterns,44options: {45transientCellMetadata: provider.options.transientCellMetadata,46transientDocumentMetadata: provider.options.transientDocumentMetadata,47transientOutputs: provider.options.transientOutputs48}49};50});51});5253CommandsRegistry.registerCommand('_resolveNotebookKernels', async (accessor, args: {54viewType: string;55uri: UriComponents;56}): Promise<{57id?: string;58label: string;59description?: string;60detail?: string;61isPreferred?: boolean;62preloads?: URI[];63}[]> => {64const notebookKernelService = accessor.get(INotebookKernelService);65const uri = URI.revive(args.uri as UriComponents);66const kernels = notebookKernelService.getMatchingKernel({ uri, notebookType: args.viewType });6768return kernels.all.map(provider => ({69id: provider.id,70label: provider.label,71description: provider.description,72detail: provider.detail,73isPreferred: false, // todo@jrieken,@rebornix74preloads: provider.preloadUris,75}));76});777879