code

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package code parses source files into a lightweight symbol graph so Mesh can answer "where does this function live / what calls it" without a separate code indexer. It is the pure-Go replacement for graphify's source-code role: Go is parsed with the standard library go/ast (full defs + call graph + imports); every other language uses a pure-Go declaration scanner that locates symbols by name+kind+line (no cgo, so the static binary and the Linux hub container build unchanged). The package has no database or graph dependency: it turns paths into CodeFile values and lets the index package persist them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lang

func Lang(ext string) string

Lang maps a file extension (with the dot, any case) to the language tag Mesh stores, or "" if the extension is not an indexed source language. It is the single source of truth for "is this a code file" used by both the walker and the watcher.

func LangForPath

func LangForPath(path string) string

LangForPath is a convenience for callers (watcher, CLI) that have a path and need its language tag without re-deriving the extension rules.

func ParseCodeFiles

func ParseCodeFiles(refs []FileRef, workers int) ([]*CodeFile, []FileError)

ParseCodeFiles parses refs concurrently with a bounded worker pool, preserving input order so the symbol graph is deterministic regardless of worker count. Reading + scanning is I/O-bound and embarrassingly parallel; the index-time merge that resolves call edges stays serial (it owns one shared name index). A file that parses to nothing (generated, too large, no symbols) is dropped, not errored. workers <= 0 means runtime.NumCPU().

func WalkCode

func WalkCode(roots []string, langs map[string]bool) ([]string, error)

WalkCode returns every indexable source file under each root whose extension is allowed by langs (a set of language tags from Lang; nil means all known languages). Roots are walked independently and results concatenated, so a vault can index code from several repos. Returned paths are absolute; the caller makes them root-relative for storage.

Types

type CodeFile

type CodeFile struct {
	Path    string   // root-relative, e.g. "dockyard/internal/handlers/deploy.go"
	Lang    string   // go|ts|tsx|js|jsx|mjs|cjs|svelte|astro|py
	Mtime   int64    // file mtime, unix seconds
	Package string   // Go package name; "" for other languages
	Imports []string // imported packages/modules, best-effort
	Symbols []Symbol
}

CodeFile is one parsed source file. Identity is the root-relative path; source files carry no stable frontmatter id, so a rename is a delete+add that the drift reconciler resolves by path, exactly as it does for an untitled note.

func ParseFile

func ParseFile(path, rootRel, lang string, mtime int64) (*CodeFile, error)

ParseFile reads path and extracts its symbols. lang selects the extractor: Go uses the standard library AST (full fidelity); every other language uses the declaration scanner. mtime is the caller's stat so parsing and drift detection agree on the same clock. A nil CodeFile with nil error means the file was deliberately skipped (generated, too large); the caller drops it.

type FileError

type FileError struct {
	Path string
	Err  error
}

FileError pairs a path with the error that stopped it from parsing, mirroring index.FileError so a code reindex reports skips the same way a note reindex does.

type FileRef

type FileRef struct {
	Abs string
	Rel string
}

FileRef pairs a file's absolute path (for reading) with its root-relative path (its stored identity). The orchestrator resolves Rel against whichever code root the file came from, so files from several repos coexist without path collisions.

type Symbol

type Symbol struct {
	Name      string   // qualified identifier, e.g. "DeployHandler" or "Server.Search"
	Kind      string   // func|method|type|interface|struct|const|var|class|enum
	Start     int      // 1-based start line (the editor deep link target)
	End       int      // 1-based end line; Start when the extent is unknown
	Signature string   // one-line declaration, whitespace-collapsed and truncated
	Doc       string   // leading doc comment, trimmed; "" when absent
	Calls     []string // callee identifiers referenced in the body (Go only)
}

Symbol is one declaration worth locating: a function, method, type, class, or exported const/var. Methods qualify their name with the receiver (Recv) so "Server.Search" is distinct from "Store.Search".

Jump to

Keyboard shortcuts

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