codedoc

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package codedoc indexes code files for their documentation surface: file headers, exported doc comments, test names, and example names. Symbol semantics (types, call graphs, imports) are out of scope.

Extraction is shallow and regex-based for most languages; Go uses go/parser. No new Go module dependencies are added.

Entry point: Extract(absPath, relPath, src, hash) → *parser.ParseResult Registration: language files call RegisterExtractor from init().

codedoc_cstyle.go — C-style comment extractors for Rust, C, C++, Java, Swift, C#, PHP, Kotlin, and Dart.

All nine languages share // line-comment and /* */ block-comment syntax. Extraction is line-scanning / regex only — no external dependencies. Each language is registered via init() using makeExtractor.

JS/TS/Svelte/Vue code documentation extractor. Uses regex + line scanning only — no external dependencies.

codedoc_misc.go — language extractors for Lua/Luau, Pascal, SQL, and Liquid.

Each extractor is shallow and regex-based (stdlib only, no external deps). Registered via init() — imported transitively when codedoc package is used.

Index

Constants

View Source
const (
	KindFileHeader  = "file_header"
	KindTestFunc    = "test_func"
	KindExampleFunc = "example_func"
	KindDocComment  = "doc_comment"

	FileTypeSource = "source"
	FileTypeTest   = "test"
)

Comment kind constants are stable strings consumed by docs-code drift checks.

Variables

This section is empty.

Functions

func Extract

func Extract(absPath, relPath string, src []byte, hash string) (*parser.ParseResult, error)

Extract dispatches to the language-specific extractor and returns a ParseResult shaped identically to the document extraction pipeline output. Returns (nil, error) for unsupported extensions or parse failures.

func IsCodeExt

func IsCodeExt(ext string) bool

IsCodeExt reports whether ext (lower-cased, dot-prefixed) has a registered extractor.

func RegisterExtractor

func RegisterExtractor(lang string, fn extractFunc, exts ...string)

RegisterExtractor registers a language extractor for one or more file extensions. Called from init() in per-language files (codedoc_go.go, codedoc_python.go, etc.).

func SupportedExts

func SupportedExts() []string

SupportedExts returns all extensions currently registered by language extractors. Used by docformat and scanner to decide which code files to include.

Types

type CodeDocEntry

type CodeDocEntry struct {
	SymbolName  string // exported symbol name; "" for file_header.
	CommentKind string // KindFileHeader | KindTestFunc | KindExampleFunc | KindDocComment
	HeadingPath string // "File Header", "Tests > TestFoo", "Examples > ExampleFoo", "DocComment > Bar"
	Text        string // extracted comment/doc text
	StartLine   int
	EndLine     int
	FileType    string // FileTypeSource | FileTypeTest
	Lang        string // "go", "python", "javascript", "typescript", "rust"
}

CodeDocEntry is an extracted code documentation block returned by language extractors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL