Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/leyline.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func materializeCallers(tx *sql.Tx, now int64) error {
for token, callerNodeIDs := range callerMap {
// Look up the directory that defines this token
var dirID string
err := tx.QueryRow(`SELECT dir_id FROM node_defs WHERE token = ?`, token).Scan(&dirID)
err := tx.QueryRow(`SELECT node_id FROM node_defs WHERE token = ?`, token).Scan(&dirID)
if err != nil {
continue // no definition found, skip
}
Expand Down Expand Up @@ -197,7 +197,7 @@ func materializeCallees(tx *sql.Tx, now int64) error {
// Pre-load all defs: token → []dir_id (multiple constructs may define
// the same token, e.g. Init in different packages).
defsMap := make(map[string][]string)
defRows, err := tx.Query(`SELECT token, dir_id FROM node_defs`)
defRows, err := tx.Query(`SELECT token, node_id FROM node_defs`)
if err != nil {
return fmt.Errorf("query node_defs: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/leyline_callees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func TestMaterializeCallees(t *testing.T) {
);
CREATE TABLE node_defs (
token TEXT,
dir_id TEXT,
PRIMARY KEY (token, dir_id)
node_id TEXT,
PRIMARY KEY (token, node_id)
);
`)
require.NoError(t, err)
Expand Down Expand Up @@ -76,9 +76,9 @@ func TestMaterializeCallees(t *testing.T) {
require.NoError(t, err)

// Insert defs: FuncA and FuncB are defined
_, err = db.Exec("INSERT INTO node_defs (token, dir_id) VALUES (?, ?)", "FuncA", "pkg/functions/FuncA")
_, err = db.Exec("INSERT INTO node_defs (token, node_id) VALUES (?, ?)", "FuncA", "pkg/functions/FuncA")
require.NoError(t, err)
_, err = db.Exec("INSERT INTO node_defs (token, dir_id) VALUES (?, ?)", "FuncB", "pkg/functions/FuncB")
_, err = db.Exec("INSERT INTO node_defs (token, node_id) VALUES (?, ?)", "FuncB", "pkg/functions/FuncB")
require.NoError(t, err)

// Materialize callers (existing)
Expand Down
4 changes: 2 additions & 2 deletions cmd/leyline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func setupTestDB(t *testing.T) *sql.DB {

CREATE TABLE node_defs (
token TEXT,
dir_id TEXT,
PRIMARY KEY (token, dir_id)
node_id TEXT,
PRIMARY KEY (token, node_id)
) WITHOUT ROWID;

-- Function directories
Expand Down
4 changes: 2 additions & 2 deletions internal/graph/sqlite_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ func (g *SQLiteGraph) GetCallees(id string) ([]*Node, error) {
}
// SQL fallback: node_defs table (pre-built DBs)
if !resolved && g.useNodesTable {
rows, qErr := g.db.Query("SELECT dir_id FROM node_defs WHERE token = ?", qualKey)
rows, qErr := g.db.Query("SELECT node_id FROM node_defs WHERE token = ?", qualKey)
if qErr == nil {
for rows.Next() {
var defID string
Expand Down Expand Up @@ -726,7 +726,7 @@ func (g *SQLiteGraph) GetCallees(id string) ([]*Node, error) {
// SQL fallback: node_defs then nodes table
if g.useNodesTable {
var defID string
err := g.db.QueryRow("SELECT dir_id FROM node_defs WHERE token = ? LIMIT 1", qc.Token).Scan(&defID)
err := g.db.QueryRow("SELECT node_id FROM node_defs WHERE token = ? LIMIT 1", qc.Token).Scan(&defID)
if err == nil && defID != id && !seen[defID] {
seen[defID] = true
nodes = append(nodes, &Node{ID: defID, Mode: os.ModeDir | 0o555})
Expand Down
32 changes: 32 additions & 0 deletions internal/ingest/ast_walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,38 @@ func (w *ASTWalker) ExtractAddressRefs(sourcePath, langName string) ([]string, e
return tokens, nil
}

// ExtractGoImports reads Go import aliases from the _imports table
// (produced by ley-line-open's `leyline parse`). Returns alias → path map
// for qualified call resolution (e.g., auth.Validate → github.com/foo/auth).
// Mirrors SitterWalker.ExtractGoImports but uses SQL instead of CGO tree-sitter.
func (w *ASTWalker) ExtractGoImports(sourceID string) (map[string]string, error) {
// Check if _imports table exists (older .dbs produced before LLO didn't have it)
var count int
if err := w.db.QueryRow(
"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='_imports'",
).Scan(&count); err != nil || count == 0 {
return nil, nil
}

rows, err := w.db.Query(
"SELECT alias, path FROM _imports WHERE source_id = ?", sourceID,
)
if err != nil {
return nil, fmt.Errorf("query _imports: %w", err)
}
defer func() { _ = rows.Close() }()

imports := make(map[string]string)
for rows.Next() {
var alias, path string
if err := rows.Scan(&alias, &path); err != nil {
continue
}
imports[alias] = path
}
return imports, rows.Err()
}

// SelectWalker inspects a SQLite database and returns the best Walker.
// If the database has an _ast table (produced by ley-line's ll-open/ts),
// returns an ASTWalker (pure Go, no CGO). Otherwise returns a SitterWalker
Expand Down
8 changes: 4 additions & 4 deletions internal/ingest/sqlite_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func NewSQLiteWriter(dbPath string) (*SQLiteWriter, error) {

CREATE TABLE IF NOT EXISTS node_defs (
token TEXT,
dir_id TEXT,
PRIMARY KEY (token, dir_id)
node_id TEXT,
PRIMARY KEY (token, node_id)
) WITHOUT ROWID;

CREATE TABLE IF NOT EXISTS file_index (
Expand Down Expand Up @@ -121,7 +121,7 @@ func (w *SQLiteWriter) beginTx() error {
return err
}

w.stmtDef, err = w.tx.Prepare(`INSERT OR IGNORE INTO node_defs (token, dir_id) VALUES (?, ?)`)
w.stmtDef, err = w.tx.Prepare(`INSERT OR IGNORE INTO node_defs (token, node_id) VALUES (?, ?)`)
if err != nil {
return err
}
Expand Down Expand Up @@ -344,7 +344,7 @@ func (w *SQLiteWriter) DeleteFileNodes(filePath string) {
_, _ = w.tx.Exec(`DELETE FROM node_refs WHERE node_id IN (
SELECT id FROM nodes WHERE source_file = ?
)`, filePath)
_, _ = w.tx.Exec(`DELETE FROM node_defs WHERE dir_id IN (
_, _ = w.tx.Exec(`DELETE FROM node_defs WHERE node_id IN (
SELECT id FROM nodes WHERE source_file = ?
)`, filePath)
_, _ = w.tx.Exec(`DELETE FROM nodes WHERE source_file = ?`, filePath)
Expand Down
6 changes: 4 additions & 2 deletions internal/leyline/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ func DiscoverOrStart() (string, error) {
ctrlPath := filepath.Join(dataDir, "default.ctrl")
sockPath := filepath.Join(dataDir, "default.sock")

// Start leyline serve as a background subprocess
cmd := exec.Command(leylineBin, "serve",
// Start leyline daemon as a background subprocess.
// `daemon` creates the UDS socket at <ctrl>.sock that mache connects to.
// `serve` mounts only (no socket) — wrong for our use case.
cmd := exec.Command(leylineBin, "daemon",
"--arena", arenaPath,
"--arena-size-mib", "64",
"--control", ctrlPath,
Expand Down
Loading