@codemirror/lang-cpp
C++ language support for the CodeMirror 6 code editor, with syntax highlighting, indentation, and code folding.
Repository Health
Technical Analysis
@codemirror/lang-cpp adds C++ language support to the CodeMirror 6 code editor. It wraps the Lezer C++ grammar in an LRLanguage definition, layering on indentation rules for blocks, case labels, and control statements, code folding for declaration lists and block comments, and language data for comment tokens and bracket-closing behavior around C++‘s prefixed string literals (L, u, U, u8, R, and their raw-string variants).
The package exports two symbols: cppLanguage, the underlying language provider, and cpp(), a LanguageSupport wrapper ready to drop into an editor’s extensions array alongside basicSetup. It follows the same minimal, single-purpose pattern as CodeMirror’s other lang-* packages, delegating parsing to a dedicated Lezer grammar so the language module itself stays a thin configuration layer over indentation and folding behavior.
What You Get
- cpp() extension - a ready-made LanguageSupport instance you add directly to an editor’s extensions array
- cppLanguage provider - the underlying LRLanguage definition for building custom language configurations on top of it
- Indentation rules - continued-statement, case-label, and brace-delimited indentation tuned for C++ control flow
- Code folding - folding support for declaration lists, compound statements, enumerator lists, field lists, and block comments
- Prefixed-string awareness - bracket-closing configured for C++‘s L/u/U/u8/R string literal prefixes and raw strings
Common Use Cases
- Embedding a C++ code viewer - documentation sites or admin tools that need read-only, syntax-highlighted C++ snippets
- Building a browser-based C++ IDE - online compilers or coding-exercise platforms that need real indentation and folding while editing C++
- Multi-language code editor - apps built on @codemirror/language-data or a custom language switcher that need a drop-in C++ mode alongside other lang-* packages
- Teaching tools and code playgrounds - interactive tutorials that highlight and format C++ code samples in-browser
Under The Hood
Architecture The entire module is a single file, src/cpp.ts, exporting cppLanguage and cpp(). cppLanguage is built with LRLanguage.define, configuring the imported @lezer/cpp parser with an indentNodeProp map (continuedIndent for IfStatement/TryStatement, flatIndent for LabeledStatement, a computed indent for CaseStatement, delimitedIndent for CompoundStatement) and a foldNodeProp map covering declaration/enumerator/field/initializer lists plus BlockComment. cpp() then wraps that provider in a LanguageSupport instance. There is no layering beyond this: the package is a thin configuration surface over a parser it does not implement itself, and the only thing that would break if the core abstraction (LRLanguage/LanguageSupport from @codemirror/language) changed is this exact configuration call.
Tech Stack Written in TypeScript, published as dual ESM/CJS (dist/index.js and dist/index.cjs) with generated .d.ts/.d.cts typings. Runtime dependencies are @codemirror/language (^6.0.0) for the LRLanguage/LanguageSupport/indentNodeProp/foldNodeProp APIs and @lezer/cpp (^1.0.0) for the actual C++ grammar. The only devDependency is @codemirror/buildhelper, which provides both the build step (cm-buildhelper src/cpp.ts) and the test runner (cm-runtests) shared across CodeMirror’s language packages, so there is no bespoke bundler or test framework configuration in this repo.
Code Quality No test files exist in this repository; testing is delegated to cm-runtests, a shared harness from @codemirror/buildhelper whose fixtures live outside this package, so behavior can’t be verified from this repo alone. No CI workflow file is present in this GitHub mirror (the README notes the canonical repo has moved to a self-hosted Gitea instance, which may host CI separately). The source itself is small, typed, and consistently named, following the same shape as CodeMirror’s other lang-* packages, but the lack of visible tests or CI in this repo is a real gap for auditability.
What Makes It Unique There is nothing novel here beyond the general Lezer/CodeMirror language-extension pattern already established across the ecosystem — this package is valuable for exactly what it is (a maintained, correct C++ mode) rather than for any distinctive technical approach. It’s a standard, well-worn shape: parser dependency in, indentation/folding config out.
Used by 7 apps in this directory
GitButler
Developer Tools · Devops · AI Development
Git, but better — a modern version control client with stacked branches, parallel workflows, unlimited undo, and first-class support for AI-powered development.
LearnHouse
Learning Management · CMS
Open-source LMS with AI tutoring, real-time collaboration boards, live code execution, and built-in course monetization — self-hosted in minutes.
Obot
AI Agents
An open-source MCP platform for organizations — host MCP servers, run MCP registries, monitor usage, and build agents and chatbots on top of the Model Context Protocol from one self-hosted deployment.
OpenViking
Databases · AI Development
An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.
PostgresML
Databases · AI Development
Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.
Sourcebot
Search · Developer Tools · AI Code Assistants
A self-hosted, AI-powered code search engine that indexes every repo across GitHub, GitLab, Bitbucket, Gitea, Gerrit, and Azure DevOps, so both engineers and coding agents can search, browse, and ask questions about your codebase from one place.
superset
AI Code Assistants · AI Development
Orchestrate an army of AI coding agents—Claude Code, Codex, Gemini CLI, and more—running simultaneously in isolated git worktrees from a single Electron desktop app.