query

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package query is the single source of truth for codenav's read operations: search, definition, references, callers, callees and call-path. The CLI (and, later, MCP/HTTP) are thin presenters over these functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallPath

func CallPath(db *sql.DB, fromIdent, toIdent string, maxDepth, limit int) ([][]graph.Node, error)

CallPath returns call paths from one symbol to another.

func Callees

func Callees(db *sql.DB, ident string, depth int) ([]graph.Node, error)

Callees returns symbols transitively called by ident.

func Callers

func Callers(db *sql.DB, ident string, depth int) ([]graph.Node, error)

Callers returns symbols that transitively call ident.

func Impact

func Impact(db *sql.DB, seeds []string, depth int) ([]graph.Node, error)

Impact returns the transitive callers (blast radius) of a set of seed symbols, i.e. what could break if the seeds change. Seeds are excluded from the result.

Types

type Hub

type Hub struct {
	QName   string `json:"qname"`
	Kind    string `json:"kind"`
	File    string `json:"file"`
	Line    int    `json:"line"`
	Callers int    `json:"callers"`
}

Hub is a heavily-called symbol — a good place to start understanding a repo.

type Overview

type Overview struct {
	Kinds map[string]int `json:"kinds"`
	Hubs  []Hub          `json:"hubs"`
}

Overview is a cold-start architecture summary: counts by kind and the most heavily-called symbols (entry points / hubs).

func GetOverview

func GetOverview(db *sql.DB, repo string, hubLimit int) (*Overview, error)

GetOverview computes an Overview, optionally scoped to one repo.

type RefHit

type RefHit struct {
	File string `json:"file"`
	Line int    `json:"line"`
	Col  int    `json:"col"`
	Role string `json:"role,omitempty"`
	In   string `json:"in,omitempty"`
	Text string `json:"text,omitempty"`
}

RefHit is a use-site of a symbol. In names the symbol that encloses the reference and Text is the trimmed source line, so one refs call answers "who uses this, and how" without opening each file.

func Refs

func Refs(db *sql.DB, ident string) ([]RefHit, error)

Refs returns every use-site of the matched symbol(s), each annotated with its enclosing symbol (In) and the trimmed source line (Text).

type RouteHit

type RouteHit struct {
	Method    string `json:"method"`
	Pattern   string `json:"pattern"`
	Handler   string `json:"handler,omitempty"`
	File      string `json:"file,omitempty"`
	Line      int    `json:"line,omitempty"`
	Framework string `json:"framework,omitempty"`
}

RouteHit is a detected web route, optionally bound to a handler symbol.

func ListRoutes

func ListRoutes(db *sql.DB, repo string) ([]RouteHit, error)

ListRoutes lists detected routes (with handler location), optionally per repo.

type SearchHit

type SearchHit struct {
	QName   string `json:"qname,omitempty"`
	Name    string `json:"name,omitempty"`
	Kind    string `json:"kind,omitempty"`
	File    string `json:"file"`
	Line    int    `json:"line,omitempty"`
	Snippet string `json:"snippet,omitempty"`
}

SearchHit is a search result (symbol-name or code-body).

func SearchCode

func SearchCode(db *sql.DB, q, repo string, limit int) ([]SearchHit, error)

SearchCode runs a BM25 full-text search over file bodies.

func SearchSymbols

func SearchSymbols(db *sql.DB, q, repo string, limit int) ([]SearchHit, error)

SearchSymbols runs a BM25 symbol-name search.

type SymbolHit

type SymbolHit struct {
	QName     string `json:"qname"`
	Name      string `json:"name"`
	Kind      string `json:"kind"`
	Signature string `json:"signature,omitempty"`
	File      string `json:"file"`
	Line      int    `json:"line"`
	EndLine   int    `json:"end_line,omitempty"`
	Fidelity  string `json:"fidelity,omitempty"`
	Snippet   string `json:"snippet,omitempty"`
}

SymbolHit is a resolved definition, optionally with a source snippet. EndLine makes the hit a precise edit target: callers that want to change the symbol can address File:Line-EndLine with their own editor instead of first reading the whole file to locate it.

func Def

func Def(db *sql.DB, ident string, includeBody bool) ([]SymbolHit, error)

Def returns matching definitions, each as a precise edit target (File + Line-EndLine). With includeBody it also attaches the source snippet; without it returns signature + location only, the token-frugal default for agents that just need to locate the symbol before editing with their own tools.

func ListSymbols

func ListSymbols(db *sql.DB, repo, kind string, limit int) ([]SymbolHit, error)

ListSymbols lists definitions (an entry point for exploring a codebase cold), optionally filtered by repo and kind. limit <= 0 means no limit.

func Outline

func Outline(db *sql.DB, file, repo string) ([]SymbolHit, error)

Outline lists the symbols defined in one file (signatures, no bodies) ordered by position — a cheap structural read that replaces dumping the whole file. file may be a repo-relative path or a bare basename (matched as a suffix).

func SymbolsInRange

func SymbolsInRange(db *sql.DB, repo, file string, lo, hi int) ([]SymbolHit, error)

SymbolsInRange returns symbols in a file whose span overlaps [lo,hi] — used to map git-diff hunks back to the symbols they touch.

Jump to

Keyboard shortcuts

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