Help us shape the future of Go! Take the 2026 Go Developer Survey

code

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package code holds the codebase indexing subsystem (ARCHITECTURE.md §7).

Symbol extraction is backed by gotreesitter (a pure-Go tree-sitter runtime that loads the same parse tables as upstream tree-sitter), so LadyM keeps its no-cgo / single-binary / hermetic-build properties while producing real AST-level symbols. Languages without a detailed spec degrade to line-window chunking (matching the Python port, which also only had per-language specs for these languages).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectLanguage

func DetectLanguage(path string) string

DetectLanguage returns the language id for a path, or "" when unsupported.

Types

type IndexInProgressError

type IndexInProgressError struct {
	DBPath string
}

IndexInProgressError is returned when another process already holds the index lock for a database (mirrors Python's IndexInProgressError). CLI/MCP surface the message verbatim instead of dumping a traceback. The lock itself (flock on <db>.index.lock) lives in the storage package behind Store.TryAcquireIndexLock; this package only translates storage.ErrIndexLockHeld into this user-facing type.

func (*IndexInProgressError) Error

func (e *IndexInProgressError) Error() string

type IndexReport

type IndexReport struct {
	FilesSeen               int
	FilesIndexed            int
	FilesSkippedUnchanged   int
	FilesSkippedUnsupported int
	SymbolsWritten          int
	RefsWritten             int
	ProjectedEdges          int
	ElapsedMs               float64
	Errors                  []string
}

IndexReport reports the outcome of an indexing pass.

func IndexCodebase

func IndexCodebase(root string, store storage.Store, embedder storage.EmbeddingProvider, cfg *config.Config, workspace string, force bool, languageFilter []string) (*IndexReport, error)

IndexCodebase walks root and indexes every supported source file.

The whole pass runs under a cross-process flock on <db>.index.lock (mirrors the Python indexer): a second concurrent index — from another CLI, MCP server, or worker — fails fast with IndexInProgressError instead of interleaving writes.

type LanguageSpec

type LanguageSpec struct {
	Name string
	// DefinitionKinds are tree-sitter node types that mark a definition.
	DefinitionKinds []string
	// NameField is the field carrying the symbol's identifier.
	NameField string
	// DocNodeKinds are comment/string node types preceding a def.
	DocNodeKinds []string
	// ParametersField / BodyField name the signature / body fields.
	ParametersField string
	BodyField       string
	// CallKinds are nodes that reference a callable.
	CallKinds []string
	// FallbackChunkLines is the line-window size for the chunk fallback.
	FallbackChunkLines int
	// Grammar lazily loads the gotreesitter grammar for this language.
	Grammar func() *gotreesitter.Language
}

LanguageSpec carries the tree-sitter node kinds for one language (mirrors the Python `LanguageSpec` in languages.py).

func GetSpec

func GetSpec(language string) *LanguageSpec

GetSpec returns the language spec, or a permissive chunk-only spec for unknown languages.

type RawRef

type RawRef struct {
	SrcSymbol string
	DstSymbol string
	RefKind   string
}

RawRef is a cross-reference between two symbols.

func BuildRefs

func BuildRefs(symbols []RawSymbol, filePath string) []RawRef

BuildRefs converts each symbol's calls into intra-file refs (caller→callee).

type RawSymbol

type RawSymbol struct {
	Kind          string // function | class | method | module | chunk
	Name          string // local identifier
	QualifiedName string // module[.Class].name
	Signature     string
	Docstring     string
	LineStart     int // 1-indexed
	LineEnd       int // 1-indexed, inclusive
	Body          string
	Calls         []string
}

RawSymbol is a symbol extracted from source (mirrors the Python RawSymbol).

func ExtractSymbols

func ExtractSymbols(src []byte, lang, moduleName, filePath string, maxBodyLines int) ([]RawSymbol, error)

ExtractSymbols extracts symbols from src for the given language, using the gotreesitter grammar when a detailed spec exists, otherwise returning nil so the indexer falls back to line-window chunking. A parse failure is returned as an error so the indexer can record it (mirroring the Python indexer, which logs "parse failed ...; using chunk fallback" and degrades to chunks).

Jump to

Keyboard shortcuts

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