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 🙏

© 2025 – Pkg Stats / Ryan Hefner

codemirror-lang-terraform

v0.1.1

Published

Terraform language support for CodeMirror

Readme

CodeMirror Terraform Language Support

This repository provides a CodeMirror 6 language package for Terraform. It includes:

  • A Lezer grammar for Terraform.
  • Highlighting, indentation, and folding rules specific to Terraform syntax.
  • An easy-to-use extension for CodeMirror 6.

Installation

  1. Clone this repository or install from npm (once published):
    npm install codemirror-lang-terraform
  2. Make sure you have the required CodeMirror 6 packages installed (e.g. @codemirror/language).

Usage

In your CodeMirror setup code, import and include the Terraform language extension:

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

const startState = EditorState.create({
  doc: `# Example Terraform code
resource "aws_instance" "web" {
  ami           = "ami-123456"
  instance_type = "t2.micro"
}`,
  extensions: [basicSetup, terraform()],
});

const view = new EditorView({
  state: startState,
  parent: document.querySelector("#editor"),
});

This will enable Terraform syntax highlighting, indentation, and folding while you edit .tf or .tfvars content.

Development

If you want to develop or modify this language package:

  1. Clone the repository:

    git clone https://github.com/enoreyes/lang-terraform
    cd lang-terraform
  2. Install dependencies:

    npm install
  3. Build the project:

    npm run prepare

    This will use Rollup and the Lezer generator to produce compiled parser files in the dist folder.

  4. Run tests:

    npm test

    Tests are kept in the test directory, where parsing behavior is checked.

Grammar

The Terraform grammar file (src/terraform.grammar) uses Lezer’s grammar syntax to define tokens and parse rules, including interpolation, blocks, attributes, and resource definitions.

Key aspects include:

  • Local token contexts for strings, to properly detect interpolation ("${ ... }").
  • Precedence rules to handle Terraform operators (+, -, *, /, &&, ||, etc.).
  • Nodes for resource, module, provider, data, and other Terraform block types.
  • Special highlight styling for resource/module labels.

Contributing

  • Fork this repo and make a branch for your feature or bugfix.
  • Generate the parser by running npm run prepare and ensure all tests pass with npm test.
  • Submit a pull request with your changes.

License

This project is licensed under the MIT License. Please see the license file for more details.