How to Add Custom Language Support to code-review-graph Without Forking
You can teach code-review-graph to parse any Tree-sitter-compatible language by creating a .code-review-graph/languages.toml file in your project root, which automatically registers new grammars without requiring a fork or rebuild.
The tirth8205/code-review-graph repository is built on a generic Tree-sitter walker that extracts symbols using grammars from the bundled tree-sitter-language-pack. When your target language is missing from the built-in list, the architecture allows you to define it through pure configuration data rather than source code modification.
The Configuration File Strategy
The extension monitors the .code-review-graph/ directory for a file named languages.toml. This declarative configuration maps file extensions to Tree-sitter grammars and defines the node types representing functions, classes, imports, and calls.
Required Schema Fields
Each language entry in languages.toml must specify:
- extensions: Array of file extensions associated with the language
- grammar: The Tree-sitter grammar name as shipped with the language pack
- function_node_types: AST node types representing function definitions
- class_node_types: AST node types representing class or type definitions
- import_node_types: AST node types for import statements
- call_node_types: AST node types for function calls
The generic walker consumes this configuration at runtime to populate the language column in the SQLite nodes table, as defined in GraphNode.language at code-review-graph-vscode/src/backend/sqlite.ts (lines 62-63).
Example: Adding Erlang Support
Create .code-review-graph/languages.toml in your project root with the following content:
[languages.erlang]
extensions = [".erl"]
grammar = "erlang"
function_node_types = ["function_clause"]
class_node_types = ["record_decl"]
import_node_types = ["import_attribute"]
call_node_types = ["call"]
Place this file at the repository root. The extension detects changes automatically and reloads the configuration without restarting.
Runtime Integration and Verification
Once the configuration file is present, the system integrates the new language immediately across all platforms.
Automatic Reloading
The file watcher monitors .code-review-graph/languages.toml for changes. When you save the file, the extension reloads the grammar mappings instantly. No rebuild or restart is required for VS Code, CLI, or CI environments.
Database Schema Integration
The walker stores the language identifier in the SQLite backend. According to the source code in code-review-graph-vscode/src/backend/sqlite.ts (lines 380-386), you can verify registration by querying the aggregated language statistics:
// Assuming reader is an instance of SqliteReader
const stats = await reader.getStats();
console.log('Languages in the graph:', stats.languages);
// Output includes: ["python", "javascript", "erlang"]
This array is populated from the distinct values in the language column of the nodes table, confirming your custom language is now part of the graph.
CLI Execution
To rebuild the graph with your new language support, run:
code-review-graph build
The command re-parses the repository using the updated configuration. No additional flags or compilation steps are necessary.
Key Source Files
Reference these implementation details when configuring custom languages:
docs/CUSTOM_LANGUAGES.md— Complete schema documentation, validation rules, and worked examples.code-review-graph-vscode/src/backend/sqlite.ts(lines 62-63) — Defines theGraphNode.languageproperty that stores your custom identifier in the SQLite database.code-review-graph-vscode/src/backend/sqlite.ts(lines 380-386) — Contains the aggregation query that populatesstats.languagesfor verification.
Summary
- Drop a TOML file: Create
.code-review-graph/languages.tomlto register new languages without touching source code. - Map node types: Define AST node names for functions, classes, imports, and calls that match your Tree-sitter grammar.
- Auto-reload: Changes take effect immediately across VS Code, CLI, and CI workflows.
- Universal support: Downstream features like blast-radius analysis and MCP-based context delivery automatically understand the new language.
Frequently Asked Questions
Do I need to install Tree-sitter grammars separately?
No. The code-review-graph extension bundles the tree-sitter-language-pack, which includes pre-compiled grammars for dozens of languages. As long as your target grammar exists in this pack, referencing it by name in languages.toml is sufficient. You only need the grammar name, not a separate installation.
Will custom languages work in VS Code and the CLI simultaneously?
Yes. Because the configuration lives in your repository's .code-review-graph/ directory, both the VS Code extension and the CLI tool read the same languages.toml file. The generic walker implementation ensures consistent behavior across all platforms without platform-specific configuration.
How do I find the correct node types for my language?
You must identify the specific node type names defined by your Tree-sitter grammar. The docs/CUSTOM_LANGUAGES.md file in the repository provides validation rules and debugging techniques. You can also inspect the grammar's node-types.json file or use Tree-sitter's parse inspection tools to discover the exact AST node names for functions, classes, and calls in your target language.
Is forking required if the Tree-sitter grammar isn't in the language pack?
If your target language is not included in the bundled tree-sitter-language-pack, you would need to extend the extension's grammar loading mechanism. However, for any grammar already present in the pack, the languages.toml approach requires zero code changes and zero forks, regardless of whether the language is officially supported in the default configuration.
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 →