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): keep D whose first colon follows an attribute or comment

Nelson Spenceceb729d8a36b
diff --git a/src/discover/language.c b/src/discover/language.c
index 66de4f4df..0d6d3faca 100644
--- a/src/discover/language.c
+++ b/src/discover/language.c
@@ -1342,7 +1342,9 @@ static bool is_rule_colon(const char *p, bool whole_file) {
* look like paths (contain '/', '\' or '.'); a backslash-escaped space stays
* inside its target. D source fails this: "public:", "@safe:", "extern(C):"
* and "import a.b : c" all have a non-path word or D punctuation before the
- * colon. */
+ * colon. An attribute ('@', as in "@1.0:") or a comment between tokens
+ * ("public/+ +/:") is D even with a '.' or '/' before the colon, so a target
+ * holding either is never dep-info. */
static bool is_dep_rule_line(const char *p, bool whole_file) {
bool in_target = false;
bool path_like = false;
@@ -1359,7 +1361,10 @@ static bool is_dep_rule_line(const char *p, bool whole_file) {
path_like = false;
continue;
}
- if (strchr("(){};=\"',", *p)) {
+ if (strchr("(){};=\"',@", *p)) {
+ return false;
+ }
+ if (*p == '/' && (p[SKIP_ONE] == '*' || p[SKIP_ONE] == '+' || p[SKIP_ONE] == '/')) {
return false;
}
in_target = true;
diff --git a/tests/test_language.c b/tests/test_language.c
index d9d38429f..d93eb0ecb 100644
--- a/tests/test_language.c
+++ b/tests/test_language.c
@@ -878,6 +878,14 @@ TEST(lang_d_source_stays_dlang) {
ASSERT_EQ(disambiguate_d_content("/+ dub.sdl:\n name \"hello\"\n+/\nvoid main() {}\n"),
CBM_LANG_DLANG);
ASSERT_EQ(disambiguate_d_content("enum E : ubyte {\n a,\n}\n"), CBM_LANG_DLANG);
+ /* A float UDA ("@ FloatLiteral") has a '.' before its colon, alone or glued
+ * to a keyword. */
+ ASSERT_EQ(disambiguate_d_content("@1.0:\nvoid f() {}\n"), CBM_LANG_DLANG);
+ ASSERT_EQ(disambiguate_d_content("[email protected]:\nvoid f() {}\n"), CBM_LANG_DLANG);
+ /* A comment between tokens puts a '/' before the colon. */
+ ASSERT_EQ(disambiguate_d_content("public/**/:\nvoid f() {}\n"), CBM_LANG_DLANG);
+ ASSERT_EQ(disambiguate_d_content("public/+ +/:\nvoid f() {}\n"), CBM_LANG_DLANG);
+ ASSERT_EQ(disambiguate_d_content("public//note: x\nvoid f() {}\n"), CBM_LANG_DLANG);
/* Default on doubt: empty or unreadable. */
ASSERT_EQ(disambiguate_d_content(""), CBM_LANG_DLANG);
ASSERT_EQ(cbm_disambiguate_d("/tmp/nonexistent_file_12345.d"), CBM_LANG_DLANG);