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-powershell

v1.0.2

Published

PowerShell language support for CodeMirror

Readme

PowerShell language support for CodeMirror

NPM Version

This package gives the CodeMirror 6 editor a Lezer grammar for PowerShell, with highlighting, indentation, folding and completion. It is written for the online editor of Exercism's PowerShell track.

To keep the package working on the Exercism website, don't change the versions of these packages:

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

Install

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

Usage

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

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

powershell() includes the completion. The package also exports powershellLanguage, the completion source on its own, and the lists the completion uses (keywords, cmdlets, automaticVariables, types, operators and snippets).

What the completion offers

  • Keywords, common cmdlets such as Write-Output and ForEach-Object, and snippets for a function with a param block, if/elseif/else, foreach, for, while, do/until, switch, try/catch, class and enum.
  • Automatic variables such as $_, $PSItem and $args.
  • The functions, variables and parameters declared in the file. A variable assigned inside a function or script block is offered inside that function or block and nowhere else.
  • Types and attributes inside [, including the classes and enums declared in the file.
  • After $this., the members of the class. After [Name]::, the static members of a class or the members of an enum.
  • Operators such as -eq and -like after a dash in an expression.

It offers nothing inside comments or single-quoted strings. Inside a double-quoted string it offers variables after $.

How the grammar reads PowerShell

PowerShell reads a line in one of two modes. A line that starts with a value ($x, 1, "a", (...), [int]) is an expression, and -eq is an operator. A line that starts with a bare word (Get-Item) is a command, and -Path is a parameter. The grammar follows the same rule.

A newline ends a statement wherever the statement can end. A line that ends with |, =, , or an operator carries on to the next line, and so does a line that starts with |, else, elseif, catch or finally. src/tokens.ts makes these decisions.

Keywords and operators are case-insensitive, so Function, IF and -EQ all work.

Known gaps

  • The grammar reads a line that starts with an operator, such as -and, as a new statement. It doesn't join that line to the one before.
  • A here-string is highlighted as one string, without its $variables.
  • The grammar doesn't read a bare word that starts with something other than a letter, such as .\script.ps1 or *.txt, as a command argument.

Development

You need Bun.

  • bun install installs the dependencies.
  • bun run test builds the parser from src/syntax.grammar and runs the tests.
  • bun run prepare builds the package into dist/.
  • bun run dev starts a playground at http://localhost:5173/ (run bun run build:grammar first).

The grammar tests are in test/cases, one file per topic. Each test gives some PowerShell and the tree it should parse to.

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.