# `VirtualTimeMigrate.Edits`
[🔗](https://github.com/d-led/gen_server_virtual_time/blob/v1.1.1/packages/gen_server_virtual_time_migrate/lib/virtual_time_migrate/edits.ex#L1)

The editable unit of a planned rewrite: a token at a line and column.

Two rewrites need this — moving `GenServer` code onto the virtual clock
(`VirtualTimeMigrate`) and moving a project off the deprecated module names
(`VirtualTimeUpgrade`) — so the machinery for collecting, checking and applying
the edits lives here rather than in either of them.

Every edit carries the exact source text it expects to find at its position and
is checked against the source before it joins the plan, so a plan can never be
applied to text it does not describe.

# `edit`

```elixir
@type edit() :: %{
  line: pos_integer(),
  column: pos_integer(),
  from: String.t(),
  to: String.t(),
  change: String.t()
}
```

One replacement: `from` is the exact source text at `column` on `line`, and
`to` is what replaces it.

# `note`

```elixir
@type note() :: %{line: pos_integer(), message: String.t()}
```

Something the rewrite noticed but leaves alone.

# `plan`

```elixir
@type plan() :: %{edits: [edit()], notes: [note()]}
```

# `state`

```elixir
@opaque state()
```

# `add`

```elixir
@spec add(state(), keyword(), String.t(), String.t(), String.t()) :: state()
```

Records that `from`, at `meta`'s position, becomes `to`.

`change` is what the report prints. If the source does not have `from` there, a
note is recorded instead: a wrong position is a bug in the plan, and a note is
how it becomes visible rather than a silently mis-edited file.

# `apply`

```elixir
@spec apply(String.t(), [edit()]) :: String.t()
```

Applies a plan to the source it was planned from.

Edits are applied right to left within a line, so an earlier replacement never
moves a later one.

# `new`

```elixir
@spec new(String.t()) :: state()
```

Starts collecting edits for `source`.

# `note`

```elixir
@spec note(state(), keyword(), String.t()) :: state()
```

Records something worth telling the human about, without rewriting it.

# `to_plan`

```elixir
@spec to_plan(state()) :: plan()
```

The plan, in source order.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
