Miranda Language Server Protocol for VS CodeWhat is MirandaMiranda is a functional programming language developed by David Turner in the 1980s. It was one of the first functional languages with lazy evaluation and directly influenced the design of Haskell. Miranda files use the Visual Studio Code is a code editor that, by default, does not understand Miranda. It cannot colorize the code, detect errors, or provide navigation tools. This extension solves that by implementing an LSP (Language Server Protocol) server. LSP is a standard protocol that defines how an editor and a server that understands a programming language communicate. This allows the server to work not only in VS Code but also in any other editor compatible with LSP. Before LSP existed, if you wanted language support across multiple editors, you had to implement all the logic separately for each one. With LSP, the editor and the server speak a "common language." The editor handles the interface and the server handles code analysis. When a Main Use CaseThe main actor is the programmer writing Miranda code in VS Code. The central use case is being able to open a Before this extension, VS Code treated Miranda files as plain text with no assistance. The programmer had to memorize the syntax and types, navigate the code manually, and only detect errors by running the interpreter. This extension eliminates that friction, allowing Miranda to be worked on with the same tools available for any modern language. ArchitectureThe architecture is split into two parts:
When the server starts, it declares its capabilities through a function called The libraries used are Technical DecisionsTo keep content synchronized between the editor and the server, LSP offers two strategies: To analyze Miranda code, the server uses regular expressions instead of a formal parser. The traditional solution would be to build an AST (Abstract Syntax Tree), a structured tree representation of the program where each node represents syntactic elements of the language, such as functions, expressions, or types. From that tree, the server could answer questions like "where is this function defined?".
The problem is that no Miranda parser exists for Node.js and developing one from scratch would have implied a much larger project than the LSP server itself. As an alternative, I decided to work directly on the text using regular expressions. For example, to detect function definitions the server checks that a line starts at column 0, begins with a lowercase letter, and contains an Implemented Features1. Syntax HighlightingVS Code does not know Miranda, so code appeared all in the same color. A grammar ( 2. HoverHovering over any keyword or prelude function shows a tooltip with its description and type signature. 3. AutocompletionTyping the first letters of a function or keyword shows suggestions. Autocompletion includes:
4. Signature HelpTyping 5. Error DetectionThe server analyzes code in real time and underlines errors with red or yellow squiggles depending on severity. 6. Go to DefinitionPlacing the cursor over a function name jumps directly to where it is defined. Works for functions in the same file as well as functions defined in other files. 7. Find All ReferencesRight-clicking and selecting Find All References on any function opens a panel with all the lines in the file where that name appears. 8. Rename SymbolRight-clicking and selecting Rename Symbol on a function name, typing the new name, and pressing Enter. The server updates all occurrences at once: the definition, the type signature, and every call site. 9. Code LensAbove each function a gray line shows how many times it is called in the file. 10. Document SymbolsThe Outline panel in the VS Code sidebar lists all functions defined in the file. Clicking any one of them jumps to that line. 11. Format DocumentRight-clicking and selecting Format Document. The server cleans up the file, removes trailing spaces from each line, and normalizes extra blank lines. 12. Code ActionsWhen an error or warning is underlined, a lightbulb icon appears alongside it. Clicking it opens a menu with an action to fix it automatically. 13. Workspace SymbolsPressing Cmd+T opens a symbol search across all files in the project. How to Run It
To compile in watch mode (recompiles automatically on save):
Once compiled, open the Run and Debug panel, select Run Miranda Extension, and click the green play button. This opens a new VS Code window where the extension is already active. Open any MarketplaceThe extension is published on the Visual Studio Code Marketplace and can be installed directly from VS Code by searching for Miranda LSP. ExamplesSee EXAMPLES.md for visual examples of each feature. ContributingSee CONTRIBUTING.md for setup instructions, how to add new LSP features, diagnostics, keywords, and code conventions. AI Tool UsageDuring the development of this project I used Claude Code (claude-sonnet-4-5) as a support tool, mainly to implement the LSP server logic. The generated code was reviewed, adjusted, and extended by me to fit the specific needs of the Miranda language. In all cases the decisions, the extension design, and the final content were my responsibility. |