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

codemirror-lang-rego

v0.1.0

Published

Rego language support for CodeMirror 6

Readme

codemirror-lang-rego

Rego language support for CodeMirror 6, the policy language of Open Policy Agent (OPA).

Features

  • Syntax Highlighting: Full grammar support for Rego, including rules, comprehensions, and every/some quantifiers.
  • Autocomplete: Suggestions for all OPA built-in functions and Rego keywords.
  • Context-Aware Completions: Pass your input and data JSON schemas to get intelligent completions for paths like input.user.roles.
  • Hover Tooltips: Documentation on hover for built-in functions and data paths.
  • Folding & Indentation: Proper code folding for rule bodies, objects, arrays, and sets.

Installation

npm install codemirror-lang-rego

Usage

Basic Setup

import { EditorState } from "@codemirror/state";
import { EditorView, basicSetup } from "codemirror";
import { rego } from "codemirror-lang-rego";

const state = EditorState.create({
  doc: `package example

allow if {
    input.user == "admin"
}`,
  extensions: [basicSetup, rego()],
});

new EditorView({ state, parent: document.body });

With Data Context (Advanced Autocomplete)

Provide JSON schemas for input and data to enable intelligent path completions.

import { rego, regoDataContext, setRegoDataContext } from "codemirror-lang-rego";

const inputSchema = {
  type: "object",
  children: {
    user: { type: "string", example: "alice" },
    roles: {
      type: "array",
      arrayItemType: { type: "string" },
      example: ["admin", "viewer"],
    },
  },
};

const state = EditorState.create({
  extensions: [
    rego(),
    regoDataContext({ input: inputSchema, data: null }),
  ],
});

Now typing input. will suggest user and roles.

Updating Context Dynamically

If your input/data changes at runtime, dispatch an effect to update the context:

import { setRegoDataContext } from "codemirror-lang-rego";

view.dispatch({
  effects: setRegoDataContext.of({
    input: newInputSchema,
    data: newDataSchema,
  }),
});

Configuration Options

rego({
  autocomplete: true, // Enable keyword/built-in completions (default: true)
  hover: true,        // Enable hover tooltips (default: true)
  dataContext: {      // Initial data context (optional)
    input: null,
    data: null,
  },
});

API

rego(config?: RegoConfig): LanguageSupport

Creates the Rego language extension.

| Option | Type | Default | Description | |---------------|-------------------|---------|--------------------------------------------------| | autocomplete| boolean | true | Enable autocomplete for keywords and built-ins. | | hover | boolean | true | Enable hover tooltips. | | dataContext | RegoDataContext | null | Initial schema for input.* and data.* paths.|

regoDataContext(context: RegoDataContext): Extension

Standalone extension to initialize the data context. Use this if you want to separate the context from the main rego() call.

setRegoDataContext: StateEffect<RegoDataContext>

Dispatch this effect to update the data context on a live editor.

regoLanguage: LRLanguage

The raw Lezer-based LRLanguage instance, if you need low-level access.

RegoDataContext

interface RegoDataContext {
  input: SchemaNode | null;
  data: SchemaNode | null;
}

interface SchemaNode {
  type: "object" | "array" | "string" | "number" | "boolean" | "null";
  children?: Record<string, SchemaNode>;
  arrayItemType?: SchemaNode;
  example?: unknown;
  source?: string;
}

Schema Format

The SchemaNode format is a simple tree structure:

{
  "type": "object",
  "children": {
    "user": { "type": "string", "example": "alice" },
    "attributes": {
      "type": "object",
      "children": {
        "department": { "type": "string", "example": "engineering" }
      }
    }
  }
}
  • type: The JSON type of the node.
  • children: For objects, a map of property names to child nodes.
  • arrayItemType: For arrays, the schema of array items.
  • example: An example value shown in tooltips.
  • source: Optional label (e.g., "OIDC Token") for documentation.

Built-in Functions

This package includes OPA's built-in function definitions (from capabilities.json), providing autocomplete and hover docs for functions like count, startswith, json.marshal, etc.

Grammar

The Rego grammar is implemented using Lezer, CodeMirror's incremental parser system. It supports:

  • Package and import declarations
  • Complete, partial, and function rules
  • if/else chains
  • some/every quantifiers
  • Comprehensions (set, array, object)
  • All operators and literals

License

MIT

Contributing

Contributions are welcome! Please open an issue or pull request.

Acknowledgments

Created by Maynframe (https://maynframe.xyz). Built on CodeMirror, Lezer, and OPA.