mjdi docsv0.10.0latest
IDE integration starter (P1-11)
mjdi's diagnostics are plain text with a stable shape — the mjdi:
Source: mjdi/docs/ide-integration.md
mjdi's diagnostics are plain text with a stable shape — the mjdi:
prefix, names of the offending types, and (for runtime diagnostics) the
embedded stable ID. This page documents the language-server-agnostic
foundation built around that shape. It is a starter: full IDE
integration needs compiler tooling the supported Mojo 1.2.0 toolchain
does not expose (no language-server hooks, no structured diagnostic
output channel), and mjdi does not claim more than it delivers.
The pieces
| Piece | File | What it is |
|---|---|---|
| Diagnostic catalog | diagnostics/catalog.json | The machine-readable quick-fix catalog: stable IDs, severities, stages, message patterns, causes, quick fixes, documentation URLs, example bad/corrected snippets — generated from the library sources by scripts/gen_diagnostics.py. |
| Catalog schema | diagnostics/schema.json | The JSON Schema editors and CI tooling validate the catalog against. |
| Problem matchers | ide/problem-matchers.json | GitHub Actions problem matchers: turn mjdi: compile-time constraint failures and runtime errors into workflow annotations. |
| Editor example | ide/vscode-example/tasks.json | A VS Code tasks.json whose problemMatcher surfaces mjdi compile-time diagnostics as editor problems, mapped to the catalog by message text. |
Consuming the catalog
import json, sys
catalog = json.load(open("diagnostics/catalog.json"))
for entry in catalog["diagnostics"]:
if entry["message_pattern"].startswith("mjdi: re-entrant resolution"):
print(entry["id"], "->", entry["quick_fix"])
The catalog is drift-checked: scripts/gen_diagnostics.py --check
(CI) fails when the checked-in catalog is not what the library sources
produce — every message builder in mjdi/errors.mojo must have an
entry, and every entry must reference a real builder or a documented
runtime contract.
The example editor integration
Copy the task object from ide/vscode-example/tasks.json into your
application's .vscode/tasks.json. Building or running through the
task turns every mjdi compile-time diagnostic into a squiggle at the
reported file/line, with the message inline. The catalog's
message_pattern is the join key for looking up the quick fix and the
documentation link (the runtime messages embed their diagnostic ID —
for example [diagnostic MJDI-R003] — so runtime errors are joinable
by ID too).
CI annotations
- name: Annotate mjdi diagnostics
run: echo "::add-matcher::ide/problem-matchers.json"
- name: Build and test
run: pixi run bash scripts/run_tests.sh
The boundary (documented, not hidden)
- The toolchain emits compile-time diagnostics through the build log only; there is no structured channel (JSON-RPC, SARIF) or language server to plug into, so editor integration is problem-matcher based.
- Runtime diagnostics are raised
Errors: they surface in test/program output with their stable IDs, which the catalog maps to quick fixes. - The catalog's
coverage_noteslist the deliberate non-diagnostics (for example, resolution-after-closure — impossible by ownership, see Container guard) so tooling does not wait for messages that will never come.
Related
- Diagnostics — the diagnostic reference with exact message texts.
- Testing — asserting runtime diagnostics in tests
(
assert_resolve_fails_with).