UNPKG

3.89 kBTypeScriptView Raw
1import { NotificationHandler1, Event, DocumentUri, URI, Disposable, DidOpenNotebookDocumentParams, DidChangeNotebookDocumentParams, DidSaveNotebookDocumentParams, DidCloseNotebookDocumentParams, NotebookDocument, NotebookCell, LSPObject } from 'vscode-languageserver-protocol';
2import type { Feature, _Notebooks, Connection } from './server';
3import { TextDocuments, TextDocumentsConfiguration } from './textDocuments';
4/**
5 * Shape of the notebooks feature
6 *
7 * @since 3.17.0
8 */
9export interface NotebookSyncFeatureShape {
10 synchronization: {
11 onDidOpenNotebookDocument(handler: NotificationHandler1<DidOpenNotebookDocumentParams>): Disposable;
12 onDidChangeNotebookDocument(handler: NotificationHandler1<DidChangeNotebookDocumentParams>): Disposable;
13 onDidSaveNotebookDocument(handler: NotificationHandler1<DidSaveNotebookDocumentParams>): Disposable;
14 onDidCloseNotebookDocument(handler: NotificationHandler1<DidCloseNotebookDocumentParams>): Disposable;
15 };
16}
17export declare const NotebookSyncFeature: Feature<_Notebooks, NotebookSyncFeatureShape>;
18export type NotebookDocumentChangeEvent = {
19 /**
20 * The notebook document that changed.
21 */
22 notebookDocument: NotebookDocument;
23 /**
24 * The meta data change if any.
25 *
26 * Note: old and new should always be an object literal (e.g. LSPObject)
27 */
28 metadata?: {
29 old: LSPObject | undefined;
30 new: LSPObject | undefined;
31 };
32 /**
33 * The cell changes if any.
34 */
35 cells?: {
36 /**
37 * The cells that got added.
38 */
39 added: NotebookCell[];
40 /**
41 * The cells that got removed.
42 */
43 removed: NotebookCell[];
44 /**
45 * The cells that changed.
46 */
47 changed: {
48 /**
49 * The cell data has changed, excluding its
50 * text content which is reported via
51 * `textContentChanged`.
52 */
53 data: {
54 old: NotebookCell;
55 new: NotebookCell;
56 }[];
57 /**
58 * The text content of a cell has changed.
59 * The actual text is available via the `Notebooks`
60 * text document manager.
61 */
62 textContent: NotebookCell[];
63 };
64 };
65};
66export declare class NotebookDocuments<T extends {
67 uri: DocumentUri;
68}> {
69 private readonly notebookDocuments;
70 private readonly notebookCellMap;
71 private readonly _onDidOpen;
72 private readonly _onDidSave;
73 private readonly _onDidChange;
74 private readonly _onDidClose;
75 private _cellTextDocuments;
76 constructor(configurationOrTextDocuments: TextDocumentsConfiguration<T> | TextDocuments<T>);
77 get cellTextDocuments(): TextDocuments<T>;
78 getCellTextDocument(cell: NotebookCell): T | undefined;
79 getNotebookDocument(uri: URI): NotebookDocument | undefined;
80 getNotebookCell(uri: DocumentUri): NotebookCell | undefined;
81 findNotebookDocumentForCell(cell: DocumentUri | NotebookCell): NotebookDocument | undefined;
82 get onDidOpen(): Event<NotebookDocument>;
83 get onDidSave(): Event<NotebookDocument>;
84 get onDidChange(): Event<NotebookDocumentChangeEvent>;
85 get onDidClose(): Event<NotebookDocument>;
86 /**
87 * Listens for `low level` notification on the given connection to
88 * update the notebook documents managed by this instance.
89 *
90 * Please note that the connection only provides handlers not an event model. Therefore
91 * listening on a connection will overwrite the following handlers on a connection:
92 * `onDidOpenNotebookDocument`, `onDidChangeNotebookDocument`, `onDidSaveNotebookDocument`,
93 * and `onDidCloseNotebookDocument`.
94 *
95 * @param connection The connection to listen on.
96 */
97 listen(connection: Connection): Disposable;
98 private updateCellMap;
99}