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 condis moved to the column of the first=, and theif/otherwiseguards 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=bAfter:
gcd a b = gcd (a-b) b, if a>b = gcd a (b-a), if a<b = a, if a=b -
Normalizes comment spacing (
||textbecomes|| 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
whereblocks 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
- Open a Miranda file (
.m,.mira, or.mir), or set the document language to Miranda. - Run Format Document (
Shift+Alt+F) or format a selection. - Optionally enable Format On Save.
Note: VS Code also associates
.mwith 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.