Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

Add Mojo language wiring

Anand Aiyer222e97a0760a
diff --git a/internal/cbm/cbm.h b/internal/cbm/cbm.h
index 6b4228131..2cf5dde8a 100644
--- a/internal/cbm/cbm.h
+++ b/internal/cbm/cbm.h
@@ -170,6 +170,7 @@ typedef enum {
CBM_LANG_QML, // Qt QML (Qt Modeling Language — declarative UI + embedded JS)
CBM_LANG_CFSCRIPT, // CFML script dialect (.cfc components — Lucee/ColdFusion)
CBM_LANG_CFML, // CFML tag dialect (.cfm templates — Lucee/ColdFusion)
+ CBM_LANG_MOJO, // Mojo
CBM_LANG_COUNT
} CBMLanguage;
diff --git a/internal/cbm/lang_specs.c b/internal/cbm/lang_specs.c
index e7c97fcc0..e328e8d88 100644
--- a/internal/cbm/lang_specs.c
+++ b/internal/cbm/lang_specs.c
@@ -164,6 +164,7 @@ extern const TSLanguage *tree_sitter_apex(void);
extern const TSLanguage *tree_sitter_soql(void);
extern const TSLanguage *tree_sitter_sosl(void);
extern const TSLanguage *tree_sitter_pine(void);
+extern const TSLanguage *tree_sitter_mojo(void);
// -- Empty sentinel --
static const char *empty_types[] = {NULL};
@@ -1596,6 +1597,21 @@ static const char *pine_var_types[] = {"variable_definition_statement",
static const char *pine_branch_types[] = {"if_statement", "switch_statement", "for_statement",
"for_in_statement", "while_statement", NULL};
static const char *pine_assign_types[] = {"reassignment_statement", NULL};
+static const char *mojo_func_types[] = {"function_definition", NULL};
+static const char *mojo_class_types[] = {"class_definition", "trait_definition", NULL};
+static const char *mojo_module_types[] = {"module", NULL};
+static const char *mojo_call_types[] = {"call", NULL};
+static const char *mojo_import_types[] = {"import_statement", "import_from_statement",
+ "future_import_statement", NULL};
+static const char *mojo_branch_types[] = {"if_statement",
+ "match_statement",
+ "for_statement",
+ "while_statement",
+ "try_statement",
+ "with_statement",
+ NULL};
+static const char *mojo_var_types[] = {"assignment", NULL};
+static const char *mojo_assign_types[] = {"assignment", "augmented_assignment", NULL};
// ==================== SPEC TABLE ====================
static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
@@ -2571,6 +2587,12 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
pine_branch_types, pine_var_types, pine_assign_types, empty_types, NULL,
empty_types, NULL, NULL, tree_sitter_pine, NULL},
+ // CBM_LANG_MOJO
+ [CBM_LANG_MOJO] = {CBM_LANG_MOJO, mojo_func_types, mojo_class_types, empty_types,
+ mojo_module_types, mojo_call_types, mojo_import_types, mojo_import_types,
+ mojo_branch_types, mojo_var_types, mojo_assign_types, empty_types, NULL,
+ empty_types, NULL, NULL, tree_sitter_mojo, NULL},
+
};
_Static_assert(sizeof(lang_specs) / sizeof(lang_specs[0]) == CBM_LANG_COUNT,
diff --git a/src/discover/language.c b/src/discover/language.c
index 917651d13..65b3cf0ce 100644
--- a/src/discover/language.c
+++ b/src/discover/language.c
@@ -187,6 +187,9 @@ static const ext_entry_t EXT_TABLE[] = {
/* Meson */
{".meson", CBM_LANG_MESON},
+ /* Mojo */
+ {".mojo", CBM_LANG_MOJO},
+
/* Nix */
{".nix", CBM_LANG_NIX},
@@ -835,6 +838,7 @@ static const char *LANG_NAMES[CBM_LANG_COUNT] = {
[CBM_LANG_APEX] = "Apex",
[CBM_LANG_SOQL] = "SOQL",
[CBM_LANG_SOSL] = "SOSL",
+ [CBM_LANG_MOJO] = "Mojo",
};
diff --git a/src/discover/userconfig.c b/src/discover/userconfig.c
index 7c606f912..f533edd0e 100644
--- a/src/discover/userconfig.c
+++ b/src/discover/userconfig.c
@@ -118,6 +118,7 @@ static const lang_name_entry_t LANG_NAME_TABLE[] = {
{"glsl", CBM_LANG_GLSL},
{"ini", CBM_LANG_INI},
{"matlab", CBM_LANG_MATLAB},
+ {"mojo", CBM_LANG_MOJO},
{"lean", CBM_LANG_LEAN},
{"form", CBM_LANG_FORM},
{"magma", CBM_LANG_MAGMA},
diff --git a/tests/test_grammar_labels.c b/tests/test_grammar_labels.c
index 21f1a4704..b592e3285 100644
--- a/tests/test_grammar_labels.c
+++ b/tests/test_grammar_labels.c
@@ -151,6 +151,7 @@ static const LabelGolden LABEL_GOLDENS[] = {
{"func", "Function:1,Module:1"},
{"lean", "Function:2,Module:1"},
{"move", "Function:1,Module:1"},
+ {"mojo", "Class:1,Function:1,Method:1,Module:1"},
{"smali", "Class:1,Function:1,Module:1"},
{"systemverilog", "Class:1,Function:1,Module:1"},
{"verilog", "Class:1,Module:1"},
diff --git a/tests/test_grammar_regression.c b/tests/test_grammar_regression.c
index b578fc0b0..5f698c103 100644
--- a/tests/test_grammar_regression.c
+++ b/tests/test_grammar_regression.c
@@ -196,6 +196,12 @@ const GrammarCase CBM_GRAMMAR_CASES[] = {
"module 0x1::m {\n public fun foo() {}\n}\n",
1,
{"foo", NULL}},
+ {"mojo",
+ CBM_LANG_MOJO,
+ "a.mojo",
+ "fn foo() -> Int:\n return 1\n\nstruct A:\n fn bar(self) -> Int:\n return foo()\n",
+ 2,
+ {"foo", "A", NULL}},
{"smali",
CBM_LANG_SMALI,
"A.smali",
diff --git a/tests/test_language.c b/tests/test_language.c
index 4b1fe4453..fe2497a5e 100644
--- a/tests/test_language.c
+++ b/tests/test_language.c
@@ -956,6 +956,11 @@ TEST(lang_ext_move) {
PASS();
}
+TEST(lang_ext_mojo) {
+ ASSERT_EQ(cbm_language_for_extension(".mojo"), CBM_LANG_MOJO);
+ PASS();
+}
+
TEST(lang_ext_squirrel) {
ASSERT_EQ(cbm_language_for_extension(".nut"), CBM_LANG_SQUIRREL);
PASS();
@@ -1271,6 +1276,7 @@ SUITE(language) {
RUN_TEST(lang_ext_ispc);
RUN_TEST(lang_ext_cairo);
RUN_TEST(lang_ext_move);
+ RUN_TEST(lang_ext_mojo);
RUN_TEST(lang_ext_squirrel);
RUN_TEST(lang_ext_func);
RUN_TEST(lang_ext_rst);