Skip to content

Commit ceb729d

Browse files
fix(discover): keep D whose first colon follows an attribute or comment
is_dep_rule_line took any '.' or '/' before the rule colon as a path, so valid D such as "@1.0:" (a float UDA) and "public/**/:" (a comment between tokens) was dropped as dep-info. A target holding '@' or a comment opener ("/*", "/+", "//") is now D. Over 12,062 real D files and 4,494 real files under deps/ dirs, no classification changes. A dep-info file whose target path contains '@' now stays D, as it does on main. Signed-off-by: Nelson Spence <nelson@projectnavi.ai>
1 parent 9140e7d commit ceb729d

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎src/discover/language.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,9 @@ static bool is_rule_colon(const char *p, bool whole_file) {
13421342
* look like paths (contain '/', '\' or '.'); a backslash-escaped space stays
13431343
* inside its target. D source fails this: "public:", "@safe:", "extern(C):"
13441344
* and "import a.b : c" all have a non-path word or D punctuation before the
1345-
* colon. */
1345+
* colon. An attribute ('@', as in "@1.0:") or a comment between tokens
1346+
* ("public/+ +/:") is D even with a '.' or '/' before the colon, so a target
1347+
* holding either is never dep-info. */
13461348
static bool is_dep_rule_line(const char *p, bool whole_file) {
13471349
bool in_target = false;
13481350
bool path_like = false;
@@ -1359,7 +1361,10 @@ static bool is_dep_rule_line(const char *p, bool whole_file) {
13591361
path_like = false;
13601362
continue;
13611363
}
1362-
if (strchr("(){};=\"',", *p)) {
1364+
if (strchr("(){};=\"',@", *p)) {
1365+
return false;
1366+
}
1367+
if (*p == '/' && (p[SKIP_ONE] == '*' || p[SKIP_ONE] == '+' || p[SKIP_ONE] == '/')) {
13631368
return false;
13641369
}
13651370
in_target = true;

‎tests/test_language.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,14 @@ TEST(lang_d_source_stays_dlang) {
878878
ASSERT_EQ(disambiguate_d_content("/+ dub.sdl:\n name \"hello\"\n+/\nvoid main() {}\n"),
879879
CBM_LANG_DLANG);
880880
ASSERT_EQ(disambiguate_d_content("enum E : ubyte {\n a,\n}\n"), CBM_LANG_DLANG);
881+
/* A float UDA ("@ FloatLiteral") has a '.' before its colon, alone or glued
882+
* to a keyword. */
883+
ASSERT_EQ(disambiguate_d_content("@1.0:\nvoid f() {}\n"), CBM_LANG_DLANG);
884+
ASSERT_EQ(disambiguate_d_content("nothrow@1.0:\nvoid f() {}\n"), CBM_LANG_DLANG);
885+
/* A comment between tokens puts a '/' before the colon. */
886+
ASSERT_EQ(disambiguate_d_content("public/**/:\nvoid f() {}\n"), CBM_LANG_DLANG);
887+
ASSERT_EQ(disambiguate_d_content("public/+ +/:\nvoid f() {}\n"), CBM_LANG_DLANG);
888+
ASSERT_EQ(disambiguate_d_content("public//note: x\nvoid f() {}\n"), CBM_LANG_DLANG);
881889
/* Default on doubt: empty or unreadable. */
882890
ASSERT_EQ(disambiguate_d_content(""), CBM_LANG_DLANG);
883891
ASSERT_EQ(cbm_disambiguate_d("/tmp/nonexistent_file_12345.d"), CBM_LANG_DLANG);

0 commit comments

Comments
 (0)