Index a TypeScript file's own documentation - #9
Merged
Conversation
A leading `/** … */` block documents the file when no declaration follows it
to own it: the `@fileoverview` and `@module` convention, and any design note
written above the imports. Association is by adjacency, and an `import`, a
bare `export {}`, or a re-export carries no symbol to attach such a block to,
so the walk dropped it. A file written that way contributed only signatures
to the index, and the one piece of prose saying what it is for could not be
retrieved at all.
It now emits as a `file` chunk keyed `ts/file`, which is for TypeScript and
JavaScript what the `package` chunk is for Go. A shebang and a directive
prologue are skipped when looking for the block, in either order, and a block
that does document a declaration is untouched.
The Go pin moves to 1.26.7 because two standard library advisories landed
against 1.26.5 after the last release, both fixed in 1.26.6, and the
vulnerability scan reaches them through the model download path.
Signed-off-by: Conner Ruhl <conner@reactor.inc>
Signed-off-by: Conner Ruhl <connerruhl@me.com>
cruhl
force-pushed
the
chunk/typescript-module-doc
branch
from
August 20, 2026 00:02
ec9f012 to
49e4a97
Compare
cruhl
marked this pull request as ready for review
August 20, 2026 00:02
johnsabath
self-requested a review
August 20, 2026 00:04
johnsabath
approved these changes
Aug 20, 2026
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.
/** … */block that no declaration owns is a file's own documentation, and it was being dropped rather than indexed.filechunk, keyedts/file, which is for TypeScript and JavaScript what thepackagechunk is for Go.The gap
Doc association is by adjacency: a comment group ending directly above a declaration documents that declaration. A file whose first statement is an
import, whose only export isexport {}, or which is documentation and nothing else, leaves its leading block with no declaration below it to own. The walk consumed the block and dropped it.That is the
@fileoverview/@moduleconvention, and it is also where a design note above the imports lives. So a file written that way contributed only signatures to the index, and the one piece of prose saying what the file is for could not be retrieved at all. Go has not had this gap:emitPackagegives a package's doc its own chunk.Before and after
Two files, one documenting itself above its imports and one that is documentation with a bare
export {}under it:Both blocks are absent. After:
Which is the difference between finding a file and not:
Before the change the same query returned an unrelated function signature at 0.32, because the sentence it was looking for was not in the index.
On a 950-file TypeScript codebase that documents its modules this way, 46 of 59 leading doc blocks were missing from the index. All 59 are present now.
Decisions worth reviewing
file, notmodule.VariantModulealready names a declared module or namespace in Rust, Ruby, C#, C++, and Scala, and conflating the two would break a--lang-style filter on meaning rather than on syntax."use client"above the block is the common React case, and#!/usr/bin/env nodeis the common CLI one. A directive below the block also leaves it unowned, so both orders emit.documentsNextdecides by exclusion —import, a declaration-lessexport, a second comment, a directive, end of file — so every existing association keeps its current behavior.filechunk per file. The key is fixed, so a second leading block cannot collide with it.Proof
go test ./...passes;go vet ./...is clean.pkg/chunk/typescript_test.go: a block above imports emits; the declaration under it still chunks; six unowned shapes emit (export {}, nothing at all, a second block, a directive above, a directive below, a shebang,export *); a block that owns a declaration does not emit; a//line comment does not emit.