npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@exercism/codemirror-lang-elm

v1.0.2

Published

Elm language support for CodeMirror

Readme

Elm language support for CodeMirror

NPM Version

This package gives the CodeMirror 6 editor a Lezer grammar for Elm 0.19, with highlighting, indentation, folding and autocompletion. Exercism uses it in the in-browser editor for the Elm track.

⚠️ Keep the versions of these dependencies as they are, so that the package works on the Exercism website:

"@codemirror/language": "^6.10.1",
"@lezer/highlight": "^1.2.0",
"@lezer/lr": "^1.4.0"

Install

  • NPM: npm install @exercism/codemirror-lang-elm
  • Yarn: yarn add @exercism/codemirror-lang-elm
  • Bun: bun add @exercism/codemirror-lang-elm

Usage

import { EditorView, basicSetup } from "codemirror";
import { elm } from "@exercism/codemirror-lang-elm";

new EditorView({
  extensions: [basicSetup, elm()],
  parent: document.body,
});

elm-format indents by four spaces. To match it, add indentUnit.of(" ") from @codemirror/language to the editor's extensions.

What it does

  • It highlights keywords, strings, numbers, comments, declarations, function calls, types, constructors, record fields and operators.
  • It indents a new line under =, ->, let, of, then and else, and folds declarations, let blocks, case expressions, records and lists.
  • Its autocompletion offers:
    • keywords, and snippets for a function with its annotation, case, if, let, a lambda, a custom type, a record type alias, a module header and an import.
    • the names imported into every Elm module by default, such as List, Maybe, Just and modBy.
    • a module's functions, types and constructors after its name and a dot, such as List.map or Dict.insert. This works for elm/core, elm/regex, elm/parser, elm/time, elm/random and elm/json, and for an alias set by import Dict as D.
    • the names exposed by an import, such as insert after import Dict exposing (insert).
    • the names declared in the file that are in scope at the cursor: top-level functions, types and constructors, parameters, and the names bound by let, case and lambdas.
    • record field names after a dot, as in model.count or .count.

How the grammar reads indentation

Elm marks its blocks with indentation, so the grammar can't be written with token rules alone. The layout tokenizer in src/tokens.ts adds three invisible tokens for the grammar to use. One opens a block, one separates its items, and one closes it.

  • The file is a block at column 0, so a line at the left margin starts a new declaration.
  • A let or an of opens a block at the column of the token after it.
  • A line at that column starts the next item, and a line further left closes the block.
  • A block also closes in front of a token that can't go inside it. That is how let x = 1 in x works on one line.

The same file reads nested block comments, the module part of a qualified name such as List. in List.map, and the dot in model.count. A dot written straight after a name reads a field, and a dot with a space in front of it starts an accessor function such as .count.

Prerequisites

Setup

Run bun install to install all dependencies.

Developing

To help with development, run bun run dev. This starts a Vite dev server (usually at http://localhost:5173/) that renders index.html with some sample Elm code.

The grammar is in src/syntax.grammar, the external tokenizers are in src/tokens.ts, and the completion is in src/complete.ts and src/modules.ts.

Testing

Run bun run test. It builds the package and then runs the tests in test/.

  • test/cases/*.txt hold the grammar tests, in Lezer's test format.
  • test/completion.test.ts checks what the completion offers at a given position.
  • test/editor.test.ts checks highlighting, indentation and folding.

Building

Run bun run prepare to build the package into dist/. bun install runs the same command, so a fresh install also builds the package.

Publishing

To publish a new version, set version in package.json and commit it. Then push a tag made of v followed by that version, for example v1.0.0. The tag starts the Publish workflow, which builds and tests the package and publishes it to npm. If the tag differs from version, the workflow stops before it publishes.

Resources