jonaprieto/lean-termcolor-diagnostics

Source-annotated diagnostics and rich error reporting for Lean 4 CLI tools

★ 0Forks 0LeanGitHub ↗Compare

Project website ↗

ai-assistedansiclideveloper-toolsdiagnosticserror-reportingleanlean4pretty-printingsource-annotationstermcolorterminal

README

lean-termcolor-diagnostics

CI Release Lean 4 Docs License

Pure source-annotated diagnostics for Lean 4 command-line tools. A diagnostic renders to TermColor.Text; terminal IO remains outside the package.

Problem

Command-line tools need precise source context for errors without taking on terminal IO or a particular output policy.

TermColor diagnostics demo

Development

This project is maintained by its author with AI-assisted development tools. Changes are reviewed, tested, and remain the maintainer's responsibility.

Install

require termcolor-diagnostics from git
  "https://github.com/jonaprieto/lean-termcolor-diagnostics.git" @ "v0.1.14"

Quick start

import TermColor.Diagnostics
import TermColor.Detect

open TermColor TermColor.Diagnostics

def sources : Sources := #[Source.named "settings.toml" "timeout = 2x"]

def diagnostic : Diagnostic :=
  (Diagnostic.error "invalid duration")
    |>.withCode "E1001"
    |>.withLabel (Label.primary (Span.range 0 10 12) "expected a duration")
    |>.withFixIt { span := Span.range 0 10 12, replacement := "2m" }
    |>.withHelp "try timeout = 2m"

#eval Text.render RenderTarget.plain (render sources diagnostic)

The model supports source spans, primary and secondary labels, notes, help, fix-its, multiple files, configurable context and width, color schemes, plain output, and optional OSC-8 links. Offsets are UTF-8 byte positions, matching byte-oriented parsers such as Grip.

Build

lake build TermColor.Diagnostics TermColor.Diagnostics.Properties tests detect readme demo
lake exe tests
lake exe demo

Related projects

grip-diagnostics adapts Grip parse errors; argus uses the renderer for command-line errors; lean-calc-chat, termcolor-layout, and oatp consume it directly.

License

Apache-2.0.

Contributors

jonaprieto

Issues