Skip to content

Commit ec6f837

Browse files
authored
Merge pull request #2550 from DeusData/feat/doc-links-core
feat(doc-links): C# doc-comment references become MENTIONS edges
2 parents e93e438 + 341783a commit ec6f837

30 files changed

Lines changed: 29184 additions & 50 deletions

‎Makefile.cbm‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ EXTRACTION_SRCS = \
373373
$(CBM_DIR)/extract_channels.c \
374374
$(CBM_DIR)/extract_k8s.c \
375375
$(CBM_DIR)/extract_dbt.c \
376+
$(CBM_DIR)/doclink.c \
377+
$(CBM_DIR)/doclink_cs.c \
376378
$(CBM_DIR)/sql_values.c \
377379
$(CBM_DIR)/helpers.c \
378380
$(CBM_DIR)/cpp_branch_views.c \
@@ -493,6 +495,9 @@ PIPELINE_SRCS = \
493495
src/pipeline/pass_configures.c \
494496
src/pipeline/pass_configlink.c \
495497
src/pipeline/pass_doclinks.c \
498+
src/pipeline/doc_links.c \
499+
src/pipeline/doc_links_cs.c \
500+
src/pipeline/doc_links_msbuild.c \
496501
src/pipeline/pass_route_nodes.c \
497502
src/pipeline/pass_enrichment.c \
498503
src/pipeline/pass_envscan.c \
@@ -754,7 +759,7 @@ TEST_DISCOVER_SRCS = \
754759

755760
TEST_GRAPH_BUFFER_SRCS = tests/test_graph_buffer.c
756761

757-
TEST_PIPELINE_SRCS = tests/test_registry.c tests/test_pipeline.c tests/test_pipeline_conventions.c tests/test_pipeline_frozen.c tests/test_importance.c tests/test_cross_repo.c tests/test_fqn.c tests/test_route_canon.c tests/test_path_alias.c tests/test_configlink.c tests/test_doclinks.c tests/test_infrascan.c tests/test_worker_pool.c tests/test_parallel.c tests/test_index_resilience.c tests/test_index_format.c tests/test_call_reference_contract.c tests/repro/repro_call_scope_usages.c tests/repro/repro_call_argument_usages.c tests/repro/repro_reference_precision.c tests/repro/repro_lexical_binding_precision.c tests/repro/repro_call_argument_matrix_a.c tests/repro/repro_call_argument_matrix_b.c tests/repro/repro_call_node_behaviors.c tests/repro/repro_language_registry.c tests/repro/repro_call_node_manifest.c tests/repro/repro_lsp_ordered_signatures.c tests/repro/repro_lsp_ordered_local.c tests/repro/repro_ts_overload_return_chains.c tests/repro/repro_harness_cleanup.c tests/repro/repro_runner_filter.c
762+
TEST_PIPELINE_SRCS = tests/test_registry.c tests/test_pipeline.c tests/test_pipeline_conventions.c tests/test_pipeline_frozen.c tests/test_importance.c tests/test_cross_repo.c tests/test_fqn.c tests/test_route_canon.c tests/test_path_alias.c tests/test_configlink.c tests/test_doclinks.c tests/test_doc_mentions.c tests/test_infrascan.c tests/test_worker_pool.c tests/test_parallel.c tests/test_index_resilience.c tests/test_index_format.c tests/test_call_reference_contract.c tests/repro/repro_call_scope_usages.c tests/repro/repro_call_argument_usages.c tests/repro/repro_reference_precision.c tests/repro/repro_lexical_binding_precision.c tests/repro/repro_call_argument_matrix_a.c tests/repro/repro_call_argument_matrix_b.c tests/repro/repro_call_node_behaviors.c tests/repro/repro_language_registry.c tests/repro/repro_call_node_manifest.c tests/repro/repro_lsp_ordered_signatures.c tests/repro/repro_lsp_ordered_local.c tests/repro/repro_ts_overload_return_chains.c tests/repro/repro_harness_cleanup.c tests/repro/repro_runner_filter.c
758763

759764
TEST_WATCHER_SRCS = tests/test_watcher.c
760765

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,9 @@ mode. `index_status` keeps describing the published graph and its freshness.
745745

746746
### Edge Types
747747

748-
`CONTAINS_PACKAGE`, `CONTAINS_FOLDER`, `CONTAINS_FILE`, `DEFINES`, `DEFINES_METHOD`, `IMPORTS`, `CALLS`, `CALL_REFERENCE`, `HTTP_CALLS`, `ASYNC_CALLS`, `SPAWNS`, `IMPLEMENTS`, `HANDLES`, `USAGE`, `CONFIGURES`, `REFERENCES_FILE`, `WRITES`, `MEMBER_OF`, `TESTS`, `USES_TYPE`, `FILE_CHANGES_WITH`
748+
`CONTAINS_PACKAGE`, `CONTAINS_FOLDER`, `CONTAINS_FILE`, `DEFINES`, `DEFINES_METHOD`, `IMPORTS`, `CALLS`, `CALL_REFERENCE`, `HTTP_CALLS`, `ASYNC_CALLS`, `SPAWNS`, `IMPLEMENTS`, `HANDLES`, `USAGE`, `CONFIGURES`, `REFERENCES_FILE`, `MENTIONS`, `WRITES`, `MEMBER_OF`, `TESTS`, `USES_TYPE`, `FILE_CHANGES_WITH`
749+
750+
`MENTIONS` links a documented definition to the code its doc comment references (C# `<see cref>`, `<seealso cref>`, `<exception cref>`, `<inheritdoc cref>`), one edge per pair with `via`, `syntax`, `tier` (`exact` or `unique`), first `line` and `count`. A reference is bound only when it names exactly one definition under the language's own lookup rules; the rest are counted by reason in `index_status` under `doc_links` (samples with `diagnostics='full'`).
749751

750752
### Qualified Names
751753

‎docs/EVALUATION_PLAN.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,16 @@ SHA, and — **not just totals** — a **per-type breakdown**:
311311
- `node-types.json` — a histogram of **node count by label** (`Function`, `Method`, `Class`,
312312
`Interface`, `Type`/`Enum`/`Struct`, `Field`, `Variable`, `Route`, `Module`, `Section`, `Macro`,
313313
`File`, `Folder`) + total.
314-
- `edge-types.json` — a histogram of **edge count by type, with one entry for every one of the 32
314+
- `edge-types.json` — a histogram of **edge count by type, with one entry for every one of the 33
315315
edge types, including those that came back `0`**. The canonical set is the indexer's own
316-
`ALL_EDGE_TYPES[]` (26 intra-repo types — `tests/test_lang_contract.c`): `CALLS`, `ASYNC_CALLS`,
316+
`ALL_EDGE_TYPES[]` (27 intra-repo types — `tests/test_lang_contract.c`): `CALLS`, `ASYNC_CALLS`,
317317
`HTTP_CALLS`, `GRPC_CALLS`, `GRAPHQL_CALLS`, `TRPC_CALLS`, `DEFINES`, `DEFINES_METHOD`, `IMPLEMENTS`,
318318
`INHERITS`, `OVERRIDE`, `DECORATES`, `IMPORTS`, `HANDLES`, `CONFIGURES`, `DEPENDS_ON`, `USAGE`,
319319
`DATA_FLOWS`, `SEMANTICALLY_RELATED`, `SIMILAR_TO`, `TESTS`, `TESTS_FILE`, `INFRA_MAPS`,
320-
`FILE_CHANGES_WITH`, `CONTAINS_FILE`, `CONTAINS_FOLDER` — **plus the 6 cross-repo types** from the
320+
`FILE_CHANGES_WITH`, `CONTAINS_FILE`, `CONTAINS_FOLDER`, `MENTIONS` (doc comment -> referenced
321+
code) — **plus the 6 cross-repo types** from the
321322
cross-repo pass (`CROSS_HTTP_CALLS`, `CROSS_ASYNC_CALLS`, `CROSS_GRPC_CALLS`, `CROSS_GRAPHQL_CALLS`,
322-
`CROSS_TRPC_CALLS`, `CROSS_CHANNEL`) and a total. The writer **emits the full 32-type list and
323+
`CROSS_TRPC_CALLS`, `CROSS_CHANNEL`) and a total. The writer **emits the full 33-type list and
323324
back-fills missing types with `0`** rather than recording only the types that appeared.
324325

325326
These come straight from `query_graph` (`MATCH (n) RETURN labels(n), count(*)` and

‎internal/cbm/cbm.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#include "foundation/mem_events.h" // waste sanitizer: the bound allocators bypass every observer
77
#include "foundation/log.h" // cbm_log_warn -- extract.lsp.skipped
88
#include "cbm.h"
9-
#include "arena.h" // CBMArena, cbm_arena_init/alloc/strdup/destroy
9+
#include "arena.h" // CBMArena, cbm_arena_init/alloc/strdup/destroy
10+
#include "doclink.h" // cbm_doclinks_extract: doc-comment references + doc-link scope
1011
#include "helpers.h"
1112
#include "lang_specs.h"
1213
#include "extract_unified.h"
@@ -3601,6 +3602,10 @@ static CBMFileResult *extract_file_ex_body(const char *source, int source_len, C
36013602

36023603
result->imports_count = result->imports.count;
36033604

3605+
/* Doc-comment references of the documented definitions, and the file's
3606+
* doc-link scope: both read the complete docstrings and the tree. */
3607+
cbm_doclinks_extract(&ctx);
3608+
36043609
// Accumulate profiling counters
36053610
atomic_fetch_add(&total_parse_ns, t1 - t0);
36063611
atomic_fetch_add(&total_extract_ns, t2 - t1);

‎internal/cbm/cbm.h‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,31 @@ typedef struct {
610610
int cap;
611611
} CBMFieldTypeArray;
612612

613+
/* One reference found in a definition's complete doc comment, or in the file's
614+
* own doc (doclink.h has the syntax table and the per-language parsers).
615+
* Resolution happens later, per file, in the pipeline
616+
* (src/pipeline/doc_links.c). */
617+
typedef struct {
618+
const char *source_qn; // QN of the documented definition (the edge source);
619+
// for a file-level reference the file's module QN
620+
const char *raw; // the reference as written, markup entities decoded
621+
uint32_t line; // 1-based source line of the reference
622+
uint32_t def_line; // 1-based start line of the documented definition
623+
uint16_t syntax; // CBMDocLinkSyntax (doclink.h)
624+
uint16_t flags; // CBM_DOCLINK_FLAG_* (doclink.h); set by the driver
625+
} CBMDocLink;
626+
627+
typedef struct {
628+
CBMDocLink *items;
629+
int count;
630+
int cap;
631+
/* Memory ran out while this file's doc-link data was extracted (a token,
632+
* a reference value, a doc text or the scope blob was lost): the
633+
* resolving half fails the layer instead of publishing a silently
634+
* incomplete graph. */
635+
bool failed;
636+
} CBMDocLinkArray;
637+
613638
// Full extraction result for one file.
614639
typedef struct CBMFileResult {
615640
CBMArena arena; // owns local memory; composites may also retain child arenas below
@@ -722,6 +747,14 @@ typedef struct CBMFileResult {
722747
int test_owner_source_len;
723748
CBMLanguage test_owner_language;
724749
char test_owner_source_sha256[65]; /* exact raw source; identity, not authentication */
750+
751+
/* Doc-comment references of this file's definitions (doclink.h), and the
752+
* file's doc-link scope: a language-tagged text blob with what OTHER
753+
* files' doc-link resolution needs from this file (C#: namespaces,
754+
* usings, type and member declarations). A pure function of the file's
755+
* bytes; NULL for languages without a scope scanner. */
756+
CBMDocLinkArray doc_links;
757+
const char *doc_scope;
725758
} CBMFileResult;
726759

727760
// --- Enclosing function cache ---
@@ -818,6 +851,18 @@ typedef struct {
818851
struct CBMTestDefinitionMatch *test_definition_matches; /* traversal scratch */
819852
int test_definition_match_count;
820853
int test_definition_match_cap;
854+
/* Start line of every doc text doc_run_text built, keyed by the returned
855+
* pointer (doclink.c), so a definition's doc references get exact source
856+
* lines. NULL until the first doc; allocated in `scratch`. */
857+
void *doc_lines;
858+
/* A per-file slot for the language's doc-link hooks (parse_doc and
859+
* scan_scope, internal/cbm/doclink_<lang>.c): state that has to survive
860+
* between the hook calls of ONE file, e.g. an index of the file's doc
861+
* sections. NULL at the start of every file. What a hook stores here must
862+
* be allocated in `scratch` (or `arena`), so that it ends with the file.
863+
* The core never reads, interprets or frees it. It is the only place for
864+
* such state: a static or thread-local cache is not. */
865+
void *doclink_state;
821866
} CBMExtractCtx;
822867

823868
/* Internal configured-definition seams. No declarations pointer enters a result. */

0 commit comments

Comments
 (0)