---
title: "document | Eidos Docs"
description: "SDK signatures, permissions and behavior for document."
source: "https://docs.eidos.space/plugins/api/document/"
lang: "en"
---

# document

Available to document file Views and document actions. Declare document; writes require access: write. observe returns the initial snapshot and a subscription. edit changes the working copy and returns stale on a version mismatch; save returns conflict on a disk conflict. Neither result is an exception. Preserve drafts and serialize edits.

Usage guide: [files](https://docs.eidos.space/plugins/files/). [API index](https://docs.eidos.space/plugins/api/).

Signatures, parameters and return types are generated from the SDK. Optional members are not available in every host and context.

## TextDocument

[Source](https://github.com/mayneyao/eidos/blob/dev/packages/plugin-sdk/src/index.ts#L592)

### TextDocument.read

Supported hosts: Lite Mobile

Read the current working-copy snapshot, including unsaved changes.

```ts
read(): Promise<TextSnapshot>;
```

Returns: `Promise<TextSnapshot>`.

### TextDocument.observe

Supported hosts: Lite Mobile

Return an initial snapshot together with a subscription to later changes.

```ts
observe(listener: (state: TextSnapshot) => void, onError?: ObserverErrorHandler): Promise<{
    snapshot: TextSnapshot;
    subscription: Disposable;
}>;
```

| Parameter | Type                          | Required |
| --------- | ----------------------------- | -------- |
| listener  | (state: TextSnapshot) => void | Yes      |
| onError   | ObserverErrorHandler          | No       |

Returns: `Promise<{ snapshot: TextSnapshot; subscription: Disposable; }>`.

### TextDocument.edit

Supported hosts: Lite

Replace working-copy text when expectedVersion matches. A stale result leaves newer content intact.

```ts
edit(change: {
    text: string;
    expectedVersion: string;
    label?: string;
    group?: string;
}): Promise<{
    status: "applied" | "stale";
    snapshot: TextSnapshot;
}>;
```

| Parameter | Type                                                                       | Required |
| --------- | -------------------------------------------------------------------------- | -------- |
| change    | { text: string; expectedVersion: string; label?: string; group?: string; } | Yes      |

Returns: `Promise<{ status: "applied" &#124; "stale"; snapshot: TextSnapshot; }>`.

### TextDocument.save

Supported hosts: Lite

Save the working copy. A disk conflict returns conflict and preserves the draft.

```ts
save(): Promise<{
    status: "saved" | "conflict";
    snapshot: TextSnapshot;
}>;
```

Returns: `Promise<{ status: "saved" &#124; "conflict"; snapshot: TextSnapshot; }>`.

### TextDocument.undo

Supported hosts: Lite

Undo an edit and return the resulting snapshot.

```ts
undo(): Promise<TextSnapshot>;
```

Returns: `Promise<TextSnapshot>`.

### TextDocument.redo

Supported hosts: Lite

Redo an edit and return the resulting snapshot.

```ts
redo(): Promise<TextSnapshot>;
```

Returns: `Promise<TextSnapshot>`.

Related types: [TextSnapshot](https://docs.eidos.space/plugins/api/types/#textsnapshot), [ObserverErrorHandler](https://docs.eidos.space/plugins/api/types/#observererrorhandler), [Disposable](https://docs.eidos.space/plugins/api/types/#disposable).
