feat: add M formatting & validation (MCP + /format-m page)#70
Merged
Conversation
Wires @microsoft/powerquery-formatter and @microsoft/powerquery-parser into pqm.guide via two surfaces sharing one library (src/lib/formatter.ts): - MCP tools format_m_code and validate_m_code in /api/mcp for AI clients. - User-facing /format-m page with a textarea, Format/Validate buttons, and syntax-highlighted output (reuses SyntaxBlock). - Supporting /api/format-m endpoint so the page doesn't speak JSON-RPC. Opinionated defaults (4-space indent, Unix newlines, 120 maxWidth) — no formatter knobs in v1. Input handling is native: the formatter accepts both let…in documents and bare expressions, so no cascading parse fallback is needed. Node runtime only (parser isn't Edge-compatible). Attribution to Microsoft added to README and the /format-m page. Four follow-up items added to BACKLOG.md: revisit input handling, enforce formatting in CI, build our own formatter, and explore a BPA-style analyze_m_code tool now that we have an AST. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Exposes a `style: "long" | "short"` arg on formatMCode, the MCP format_m_code tool, the /api/format-m endpoint, and the /format-m page (segmented toggle next to the Format button). - "long" (default, maxWidth=120): Power Query editor style — each step on a single line up to ~120 chars. - "short" (maxWidth=60): spreads parameters of complex function calls onto their own lines for readability, without over-decomposing simple expressions like `each [x] > 1`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@microsoft/powerquery-formatterand@microsoft/powerquery-parserinto pqm.guide via a shared library atsrc/lib/formatter.ts.format_m_codeandvalidate_m_code— so AI clients can clean up or parse-check M code directly./format-mpage (textarea in, syntax-highlighted formatted output, Format + Validate buttons) for humans who want the same thing in a browser./api/format-mendpoint backs the page so it doesn't need to speak JSON-RPC.README.mdand the/format-mpage (both libraries are MIT).Design decisions
let … in …documents and bare expressions directly — no cascading parse fallback needed.Follow-up items added to backlog
format_m_codeinput handling — confirm native handling holds vs. exposing an explicitmodearg.```powerqueryblocks insrc/content/.analyze_m_codetool now that we have an AST.Test plan
npm run typecheckpassesnpm test— all 59 tests pass (8 new for the formatter lib)POST /api/format-m— formatslet x=1,y=2 in x+y→let x = 1, y = 2 in x + yPOST /api/format-maction=validate — returns structured error with line/column forlet x = inPOST /api/mcpformat_m_code— returns fenced```powerqueryblockPOST /api/mcpvalidate_m_code— returns human-readable error summaryGET /format-m— page loads (200)🤖 Generated with Claude Code