What Programming Languages Does CocoIndex Support?
CocoIndex automatically recognizes hundreds of programming languages and markup formats by analyzing file extensions through its Rust-based language detection module.
The cocoindex-io/cocoindex repository maintains a comprehensive language registry that powers syntax-aware text processing capabilities. Understanding what programming languages CocoIndex supports enables developers to leverage automatic language identification for intelligent code chunking, parsing, and analysis pipelines.
Language Detection Architecture
CocoIndex implements language detection through a static registry compiled into the Rust core, exposing functionality to Python via PyO3 bindings.
The Static Registry in prog_langs.rs
The central authority for supported languages resides in rust/ops_text/src/prog_langs.rs. This module defines LANGUAGE_INFO_BY_NAME, a thread-safe static map populated at compile time:
static LANGUAGE_INFO_BY_NAME: LazyLock<HashMap<…, Arc<ProgrammingLanguageInfo>>> =
LazyLock::new(|| {
let mut map = HashMap::new();
// Series of add() calls registering each language
// e.g., add("rust", &[".rs", "rs"], Some(TreeSitterLanguageInfo::new(...)))
map
});
Each language entry registers via the add() helper, specifying the canonical name, valid file extensions, and optional Tree-sitter grammar configurations. The registry contains approximately 250 entries covering mainstream and niche programming languages.
Core Detection Logic
Language identification occurs through two primary functions in prog_langs.rs (lines 14-30):
get_language_info(name)– Performs case-insensitive HashMap lookups against the static registrydetect_language(filename: &str) -> Option<&str>– Extracts the extension usingrfind('.')and delegates toget_language_info
If the extension matches a registered language, the function returns the canonical language name (e.g., "python"); otherwise, it returns None.
Python API Bindings
The Rust detection logic exposes functionality to Python through rust/py/src/ops.rs:
pub fn detect_code_language(filename: &str) -> Option<String> {
prog_langs::detect_language(filename).map(|s| s.to_string())
}
This function registers in rust/py/src/lib.rs via PyO3's wrap_pyfunction macro, making it available as cocoindex.ops.detect_code_language(). The Python wrapper maintains the same semantics: it returns a language string or None for unrecognized extensions.
Supported Programming Languages and File Extensions
CocoIndex recognizes languages by their file extensions and common aliases. While the complete list spans roughly 250 entries in the source, representative supported languages include:
| Language | Recognized Extensions |
|---|---|
| Rust | .rs, rs |
| Python | .py, .pyw, .pyi, .pyx, .pxd, .pxi |
| JavaScript | .js, .cjs, .mjs, js |
| TypeScript | .ts, ts |
| C / C++ | .c, .h, .cpp, .hpp, c++ |
| C# | .cs, cs, c# |
| Java | .java, .jav, .jsh |
| Go | .go, golang |
| Kotlin | .kt, .ktm, .kts |
| Swift | .swift |
| Ruby | .rb |
| PHP | .php |
| Julia | .jl |
| Scala | .scala |
| Haskell | .hs, .hs-boot, .hsc |
| HTML | .html, .htm, .xhtml |
| Markdown | .md, .markdown, .mdx |
| SQL | .sql |
| YAML / TOML | .yaml, .yml, .toml |
| Svelte | .svelte |
| Vue | .vue |
| GraphQL | .graphql, .gql |
| Dockerfile | Dockerfile, .dockerfile |
| Makefile | .mk, Makefile |
Each entry optionally includes a Tree-sitter grammar reference, enabling syntax-aware chunking capabilities in rust/ops_text/src/recursive.rs.
Practical Usage Examples
Detecting Languages from Filenames
Use the Python API to identify programming languages programmatically:
from cocoindex import ops
# Returns canonical language identifiers
print(ops.detect_code_language("main.rs")) # → "rust"
print(ops.detect_code_language("script.py")) # → "python"
print(ops.detect_code_language("app.ts")) # → "typescript"
print(ops.detect_code_language("styles.css")) # → "css"
print(ops.detect_code_language("unknown.xyz")) # → None
Enabling Syntax-Aware Text Splitting
CocoIndex leverages automatic language detection for intelligent code chunking:
from cocoindex import ops, RecursiveSplitter
# Configure splitter with auto-detection (language=None)
splitter = RecursiveSplitter(chunk_size=500, language=None)
# Process mixed file types
files = ["src/main.rs", "README.md", "config.yaml"]
# Internal implementation calls detect_code_language()
# to select appropriate Tree-sitter grammars for each file
The RecursiveSplitter internally invokes detect_code_language to match file extensions against the registry, applying language-specific parsing rules when Tree-sitter grammars are available.
Summary
- CocoIndex supports hundreds of programming languages through a static registry defined in
rust/ops_text/src/prog_langs.rs - Language detection relies on
detect_language(), which maps file extensions to canonical language names using a case-insensitive HashMap lookup - Python developers access detection via
cocoindex.ops.detect_code_language(filename), a thin PyO3 wrapper around the Rust implementation - Each registry entry may include Tree-sitter grammar metadata, enabling syntax-aware chunking for supported languages
- Unrecognized file extensions return
None, allowing graceful fallback to language-agnostic processing
Frequently Asked Questions
How many programming languages does CocoIndex support?
CocoIndex recognizes approximately 250 programming languages and markup formats, ranging from mainstream languages like Python, JavaScript, and Rust to specialized formats like Svelte, GraphQL, and various configuration file syntaxes. The complete authoritative list resides in the static initialization block of rust/ops_text/src/prog_langs.rs.
What file attributes does CocoIndex use to detect programming languages?
CocoIndex detects languages exclusively through file extensions. The detect_language() function extracts the substring after the final period using rfind('.') and performs a lookup in the LANGUAGE_INFO_BY_NAME registry. Both standard extensions (.py) and common aliases (py) are supported for many languages.
Can I use CocoIndex language detection without Tree-sitter support?
Yes. While many registry entries include optional TreeSitterLanguageInfo for syntax-aware parsing, the detect_language() function operates independently of Tree-sitter grammars. You can identify file types for organizational or routing purposes even when Tree-sitter chunking is not required.
How do I check if a specific file type is supported by CocoIndex?
Import the detection function and test your specific filename or extension:
from cocoindex import ops
result = ops.detect_code_language("my_file.xyz")
# Returns the language string if supported, None otherwise
If the function returns None, the extension is not registered in the current version's language map. You can also inspect the source file rust/ops_text/src/prog_langs.rs to verify whether specific extensions appear in the add() calls within the static initialization code.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →