Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/notebook/common/notebookService.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 { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
7
import { URI } from '../../../../base/common/uri.js';
8
import { NotebookProviderInfo } from './notebookProvider.js';
9
import { Event } from '../../../../base/common/event.js';
10
import { INotebookRendererInfo, NotebookData, TransientOptions, IOrderedMimeType, IOutputDto, INotebookContributionData, NotebookExtensionDescription, INotebookStaticPreloadInfo } from './notebookCommon.js';
11
import { NotebookTextModel } from './model/notebookTextModel.js';
12
import { CancellationToken } from '../../../../base/common/cancellation.js';
13
import { NotebookCellTextModel } from './model/notebookCellTextModel.js';
14
import { IDisposable } from '../../../../base/common/lifecycle.js';
15
import { VSBuffer, VSBufferReadableStream } from '../../../../base/common/buffer.js';
16
import { ConfigurationTarget } from '../../../../platform/configuration/common/configuration.js';
17
import { IFileStatWithMetadata, IWriteFileOptions } from '../../../../platform/files/common/files.js';
18
import { ITextQuery } from '../../../services/search/common/search.js';
19
import { NotebookPriorityInfo } from '../../search/common/search.js';
20
import { INotebookFileMatchNoModel } from '../../search/common/searchNotebookHelpers.js';
21
import { SnapshotContext } from '../../../services/workingCopy/common/fileWorkingCopy.js';
22
23
24
export const INotebookService = createDecorator<INotebookService>('notebookService');
25
26
export interface INotebookContentProvider {
27
options: TransientOptions;
28
29
open(uri: URI, backupId: string | VSBuffer | undefined, untitledDocumentData: VSBuffer | undefined, token: CancellationToken): Promise<{ data: NotebookData; transientOptions: TransientOptions }>;
30
backup(uri: URI, token: CancellationToken): Promise<string | VSBuffer>;
31
}
32
33
export interface INotebookSerializer {
34
options: TransientOptions;
35
dataToNotebook(data: VSBuffer): Promise<NotebookData>;
36
notebookToData(data: NotebookData): Promise<VSBuffer>;
37
save(uri: URI, versionId: number, options: IWriteFileOptions, token: CancellationToken): Promise<IFileStatWithMetadata>;
38
searchInNotebooks(textQuery: ITextQuery, token: CancellationToken, allPriorityInfo: Map<string, NotebookPriorityInfo[]>): Promise<{ results: INotebookFileMatchNoModel<URI>[]; limitHit: boolean }>;
39
}
40
41
export interface INotebookRawData {
42
data: NotebookData;
43
transientOptions: TransientOptions;
44
}
45
46
export class SimpleNotebookProviderInfo {
47
constructor(
48
readonly viewType: string,
49
readonly serializer: INotebookSerializer,
50
readonly extensionData: NotebookExtensionDescription
51
) { }
52
}
53
54
export interface INotebookService {
55
readonly _serviceBrand: undefined;
56
canResolve(viewType: string): Promise<boolean>;
57
58
readonly onAddViewType: Event<string>;
59
readonly onWillRemoveViewType: Event<string>;
60
readonly onDidChangeOutputRenderers: Event<void>;
61
readonly onWillAddNotebookDocument: Event<NotebookTextModel>;
62
readonly onDidAddNotebookDocument: Event<NotebookTextModel>;
63
64
readonly onWillRemoveNotebookDocument: Event<NotebookTextModel>;
65
readonly onDidRemoveNotebookDocument: Event<NotebookTextModel>;
66
67
registerNotebookSerializer(viewType: string, extensionData: NotebookExtensionDescription, serializer: INotebookSerializer): IDisposable;
68
withNotebookDataProvider(viewType: string): Promise<SimpleNotebookProviderInfo>;
69
tryGetDataProviderSync(viewType: string): SimpleNotebookProviderInfo | undefined;
70
71
getOutputMimeTypeInfo(textModel: NotebookTextModel, kernelProvides: readonly string[] | undefined, output: IOutputDto): readonly IOrderedMimeType[];
72
73
getViewTypeProvider(viewType: string): string | undefined;
74
getRendererInfo(id: string): INotebookRendererInfo | undefined;
75
getRenderers(): INotebookRendererInfo[];
76
77
getStaticPreloads(viewType: string): Iterable<INotebookStaticPreloadInfo>;
78
79
/** Updates the preferred renderer for the given mimetype in the workspace. */
80
updateMimePreferredRenderer(viewType: string, mimeType: string, rendererId: string, otherMimetypes: readonly string[]): void;
81
saveMimeDisplayOrder(target: ConfigurationTarget): void;
82
83
createNotebookTextModel(viewType: string, uri: URI, stream?: VSBufferReadableStream): Promise<NotebookTextModel>;
84
createNotebookTextDocumentSnapshot(uri: URI, context: SnapshotContext, token: CancellationToken): Promise<VSBufferReadableStream>;
85
restoreNotebookTextModelFromSnapshot(uri: URI, viewType: string, snapshot: VSBufferReadableStream): Promise<NotebookTextModel>;
86
getNotebookTextModel(uri: URI): NotebookTextModel | undefined;
87
getNotebookTextModels(): Iterable<NotebookTextModel>;
88
listNotebookDocuments(): readonly NotebookTextModel[];
89
90
/** Register a notebook type that we will handle. The notebook editor will be registered for notebook types contributed by extensions */
91
registerContributedNotebookType(viewType: string, data: INotebookContributionData): IDisposable;
92
getContributedNotebookType(viewType: string): NotebookProviderInfo | undefined;
93
getContributedNotebookTypes(resource?: URI): readonly NotebookProviderInfo[];
94
hasSupportedNotebooks(resource: URI): boolean;
95
getNotebookProviderResourceRoots(): URI[];
96
97
setToCopy(items: NotebookCellTextModel[], isCopy: boolean): void;
98
getToCopy(): { items: NotebookCellTextModel[]; isCopy: boolean } | undefined;
99
clearEditorCache(): void;
100
}
101
102