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.

doc-links(cs): a props or targets file that does not parse up to its root is unknown (R6)

Martin Vogelba529c9529ec
diff --git a/internal/cbm/doclink_cs.c b/internal/cbm/doclink_cs.c
index db09f6182..57780da9c 100644
--- a/internal/cbm/doclink_cs.c
+++ b/internal/cbm/doclink_cs.c
@@ -3707,8 +3707,8 @@ const char *cbm_doclink_cs_project_scan_scope(CBMExtractCtx *ctx) {
return blob;
}
/* a *.csproj marks its directory as a C# project even when it cannot be
- * read; a *.props or *.targets file has a blob only as an MSBuild
- * <Project> */
+ * read; a *.props or *.targets file has no blob only when it parses up to
+ * a root element that is not an MSBuild <Project> */
csx_scan_t p = {
.x = {.src = ctx->source, .n = ctx->source_len > 0 ? (uint32_t)ctx->source_len : 0},
.out = {.a = ctx->arena},
@@ -3719,6 +3719,7 @@ const char *cbm_doclink_cs_project_scan_scope(CBMExtractCtx *ctx) {
p.x.i = 3;
}
bool is_project = false;
+ bool other_root = false; /* XML whose root element is not <Project> */
bool bad = false;
csx_tok_t t;
for (;;) {
@@ -3751,6 +3752,7 @@ const char *cbm_doclink_cs_project_scan_scope(CBMExtractCtx *ctx) {
break;
}
if (!csx_is(&p.x, t.name, "Project")) {
+ other_root = true;
break; /* XML, but no MSBuild file */
}
is_project = true;
@@ -3762,7 +3764,12 @@ const char *cbm_doclink_cs_project_scan_scope(CBMExtractCtx *ctx) {
}
}
cs_cost_add(p.x.i, 0);
- if ((bad && (is_project || named_project)) || (!is_project && named_project)) {
+ /* What the scan could not read is unknown, not absent: a file malformed
+ * anywhere or ending before its root, and a *.csproj that is no MSBuild
+ * <Project>. With no blob, an import of such a file would count as one
+ * outside the repository, and as the nearest Directory.Build.* it would
+ * be passed over for the one above, which MSBuild does not read. */
+ if (bad || (!is_project && (named_project || !other_root))) {
p.out.len = 0;
sb_puts(&p.out, CBM_DOCLINK_CS_SCOPE_TAG "\nP\t\t!\n");
} else if (!is_project) {
diff --git a/tests/test_doc_mentions.c b/tests/test_doc_mentions.c
index 9c9946d4d..9e1bee8f0 100644
--- a/tests/test_doc_mentions.c
+++ b/tests/test_doc_mentions.c
@@ -9698,6 +9698,45 @@ TEST(doc_mentions_msbuild_unread_project_opens) {
PASS();
}
+/* R6: a *.props or *.targets file that does not parse up to its root is not
+ * read either: what it holds is unknown. As the nearest Directory.Build.props
+ * it is the one MSBuild reads, so the scope of its project is open (a simple
+ * name found nowhere is external) and the usable file further up is not
+ * applied (its `Using Include="Lib"` imports nothing here). Decoy: a project
+ * with no nearer file reads the upper one (Gadget binds through it, a name
+ * found nowhere is missing). */
+TEST(doc_mentions_msbuild_malformed_props_opens) {
+ const dm_source_t files[] = {
+ {"Directory.Build.props", "<Project><ItemGroup><Using Include=\"Lib\"/></ItemGroup>"
+ "</Project>\n"},
+ {"a/Directory.Build.props", "<\n<Project><ItemGroup><Using Include=\"Hidden\"/>"
+ "</ItemGroup></Project>\n"},
+ {"a/A.csproj", DM_EMPTY_PROJECT},
+ {"a/Thing.cs", "namespace Lib\n{\n public class Thing { }\n}\n"},
+ {"a/UsesA.cs", "namespace App\n"
+ "{\n"
+ " /// <summary><see cref=\"Thing\"/> <see cref=\"NowhereA\"/></summary>\n"
+ " public class UsesA { }\n"
+ "}\n"},
+ {"c/C.csproj", DM_EMPTY_PROJECT},
+ {"c/Gadget.cs", "namespace Lib\n{\n public class Gadget { }\n}\n"},
+ {"c/UsesC.cs",
+ "namespace App\n"
+ "{\n"
+ " /// <summary><see cref=\"Gadget\"/> <see cref=\"NowhereC\"/></summary>\n"
+ " public class UsesC { }\n"
+ "}\n"},
+ };
+ static const dm_want_t wants[] = {
+ {"a/UsesA.cs", "NowhereA", "UsesA.UsesA", NULL, "external", NULL, NULL},
+ {"a/UsesA.cs", "Thing", "UsesA.UsesA", NULL, "external", "Thing.Thing", NULL},
+ {"c/UsesC.cs", "Gadget", "UsesC.UsesC", "Gadget.Gadget", NULL, NULL, NULL},
+ {"c/UsesC.cs", "NowhereC", "UsesC.UsesC", NULL, "missing", NULL, NULL},
+ };
+ ASSERT_EQ(dm_check_repo("malformed_props", files, DM_COUNT(files), wants, DM_COUNT(wants)), 0);
+ PASS();
+}
+
enum { DM_BIG_MEMBERS = 20000, DM_SMALL_FILES = 200 };
/* What the resolver looks at to build its index over one file of
@@ -10275,6 +10314,7 @@ SUITE(doc_mentions) {
RUN_TEST(doc_mentions_cs_stored_scope_nesting);
RUN_TEST(doc_mentions_index_status_unknown_reason);
RUN_TEST(doc_mentions_msbuild_unread_project_opens);
+ RUN_TEST(doc_mentions_msbuild_malformed_props_opens);
RUN_TEST(doc_mentions_cs_scratch_table_work);
RUN_TEST(doc_mentions_incremental_non_ascii_name);
RUN_TEST(doc_mentions_alloc_failure_status);