Skip to content

feat: add miette-based diagnostic renderer with Rust integration #1021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

idriss-hamadi
Copy link

@idriss-hamadi idriss-hamadi commented Jun 10, 2025

Overview

Adds a new high-quality diagnostic renderer using the Rust miette crate, providing beautiful, user-friendly error messages with source code highlighting and precise error location indicators.

closes #968

Features

  • Rich diagnostic rendering with Unicode/ASCII themes
  • Source code highlighting with precise span annotations
  • ANSI color support with fallback to ASCII theme
  • Multiple severity levels (ERROR, WARNING, ADVICE)
  • Hierarchical diagnostics supporting parent/child relationships
  • Configurable output (context lines, custom footers)
  • Graceful fallback when Rust extension unavailable

Implementation

  • Rust extension (miette_py) using PyO3 bindings
  • Python wrapper (diagnostic_miette.py) for seamless integration
  • Maturin build system for mixed Python/Rust package compilation
  • Comprehensive test suite (13 tests, 100% pass rate)

All quality checks pass

ruff format ruff check mypy pytest

13/13 tests passing with comprehensive coverage:

  • Direct Rust function calls
  • Python wrapper integration
  • Source code + label rendering
  • Multiple severity levels
  • Hierarchical diagnostics
  • Theme switching (Unicode/ASCII)
  • Configurable options

…d miette_py Rust extension for high-quality diagnostic rendering - Implement diagnostic_miette.py Python module with miette integration - Add comprehensive test suite (13 tests) for diagnostic rendering - Support colored/ASCII themes, source code highlighting, and error labels - Configure maturin build system for Rust extension compilation - Maintain fallback rendering when Rust module unavailable Files added/modified: - pyproject.toml: Configure maturin build backend for mixed Python/Rust - guppylang/diagnostic_miette.py: Python wrapper for miette integration - tests/diagnostics/test_diagnostics_miette.py: Comprehensive test suite - guppylang/miette-py/: Complete Rust extension module - Cargo.toml: Rust package configuration - pyproject.toml: Extension build configuration - src/lib.rs: PyO3 bindings for miette diagnostic rendering The new renderer provides: - Unicode/ASCII themed output with ANSI colors - Source code snippets with precise error highlighting - Multiple severity levels (ERROR, WARNING, ADVICE) - Hierarchical diagnostic support (parent/child relationships) - Configurable context lines and custom footers - Full compatibility with existing Guppy diagnostic objects
@idriss-hamadi idriss-hamadi requested a review from a team as a code owner June 10, 2025 15:35
@idriss-hamadi idriss-hamadi requested a review from aborgna-q June 10, 2025 15:35
@aborgna-q aborgna-q requested a review from mark-koch June 10, 2025 16:06
@mark-koch
Copy link
Collaborator

Hi! Thanks for your contribution!

It looks like your code currently doesn't build, see this CI run:

  × Failed to build `guppylang @ file:///home/runner/work/guppylang/guppylang`
  ├─▶ The build backend returned an error
  ╰─▶ Call to `maturin.build_editable` failed (exit status: 1)

      [stdout]
      Running `maturin pep517 build-wheel -i
      /home/runner/work/_temp/setup-uv-cache/builds-v0/.tmptvXFzp/bin/python
      --compatibility off --editable`

      [stderr]
      error: current package believes it's in a workspace when it's not:
      current:
      /home/runner/work/guppylang/guppylang/guppylang/miette-py/Cargo.toml
      workspace: /home/runner/work/guppylang/guppylang/Cargo.toml

      this may be fixable by adding `guppylang/miette-py` to
      the `workspace.members` array of the manifest located at:
      /home/runner/work/guppylang/guppylang/Cargo.toml
      Alternatively, to keep it out of the workspace, add the package to the
      `workspace.exclude` array, or add an empty `[workspace]` table to the
      package's manifest.
      💥 maturin failed
        Caused by: Cargo metadata failed. Does your crate compile with `cargo
      build`?
        Caused by: `cargo metadata` exited with an error:
      Error: command ['maturin', 'pep517', 'build-wheel', '-i',
      '/home/runner/work/_temp/setup-uv-cache/builds-v0/.tmptvXFzp/bin/python',
      '--compatibility', 'off', '--editable'] returned non-zero exit status 1

      hint: This usually indicates a problem with the package or the build
      environment.

Could you fix that, so I can have a closer look and test locally? Try to follow the setup from the existing validator and execute_llvm maturin projects in the repo.

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.

Diagnostics rendering with miette
2 participants