@codemirror/language-data
Language metadata and dynamic loading for every language mode in the CodeMirror 6 editor
Repository Health
Technical Analysis
@codemirror/language-data is the language registry for CodeMirror 6. Rather than bundling every language package into your editor, it exposes a single languages array of LanguageDescription objects, one per supported language, each carrying filename/extension matchers and a dynamic import() loader for that language’s actual mode package. This lets an editor offer language auto-detection and a full language picker while only downloading the parser code a user actually needs.
What You Get
- A
languagesarray ofLanguageDescriptionentries covering ~40 languages, ready to feed into a language-picker UI LanguageDescription.matchFilenameandmatchLanguageNamehelpers for auto-detecting a language from a file path or name- Dynamic
import()-based lazy loading so unused language packages never ship to the browser - A single dependency surface that transitively pulls in the full set of official
@codemirror/lang-*packages for convenience installs
Common Use Cases
- Building a browser-based code editor (like an in-browser IDE or playground) that needs to auto-detect a file’s language from its extension
- Populating a ‘change language’ dropdown in a CodeMirror-based editor without manually importing every language package
- Loading syntax highlighting and language support on demand to keep initial bundle size small in a documentation or notebook tool
- Powering multi-language snippet or gist editors where the language isn’t known until runtime
Under The Hood
Architecture The entire package is a single 1,000-line file, src/language-data.ts, that constructs one flat languages array of LanguageDescription.of({...}) calls, each entry pairing a name, filename/extension regex, optional MIME/alias list, and a load function that returns import('@codemirror/lang-x'). There is no runtime logic beyond this declarative table plus the LanguageDescription class it re-exports from @codemirror/language; matching (matchFilename, matchLanguageName) is delegated entirely to that upstream class. Tech Stack Written in TypeScript, built with CodeMirror’s shared @codemirror/buildhelper tool, and shipped as both ESM (dist/index.js) and CJS (dist/index.cjs) with bundled .d.ts types. Its dependencies list every official @codemirror/lang-* package (JSON, Python, Rust, SQL, YAML, etc.) plus @codemirror/legacy-modes, but none of them are imported eagerly — they only load through the dynamic import() inside each entry’s load function. Code Quality There are no dedicated unit tests in this repository; correctness is exercised indirectly via CodeMirror’s shared cm-runtests harness used across the monorepo-like family of @codemirror/* packages. The single source file is consistent and readable — one repeated object-literal pattern per language — which keeps the risk surface low despite the absence of local tests. API Design The public surface is minimal and ergonomic: import languages and call LanguageDescription.matchFilename(languages, filename) to get a matching description, then .load() to lazily fetch the actual language support. No configuration objects, no build-step wiring, and no boilerplate beyond that one call — the tradeoff is that customizing the language list (adding a custom language) means constructing your own LanguageDescription array rather than extending this one.
Used by 12 apps in this directory
OpenClaw
AI Agents · AI Assistants
An open-source AI assistant that runs on your own hardware and meets you in Discord, Slack, WhatsApp, iMessage, Telegram, and 20+ other channels, with native apps for every major platform.
rowboat
AI Assistants · AI Development
Build, test, and deploy multi-agent AI workflows with a visual editor, RAG data sources, MCP tool integration, and a production-ready REST API.
Sourcebot
AI Code Assistants · Developer Tools · Search
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.