View Source Mix.Task.Compiler.Diagnostic (Mix v1.17.0-dev)

Diagnostic information such as a warning or compilation error.

The file and position relate to where the diagnostic should be shown. If there is a file and position, then the diagnostic is precise and you can use the given file and position for generating snippets, IDEs annotations, and so on. An optional span is available with the line and column the diagnostic ends.

Otherwise, a stacktrace may be given, which you can place your own heuristics to provide better reporting.

The source field points to the source file the compiler tracked the error to. For example, a file lib/foo.ex may embed .eex templates from lib/foo/bar.eex. A syntax error on the EEx template will point to file lib/foo/bar.eex but the source is lib/foo.ex.

Summary

Types

Severity of a diagnostic

t()

Types

@type severity() :: :error | :warning | :information | :hint

Severity of a diagnostic:

  • :error - An issue that caused compilation to fail

  • :warning - An issue that did not cause failure but suggests the programmer may have made a mistake

  • :hint - A suggestion for style or good practices that is not as severe as a warning

  • :information - Any other information relevant to compilation that does not fit into the above categories

@type t() :: %Mix.Task.Compiler.Diagnostic{
  compiler_name: String.t(),
  details: term(),
  file: Path.t() | nil,
  message: IO.chardata(),
  position: Code.position(),
  severity: severity(),
  source: Path.t() | nil,
  span: {line :: pos_integer(), column :: pos_integer()} | nil,
  stacktrace: Exception.stacktrace()
}