Repository navigation
fix(extract): capture complete doc comments across languages - #2459
Merged
Merged
Conversation
extract_docstring() took only the single comment node directly before a definition. Multi-line `//` and `///` docs therefore kept just their last line (in C# usually `/// </summary>`); docs above attributes, exports and wrapper declarations were lost; fields, variables and modules never got a doc; Perl POD was never stored; and every doc was cut at 500 bytes. Capture the full documentation comment instead: - contiguous same-style comment runs; Go comment groups with go/ast directive lines (`//go:`, `//line`, `//export`, ...) stripped - docs above Rust attributes, JS/TS export statements and wrapper declarations (arrow and function expressions, class fields, assignments, ambient declarations) and C# top-level statements - docs for fields, variables, constants and enum members, found with a memoised linear walk - Go package comments and Rust `//!` docs on the File node - Perl POD sections that name a sub (`=head`/`=item <name>`) - Rust impl methods, Kotlin KDoc folded into package_header or sibling gaps, C `typedef struct/enum/union` declarations - a doc comment wins over an intervening plain `//`; runs detached by a blank line and runs made only of divider lines are not docs - no 500-byte cut; the properties buffer grows with the docstring, so a long doc no longer pushes other properties out Measured on nine real-world corpora (Go, C#, Java, TypeScript, Rust, C, PHP, Perl, Kotlin): full-doc capture Go 35% -> 99.999%, C# 10% -> 99.8%, Java 74% -> 99.99%, Rust 7% -> 99.9%, C 67% -> 99.2%, Kotlin 70% -> 99.96%, TypeScript sources 42% -> 100%, named-sub Perl POD 0% -> 100%. Node sets and all non-semantic edges are unchanged; index time stays within run-to-run noise. Signed-off-by: Martin Vogel <[email protected]>
neil1123-vip
pushed a commit
to neil1123-vip/codebase-memory-mcp
that referenced
this pull request
Oct 11, 2026
A POD section whose =head / =item names a sub is that sub's doc (DeusData#2459). Everything else (NAME, DESCRIPTION, SEE ALSO, the text of a section around the subs it holds, sections that name an attribute or helper without a node) was stored nowhere, so nothing could read it. It is now the file's module doc, stored on the File node as Go package comments and Rust inner docs are: every POD block with the sections a sub's doc holds cut out, each remaining run as it stands in the source, in document order and joined by a blank line (a sub's doc joins its sections the same way); a run of only =cut, =pod, =over and =back lines is dropped. A section is marked when a sub's doc takes it, so the module doc is built after the definitions and the two never hold the same text. Its first line is noted for the doc-link layer. Mojolicious at 93f591742a7d: L< codes in stored docs 624 (subs, unchanged) + 1,595 (File nodes of 112 modules) = 2,219, the count of L<> codes in the POD of its .pm and .pl files, none stored twice. Test: doc_perl_module_doc_is_the_pod_no_sub_holds (the module doc's exact text, the sub's doc unchanged, no module doc when every section is a sub's); red at its first assertion with the module doc not built. Signed-off-by: Martin Vogel <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extract_docstring()took only the single comment node immediately before a definition. On real code that loses most documentation://////docs keep only their last line (in C# usually/// </summary>);exportstatements and wrapper declarations are dropped;This PR captures the complete documentation comment for every supported language. Apart from the docs themselves, the graph is unchanged except for the side effects listed under "Graph impact".
What changes
go/astsemantics: directive lines (//go:…,//line,//export,//extern,//[a-z0-9]+:…) are stripped.exportstatements, wrapper declarations (arrow and function expressions, class-field arrows, pairs, assignments, ambient declarations) and C# top-level statements are found.//!docs land on the File node. Go has no per-file Module node (Nondeterministic Java USAGE-edge misattribution since #667 — edges attach to wrong source files on every fresh index #787).=head…/=item <name>) becomes its doc.extract_rust_implnever asked for them.package_headeror sibling gaps is recovered.typedef struct/enum/union {…} X;gets the comment above it.//comment, e.g. a Javadoc above// NOSONAR.Measured effect
Nine real-world corpora, indexed with
origin/main(0f52d30) and with this branch. The metric is the share of documented items whose full doc comment is stored./// </summary>-style one-liners.//!docs are now stored.Graph impact
SEMANTICALLY_RELATED/SIMILAR_TO, because the semantic pass now sees the full docs.bt,sp,fp, …) that the fixed 2 KB buffer used to drop are now restored: Java 5,116 nodes, C# 663.pass_importance.c,store.c). Existing indexes refresh their docstrings when files change or on a full re-index. That is worth a line in the release notes.Tests
tests/test_extraction.c: 13 new tests and 1 updated.//+ field, Kotlin folded KDoc, C typedef struct, Perl POD by sub name, long comment kept whole, divider-only run.#1017'slen <= 500assertion becomes "the whole comment is kept".tests/test_pipeline.c: 3 new tests — Go package comment on the File node, Rust inner doc on the File node, long docstring stored whole withsignatureintact.RED on revert: with the source change reverted and the tests kept,
extraction pipelinefails exactly these 17 tests, each on a behaviour assertion. With the change it is 710/710 green.Verification
run.sh lint): green.c61b3806: rebuilt, andextraction pipeline doclinks semantic store_search lang_contract complexityre-run green.scripts/test.sh: stops at step 0x (version-metadata contract) onorigin/mainas well. ff8dd47 pinned scoop at0.11.0, which is now the newest tag. That is unrelated to this change and tracked separately; this PR relies on PR CI for the full matrix.origin/main.index_resilience,mcpandcomplexityare identical on 0f52d30, with the same SQLiteunixReadmemcpy stack under QEMU.daemon_runtime/httpdidentity failures match the known QEMU/proc/self/exelimit.Follow-ups (not in this PR)
line_commentproperty for Go trailing field comments (new surface).// +k8s:…) inside docs.// @…lines.