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

    Class LexicalDocument

    Represents a lexical document in VS Code custom editor. Manages document lifecycle, content state, and collaboration features.

    This class implements the VS Code CustomDocument interface to provide document management for Datalayer's lexical editor integration.

    const document = await LexicalDocument.create(uri, undefined, delegate);
    document.setCollaborative(true); // Enable collaboration mode

    Hierarchy (View Summary)

    Implements

    • CustomDocument
    Index

    Constructors

    Properties

    Delegate for retrieving document content from webview during save.

    _disposables: Disposable[] = []

    Collection of child disposables to clean up

    _documentData: Uint8Array

    The document's binary content.

    _isCollaborative: boolean = false

    Whether the document is in collaborative editing mode.

    _isDirty: boolean = false

    Whether the document has unsaved changes.

    _onDidChange: EventEmitter<void> = ...

    Event emitter fired when document state changes.

    _onDidChangeDocument: EventEmitter<{ content?: Uint8Array }> = ...

    Event emitter fired when document content changes. Includes optional updated content binary data.

    _onDidDispose: EventEmitter<void> = ...

    Event emitter fired when document is disposed.

    _uri: Uri

    The document's URI.

    onDidChange: Event<void> = ...

    Event fired when document state changes. Indicates document is dirty or collaborative sync occurred.

    onDidChangeContent: Event<{ content?: Uint8Array }> = ...

    Event fired when document content changes. VS Code CustomDocument interface compliance.

    onDidDispose: Event<void> = ...

    Event fired when document is disposed. VS Code CustomDocument interface compliance.

    Accessors

    • get documentData(): Uint8Array

      Current document content as binary data.

      Returns Uint8Array

      Binary representation of the document content

    • get isDirty(): boolean

      Whether the document has unsaved changes.

      In collaborative mode, this always returns false since changes are automatically synchronized to the platform.

      Returns boolean

      True if document has unsaved changes, false otherwise

    • get isDisposed(): boolean

      Gets whether this instance has been disposed.

      Returns boolean

      True if disposed, false otherwise

    • get uri(): Uri

      The document's URI.

      Returns Uri

      The VS Code URI for this 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 document.

      Saves the current document state to a backup location and returns a backup descriptor that can be used for restoration.

      Parameters

      • destination: Uri

        URI for the backup location

      • cancellation: CancellationToken

        Cancellation token for the operation

      Returns Promise<CustomDocumentBackup>

      Promise resolving to backup descriptor

    • Disposes of the document and cleans up resources.

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

      Returns void

    • Records an edit operation on the document.

      In non-collaborative mode, marks the document as dirty and fires change events. In collaborative mode, only fires change events since the document state is managed externally.

      Parameters

      • _edit: unknown

        The edit operation (currently unused)

      Returns void

    • Reverts the document to its last saved state.

      Reloads content from disk, clears the dirty state, and notifies listeners of the content change.

      Parameters

      • _cancellation: CancellationToken

        Cancellation token (currently unused)

      Returns Promise<void>

    • Saves the document to its original location.

      In collaborative mode, this operation is a no-op since changes are automatically synchronized. Otherwise, retrieves current content from the webview and writes it to the file system.

      Parameters

      • cancellation: CancellationToken

        Cancellation token for the operation

      Returns Promise<void>

    • Saves the document to a new location.

      Retrieves current content from the webview and writes it to the specified target location. Does not change the document's original URI.

      Parameters

      • targetResource: Uri

        URI where to save the document

      • cancellation: CancellationToken

        Cancellation token for the operation

      Returns Promise<void>

    • Sets the collaborative mode for this document.

      When collaborative mode is enabled, the document becomes read-only and changes are automatically synchronized to the Datalayer platform. The dirty state is cleared when entering collaborative mode.

      Parameters

      • isCollaborative: boolean

        Whether to enable collaborative mode

      Returns void

    • Creates a new LexicalDocument instance from a URI.

      Handles both regular files and backup scenarios. For backup restoration, the backupId parameter should contain the backup file URI.

      Parameters

      • uri: Uri

        The document URI to open

      • backupId: string

        Optional backup ID for document restoration

      • delegate: LexicalDocumentDelegate

        Delegate for webview content retrieval

      Returns Promise<LexicalDocument>

      Promise resolving to the created document instance

    • Private

      Generates default Lexical editor content for new documents.

      Returns a valid Lexical state JSON with a heading containing welcome text. Used when creating untitled documents or handling file read failures.

      Returns Uint8Array

      Binary encoded default Lexical state JSON

    • Private

      Reads document content from Datalayer platform.

      Attempts to retrieve document metadata and load content from local cache or virtual file system. Falls back to default content if document unavailable or extension not ready.

      Parameters

      • uri: Uri

        Datalayer document URI

      Returns Promise<Uint8Array<ArrayBufferLike>>

      Promise resolving to binary file content

    • Private

      Reads file content from disk or remote storage.

      Handles three URI schemes:

      • "untitled": Returns default content for new documents
      • "datalayer": Attempts to read from Datalayer platform with fallback
      • other: Reads from local file system via VS Code workspace API

      Parameters

      • uri: Uri

        The file URI to read from

      Returns Promise<Uint8Array<ArrayBufferLike>>

      Promise resolving to binary file content