Skip to content

Add JSON syntax highlighting and a pdb-based JSON debug sandbox

Mike Boyer requested to merge json-tokenize-and-debug-sandbox into main

Two small, independent features -- the two lightest-lift items left on the roadmap.

tokenize() for lint_json.py: JSON's grammar is tiny (strings, numbers, true/false/null, // and /* */ comments for .jsonc), no keyword sets or pending-state tracking needed unlike the other tokenizers. Object keys get "type" kind rather than "string" (via a lookahead for the trailing colon) since JSON's whole structure is key/value pairs and that's worth distinguishing.

JSON "learning sandbox" debugging, from the original roadmap: JSON has no executable lines of its own, so debug_wrapper() generates a tiny synthetic Python script (import json; data=json.load(open(path)); pass) and JsonSandboxSession just points the existing, completely unmodified PdbSession at that instead -- no new session mechanics at all. Two things found by hand-testing rather than assumed: pdb's own output naturally references the wrapper's throwaway temp path throughout, swapped for the real .json path via a full-path string replace (a basename-only replace was tried first and rejected -- it fabricates a path that doesn't exist, pasting the original filename onto the wrapper's /tmp directory); and invalid JSON doesn't dead-end the sandbox at all -- python -m pdb auto-enters post-mortem debugging on the uncaught JSONDecodeError, landing the user in a real, still- useful interactive session for free, no special-casing needed.

Frontend: json added to SESSION_LANGS; since the backend ignores the posted cursor line entirely for JSON, the start/status messages are worded differently for lang==="json" rather than claiming a breakpoint line that isn't real.

Tests: test_tokenize.py covers the JSON tokenizer (keys vs values, literals, .jsonc comments); test_http_server.py exercises a real pdb subprocess through JsonSandboxSession for both the valid-JSON and invalid-JSON (post-mortem) paths. All seven test files pass.

Branch: json-tokenize-and-debug-sandbox.

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

Merge request reports