Datalayer VS Code Extension - v0.0.17
    Preparing search index...

    Class NotebookDocument

    Represents a Jupyter notebook document in VS Code custom editor. Manages document lifecycle, content persistence, and edit tracking with support for both collaborative Datalayer notebooks and local file-based notebooks.

    This class implements different behaviors based on the URI scheme:

    • datalayer:// URIs: Collaborative notebooks with real-time sync (read-only locally)
    • file:// URIs: Local notebooks with full edit tracking and persistence

    Hierarchy (View Summary)

    Implements

    • CustomDocument
    Index

    Properties

    _disposables: Disposable[] = []

    Collection of child disposables to clean up.

    onDidChange: Event<{ label: string; redo(): void; undo(): void }> = ...

    Event fired when an edit is made with undo/redo handlers. Enables VS Code's edit history functionality.

    onDidChangeContent: Event<
        { content?: Uint8Array; edits: readonly NotebookEdit[] },
    > = ...

    Event fired when the document content or edits change. Listeners receive the updated content and edit history.

    onDidDispose: Event<void> = ...

    Event fired when the document is disposed. Used to clean up resources and listeners.

    Accessors

    • get documentData(): Uint8Array

      Gets the current notebook content as binary data.

      Contains the serialized Jupyter notebook JSON structure. Updated automatically when edits are applied via makeEdit().

      Returns Uint8Array

      Binary representation of the notebook content.

    • get isDisposed(): boolean

      Gets whether this instance has been disposed.

      Returns boolean

      True if disposed, false otherwise.

    • get uri(): Uri

      Gets the notebook URI which determines collaborative vs local behavior.

      The URI scheme determines the document's behavior:

      • datalayer://: Collaborative notebook with real-time synchronization.
      • file://: Local notebook with traditional file persistence.
      • untitled:: New unsaved notebook.

      Returns Uri

      The VS Code URI for this notebook document.

    Methods

    • Registers a disposable to be cleaned up when this instance is disposed.

      Type Parameters

      • T extends Disposable

      Parameters

      • value: T

        The disposable to register.

      Returns T

      The registered disposable.

    • Creates a backup of the notebook document.

      Saves the current document state to a backup location and returns a backup descriptor for VS Code's backup/restore system.

      Parameters

      • destination: Uri

        URI for the backup location.

      • cancellation: CancellationToken

        Cancellation token for the backup operation.

      Returns Promise<CustomDocumentBackup>

      Promise resolving to backup descriptor with cleanup function.

    • Disposes of the notebook document and releases all associated resources.

      Fires disposal events and calls the parent disposable cleanup. Should be called when the document is no longer needed to prevent memory leaks.

      Returns void

    • Records an edit operation on the notebook document.

      Behavior differs based on the URI scheme:

      • Collaborative notebooks (datalayer://): Skips edit tracking since changes are managed by the Datalayer platform's real-time synchronization
      • Local notebooks: Tracks edits for undo/redo functionality and dirty state

      For local notebooks, updates the document content and fires change events with undo/redo handlers for VS Code's edit history.

      Parameters

      Returns void

    • Reverts the notebook document to its last saved state.

      Reloads content from disk and restores the edit history to the last saved state. Fires document change events to notify the UI of the content restoration.

      Parameters

      • _cancellation: CancellationToken

        Cancellation token (currently unused).

      Returns Promise<void>

    • Saves the notebook document to its original location.

      Behavior differs based on the URI scheme:

      • Collaborative notebooks (datalayer://): No-op since changes are automatically synchronized to the Datalayer platform.
      • Local notebooks: Persists current content to the file system.

      Parameters

      • cancellation: CancellationToken

        Cancellation token for the save operation.

      Returns Promise<void>

    • Saves the notebook document to a specified location.

      Handles different scenarios based on URI schemes and target locations:

      • Collaborative to same location: No-op since changes are auto-synchronized.
      • Collaborative to different location: Exports current content as local file.
      • Local notebook: Retrieves fresh content from webview and saves to target.

      Parameters

      • targetResource: Uri

        URI where to save the notebook.

      • cancellation: CancellationToken

        Cancellation token for the save operation.

      Returns Promise<void>

    • Creates a new NotebookDocument instance from a URI.

      Handles both regular notebook files and backup restoration scenarios. For backup restoration, the backupId parameter should contain the backup file URI. Supports both local file URIs and collaborative Datalayer URIs.

      Parameters

      • uri: Uri

        The notebook URI to open.

      • backupId: string

        Optional backup ID for document restoration.

      • delegate: NotebookDocumentDelegate

        Delegate for webview content retrieval and management.

      Returns Promise<NotebookDocument>

      Promise resolving to the created notebook document instance.