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.

fix(discover): map .blade.php to Blade by default (#258)

Martin Vogeldb6e99c0ea26
diff --git a/src/discover/language.c b/src/discover/language.c
index c80c2635c..187230ac9 100644
--- a/src/discover/language.c
+++ b/src/discover/language.c
@@ -860,17 +860,31 @@ CBMLanguage cbm_language_for_filename(const char *filename) {
return CBM_LANG_COUNT;
}
- /* Probe user config for compound extensions (e.g. ".blade.php"). */
+ /* Probe compound extensions (e.g. ".blade.php") from the first dot toward
+ * the last. Built-in compounds are checked first so e.g. Laravel Blade
+ * templates map to Blade rather than the single-extension fallback (PHP);
+ * user config can still add more (#258). */
+ static const struct {
+ const char *ext;
+ CBMLanguage lang;
+ } COMPOUND_EXT_TABLE[] = {
+ {".blade.php", CBM_LANG_BLADE},
+ };
const cbm_userconfig_t *ucfg = cbm_get_user_lang_config();
- if (ucfg) {
- const char *p = strchr(filename, '.');
- while (p && p < last_dot) {
+ const char *p = strchr(filename, '.');
+ while (p && p < last_dot) {
+ for (size_t i = 0; i < sizeof(COMPOUND_EXT_TABLE) / sizeof(COMPOUND_EXT_TABLE[0]); i++) {
+ if (strcmp(p, COMPOUND_EXT_TABLE[i].ext) == 0) {
+ return COMPOUND_EXT_TABLE[i].lang;
+ }
+ }
+ if (ucfg) {
CBMLanguage lang = cbm_userconfig_lookup(ucfg, p);
if (lang != CBM_LANG_COUNT) {
return lang;
}
- p = strchr(p + SKIP_ONE, '.');
}
+ p = strchr(p + SKIP_ONE, '.');
}
/* Standard single-extension lookup (built-ins + user overrides). */
diff --git a/tests/test_language.c b/tests/test_language.c
index fbf72bd89..be8fc8b2b 100644
--- a/tests/test_language.c
+++ b/tests/test_language.c
@@ -513,6 +513,16 @@ TEST(lang_fn_vimrc) {
PASS();
}
+/* issue #258: .blade.php is a built-in compound extension → Blade by default
+ * (previously fell through to the single-extension lookup and was mis-typed as
+ * PHP). Plain .php still maps to PHP. */
+TEST(lang_fn_blade_php_compound_issue258) {
+ ASSERT_EQ(cbm_language_for_filename("login.blade.php"), CBM_LANG_BLADE);
+ ASSERT_EQ(cbm_language_for_filename("alert.blade.php"), CBM_LANG_BLADE);
+ ASSERT_EQ(cbm_language_for_filename("index.php"), CBM_LANG_PHP);
+ PASS();
+}
+
/* Filename with extension falls through to extension lookup */
TEST(lang_fn_main_go) {
ASSERT_EQ(cbm_language_for_filename("main.go"), CBM_LANG_GO);
@@ -1160,6 +1170,7 @@ SUITE(language) {
RUN_TEST(lang_fn_meson_opts);
RUN_TEST(lang_fn_meson_opts_txt);
RUN_TEST(lang_fn_vimrc);
+ RUN_TEST(lang_fn_blade_php_compound_issue258);
RUN_TEST(lang_fn_main_go);
RUN_TEST(lang_fn_test_py);
RUN_TEST(lang_fn_unknown);