mix compile.diagnostics (client_utils v0.5.0)

View Source

Registers after_compiler hooks that write diagnostics to a JSONL file.

Add :diagnostics as the first compiler so the hooks are registered before :elixir runs. This ensures diagnostics are written even when a syntax error aborts the compiler chain.

def project do
  [
    compilers: [:diagnostics] ++ Mix.compilers() ++ [:spex],
    diagnostics: [output: "diagnostics.jsonl"],
    ...
  ]
end

Options

  • :output - output file path, defaults to "diagnostics.jsonl". Can also be set via the DIAGNOSTICS_OUTPUT env var.

Project configuration

Options can be set under the :diagnostics key:

def project do
  [
    compilers: [:diagnostics] ++ Mix.compilers() ++ [:spex],
    diagnostics: [output: "build/diagnostics.jsonl"],
    ...
  ]
end

Summary

Functions

Adds one compiler's diagnostics to those already seen in this compile and rewrites the file with all of them.

Writes diagnostics to the output file.

Functions

record(output, diagnostics)

Adds one compiler's diagnostics to those already seen in this compile and rewrites the file with all of them.

Each hook used to write only its own: :app runs after :elixir with none, so the file was rewritten empty and every compiler warning was lost before anything read it.

write_diagnostics(output, extra_diagnostics \\ [])

Writes diagnostics to the output file.

Merges diagnostics passed via extra_diagnostics (from the after_compiler callback) with those queried from every compiler that exposes diagnostics/0, deduplicating by file + position + message.