Ragex.Editor.Types (Ragex v0.10.1)

View Source

Common types and structs for the editor module.

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

Summary

Types

Information about a backup.

A single change to apply to a file.

Type of edit operation.

Result of an edit operation.

Validation error.

Functions

Creates a backup info struct.

Creates a delete change struct.

Creates an edit result struct.

Creates an insert change struct.

Creates a replace change struct.

Validates a change struct.

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.