Adze.Aliases (Adze v0.1.0)

Copy Markdown View Source

List every alias / import / require / use directive in a file, scoped per defmodule and emitted in source order.

Useful as a cleanup target (unused aliases, import -> explicit alias, etc.) and as a navigation index for AI consumers — same role as outline, but specifically for directives.

Output shape

%{
  file: "lib/foo.ex" | nil,
  modules: [
    %{
      name: "Foo.Bar",
      range: %{start: 1, end: 20},
      directives: [
        %{
          kind: :alias | :import | :require | :use,
          target: "Foo.Bar",           # dotted module string
          as: "Baz" | nil,             # alias-only binding override
          group: true | false,         # part of `alias Foo.{A, B}` form
          text: "alias Foo.Bar",       # raw source slice
          range: %{start: N, end: N}
        },
        ...
      ]
    }
  ]
}

Group-form alias Foo.{A, B} is expanded into one entry per member. All members share the same range and text (pointing at the original declaration) and carry group: true, so callers can either reason about each binding independently or recognize the original grouping.

Summary

Types

directive()

@type directive() :: %{
  kind: :alias | :import | :require | :use,
  target: String.t(),
  as: String.t() | nil,
  group: boolean(),
  text: String.t(),
  range: %{start: pos_integer(), end: pos_integer()} | nil
}

Functions

aliases(source, opts \\ [])

@spec aliases(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

aliases_file(path)

@spec aliases_file(Path.t()) :: {:ok, map()} | {:error, term()}