Datalayer VS Code Extension - v0.0.4
    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

    _disposables: Disposable[] = []

    Collection of child disposables to clean up

    _documentData: Uint8Array
    _isCollaborative: boolean = false
    _isDirty: boolean = false
    _onDidChange: EventEmitter<void> = ...
    _onDidChangeDocument: EventEmitter<{ content?: Uint8Array }> = ...
    _onDidDispose: EventEmitter<void> = ...
    _uri: Uri
    onDidChange: Event<void> = ...
    onDidChangeContent: Event<{ content?: Uint8Array }> = ...
    onDidDispose: Event<void> = ...

    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

    • Parameters

      • uri: Uri

      Returns Promise<Uint8Array<ArrayBufferLike>>

    • Parameters

      • uri: Uri

      Returns Promise<Uint8Array<ArrayBufferLike>>