Documentation
¶
Overview ¶
Package langutil provides shared language-aware helpers used across go-code packages.
Index ¶
Constants ¶
const ( CallerKindProduction = "production" CallerKindTest = "test" CallerKindExample = "example" CallerKindBenchmark = "benchmark" CallerKindUnresolved = "unresolved" )
Canonical caller-kind values used by understand, call_trace, and related tools.
Variables ¶
This section is empty.
Functions ¶
func CallerKind ¶ added in v1.39.0
CallerKind classifies a symbol as production/test/example/benchmark from its name and file path. It is used by understand and call_trace to annotate callers so blast-radius answers can distinguish production call sites from tests.
The file is the gate: any caller in a non-test file is production, regardless of its name. Only callers inside a recognised test file are sub-classified by name (Example -> example, Benchmark -> benchmark, everything else -> test). This is intentionally multi-language: IsTestFile covers Go _test.go, Python test_/_test.py, JS/TS .test./.spec., test dirs, etc.
func IsExportedForDoc ¶ added in v1.22.0
IsExportedForDoc reports whether a symbol is considered exported for doc-coverage purposes, using language-appropriate rules. The logic mirrors isExportedSymbol in internal/compare/apisurf.go, extended with the IsPublic early-return for languages that carry an explicit visibility flag.
- IsPublic=true always wins — covers explicit "pub fn" (Rust), "def" with __all__ (Python), "public:" (C++), and any other language where the parser sets the flag.
- Go, Java, C#: uppercase-first-rune convention.
- JavaScript, TypeScript, Rust, Python, and all others: any non-underscore name is exported (matches the non-Go branch in apisurf.isExportedSymbol).
func IsTestFile ¶
IsTestFile returns true if the path looks like a test file based on suffix, prefix, infix, or containing directory.
func RelPath ¶
RelPath returns the relative path from root to abs. Falls back to the absolute path on error.
func TestStem ¶
TestStem extracts the logical stem from an infix-based test file path (e.g. "Button.test.ts" → "Button", true; "Modal.spec.svelte" → "Modal", true). It uses the first occurrence of ".test." or ".spec." in the file base-name. Returns ("", false) if the path does not contain a recognised infix or if the stem before the infix is empty (e.g. ".test.ts"). Detection is case-sensitive; lowercase the path first if case-insensitive matching is needed.
Types ¶
This section is empty.