Search documentation of Ragex

# Ragex.Editor.Types (Ragex v0.4.0)

View Source

Common types and structs for the editor module.

Defines data structures for changes, backups, and operation results.

## Summary

### Types

backup_info()

Information about a backup.

change()

A single change to apply to a file.

change_type()

Type of edit operation.

edit_result()

Result of an edit operation.

validation_error()

Validation error.

### Functions

backup_info(id, path, backup_path, opts \\ [])

Creates a backup info struct.

delete(line_start, line_end)

Creates a delete change struct.

edit_result(path, opts \\ [])

Creates an edit result struct.

insert(line_start, content)

Creates an insert change struct.

replace(line_start, line_end, content)

Creates a replace change struct.

validate_change(change)

Validates a change struct.

validation_error(message, opts \\ [])

Creates a validation error struct.

## Types

# backup_info()

    @type backup_info() :: %{
      id: String.t(),
      path: String.t(),
      backup_path: String.t(),
      size: non_neg_integer(),
      created_at: DateTime.t(),
      original_mtime: integer()
    }

Information about a backup.

# change()

    @type change() :: %{
      type: change_type(),
      line_start: pos_integer(),
      line_end: pos_integer() | nil,
      content: String.t() | nil
    }

A single change to apply to a file.

# change_type()

    @type change_type() :: :replace | :insert | :delete

Type of edit operation.

# edit_result()

    @type edit_result() :: %{
      path: String.t(),
      backup_id: String.t() | nil,
      changes_applied: non_neg_integer(),
      lines_changed: non_neg_integer(),
      validation_performed: boolean(),
      timestamp: DateTime.t()
    }

Result of an edit operation.

# validation_error()

    @type validation_error() :: %{
      line: pos_integer() | nil,
      column: pos_integer() | nil,
      message: String.t(),
      severity: :error | :warning
    }

Validation error.

## Functions

# backup_info(id, path, backup_path, opts \\ [])

    @spec backup_info(String.t(), String.t(), String.t(), keyword()) :: backup_info()

Creates a backup info struct.

# delete(line_start, line_end)

    @spec delete(pos_integer(), pos_integer()) :: change()

Creates a delete change struct.

## Examples

    iex> Types.delete(5, 8)
    %{type: :delete, line_start: 5, line_end: 8, content: nil}

# edit_result(path, opts \\ [])

    @spec edit_result(
      String.t(),
      keyword()
    ) :: edit_result()

Creates an edit result struct.

# insert(line_start, content)

    @spec insert(pos_integer(), String.t()) :: change()

Creates an insert change struct.

## Examples

    iex> Types.insert(20, "inserted line")
    %{type: :insert, line_start: 20, line_end: nil, content: "inserted line"}

# replace(line_start, line_end, content)

    @spec replace(pos_integer(), pos_integer(), String.t()) :: change()

Creates a replace change struct.

## Examples

    iex> Types.replace(10, 15, "new content")
    %{type: :replace, line_start: 10, line_end: 15, content: "new content"}

# validate_change(change)

    @spec validate_change(change()) :: :ok | {:error, String.t()}

Validates a change struct.

Returns `:ok` if valid, `{:error, reason}` otherwise.

# validation_error(message, opts \\ [])

    @spec validation_error(
      String.t(),
      keyword()
    ) :: validation_error()

Creates a validation error struct.