Skip to content

feat: plan 06 diagnostics - #18

Merged
MicroProofs merged 12 commits into
mainfrom
plan-6
Sep 10, 2026
Merged

feat: plan 06 diagnostics#18
MicroProofs merged 12 commits into
mainfrom
plan-6

Conversation

@MicroProofs

Copy link
Copy Markdown
Contributor

Summary

Implements plan 06 (plans/06-diagnostics.md): the new nash-report crate ports Elm's Reporting/* (Doc, Report, Render, Suggest, Error/*) onto miette, and the driver, CLI and language server render owned diagnostics from it. Twelve commits: three compiler fixes that diagnostics depend on, six nash-report steps, then driver/CLI/LSP wiring and final acceptance.

Versioning: two changesets. report-foundation.md bumps nash-report minor and nash-parse patch. report-wiring.md bumps nash-driver, nash-cli, nash-language-server minor and nash-can, nash-constrain, nash-solve patch. Internal path dependency versions match their crates; the publication graph including dev dependencies is acyclic.

Compiler fixes

  • fix(parse): preserve nested diagnostic context — nested parser errors keep their inner variant instead of collapsing to the outer one. keyword::is_reserved and symbol::is_binop_char are public for the report crate.
  • fix(types): retain diagnostic context — trait-method call names survive into error context.
  • fix(solve): recover independent errors — new nash-solve/src/recovery.rs. The solver no longer stops at the first error. Unrelated definitions and unrelated tuple/record children still check; a failure in one child keeps the known shape so siblings compare against their annotations. Changes to shared inference variables still invalidate every dependent computation. Kind and representation failures survive unrelated type errors. A failed solve returns errors and no solved output. Covered by nash-solve/tests/inference.rs and representation_predicates.rs.

nash-report

  • feat(report): add documents and renderersDoc with Elm's nested fillSep semantics, styled chunks and Unicode widths; owned Report with byte-safe source spans; Report::with_region widens source context while keeping the primary problem region; miette handler for terminal output; Suggest with deterministic distance ordering.
  • feat(report): render type names and differencesLocalizer (actual source imports plus the compiler primitive inventory, qualification preserved when a primitive is shadowed), render_type, and type_diff for focused differences.
  • feat(report): explain syntax errors — module header, imports, exposing, whitespace, end of input, declarations, expressions, patterns and types. Covers all 369 parser variants.
  • feat(report): explain canonicalization errors — including paired declaration locations.
  • feat(report): explain type and trait errors — mismatches with expected/actual types and expression context, operators, records, missing impls (advises an explicit impl; states that @derive is Plan 11), ambiguity, kind and representation errors. Pattern errors and warnings from nitpick.
  • Elm-shaped JSON output (json.rs) with complete snippets. Byte regions convert to display-cell carets, including Unicode and tabs.

Wiring (feat(report): collect phase errors and warnings, feat(cli): …, feat(lsp): …)

  • Driver: nash-driver/src/diagnostics.rs (string formatting) is deleted. compile.rs collects phase errors and warnings into owned reports. Independent modules continue after a failure; a failed dependency blocks its transitive users and exports no interface; unreadable files preserve independent diagnostics; shuffled discovery produces a stable compilation order. Warnings on a failed module sort together with its errors.
  • CLI: nash check gains --report human|json and --no-warnings. Global --color auto|always|never; auto honours NO_COLOR and a non-terminal stderr. Exit codes checked. nash-cli/tests/diagnostics.rs runs the three examples from docs/diagnostics.md against the real core package and checks terminal, JSON and LSP agree on the problem set and source ranges.
  • LSP: nash-language-server/src/workspace.rs and diagnostics.rs publish live compiler diagnostics for unsaved buffers with UTF-16 ranges, paired related locations, version checks, close/repair clearing and nested workspace ownership.
  • docs/diagnostics.md describes recovery rules, localizer scope and the checked examples. SPEC.md ticks plan 06.

Deferred

  • Automatic Prelude imports: Plan 12. The localizer uses actual source imports only.
  • @derive: Plan 11. Missing-impl reports mention it as unavailable.
  • No Plan 06 chunk is deferred.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo insta test --workspace --check --unreferenced reject — 2,950 passed, 0 failed, 3 ignored; no pending or unreferenced snapshots
  • cargo run -p nash-cli -- check tests/core — 23 modules, 215 declarations
  • nash-solve/tests/inference.rs: mixed mismatches, missing impls, ambiguity and kind errors in both declaration orders; repeated and recursive uses; shared partial unification; independent tuple siblings; nested aggregates; generic record selection with failures in other fields
  • nash-driver/src/compile/collection_tests.rs and graph tests: independent-module continuation, blocked dependents, unreadable files, no interfaces from failed modules, stable order under shuffled discovery
  • nash-cli/tests/diagnostics.rs: identical ordering across repeated runs; terminal/JSON/LSP parity; color, warning controls and exit codes; docs examples against the shipping core/
  • Language-server tests: UTF-16 positions, related locations, unsaved buffers, version checks, close/repair clearing, nested workspace ownership
  • Independent review passed 28 additional recovery probes; no open findings

https://claude.ai/code/session_01ScuAeUCfNGXAznfEEKDH1X

Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
@MicroProofs
MicroProofs merged commit b7ff823 into main Sep 10, 2026
9 checks passed
@MicroProofs
MicroProofs deleted the plan-6 branch September 10, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant