Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Miranda FormatterNew to Visual Studio Code? Get it now.
Miranda Formatter

Miranda Formatter

Pablo Koziolas

| (0) | Free
Conservative formatter for the Miranda functional language: aligns guards, normalizes spaces, and cleans up style while respecting the offside rule.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Miranda Formatter

A formatter for the Miranda functional programming language in Visual Studio Code. It applies a set of conservative style transformations: it cleans up and normalizes your code without risking the language's layout-sensitive semantics (the offside rule).

What it does

  • Aligns guarded equations. Each alternative = rhs, if cond is moved to the column of the first =, and the if / otherwise guards are aligned into a single column. This is the core use case and the most Miranda-specific feature:

    Before:

    gcd a b = gcd (a-b) b, if a>b
    = gcd a (b-a), if a<b
    = a, if a=b
    

    After:

    gcd a b = gcd (a-b) b, if a>b
            = gcd a (b-a), if a<b
            = a,           if a=b
    
  • Normalizes comment spacing (||text becomes || text).

  • One space after each comma (outside strings and comments).

  • Normalizes :: spacing in type signatures (without touching ::= in algebraic data types).

  • Converts tabs to spaces, trims trailing whitespace, and collapses consecutive blank lines.

Conservative by design (offside rule)

Miranda uses layout (indentation) to delimit blocks such as where clauses, equation alternatives, and multi-line expressions. Reindenting blindly can change a program's meaning, so the formatter:

  • Never reindents where blocks or multi-line expressions.
  • Only changes the indentation of continuation lines that start with = (the alternatives of a guarded equation), which is safe and matches the language's canonical style.
  • Never touches the contents of strings, character literals, or comments.

Formatting is idempotent: running it twice produces the same result.

Usage

  1. Open a Miranda file (.m, .mira, or .mir), or set the document language to Miranda.
  2. Run Format Document (Shift+Alt+F) or format a selection.
  3. Optionally enable Format On Save.

Note: VS Code also associates .m with Objective-C. If your file uses .m, pick the Miranda language mode in the status bar.

Settings

Setting Default Description
mirandaFormatter.alignGuards true Align alternatives and guards.
mirandaFormatter.normalizeCommentSpacing true Space after ||.
mirandaFormatter.spaceAfterComma true Space after commas.
mirandaFormatter.normalizeTypeSignatureSpacing true Spacing around ::.
mirandaFormatter.convertTabsToSpaces true Tabs to spaces.
mirandaFormatter.indentSize 2 Spaces per tab.
mirandaFormatter.trimTrailingWhitespace true Trim end of line.
mirandaFormatter.maxConsecutiveBlankLines 1 Max blank lines in a row.

Development

npm install
npm run compile
npm test

The formatting logic lives in src/core/ and does not depend on the VS Code API, so it can be unit-tested in isolation. src/extension.ts only wires that logic to the editor's formatting providers.

License

MIT.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft