feat: campos documentation, notes y code en registry

Añade campos documentation, notes y code a functions y types.
El parser extrae el contenido del .md y el código fuente del archivo
referenciado en file_path. El indexer los almacena en SQLite y los
incluye en FTS5 para búsqueda sobre código y documentación.
Nueva migración 003_documentation.sql para añadir las columnas.
This commit is contained in:
2026-03-28 20:32:15 +01:00
parent 476696dd10
commit 49eecd0c87
7 changed files with 290 additions and 68 deletions
+47 -19
View File
@@ -19,6 +19,9 @@ type IndexResult struct {
// and populates the database. It uses two passes:
// 1. Parse all entries and collect known IDs
// 2. Validate references against known IDs, then insert valid entries
//
// Scans functions/ and types/ at the root level, plus any language-specific
// directories (e.g. python/functions/, python/types/).
func Index(db *DB, root string) (*IndexResult, error) {
if err := db.Purge(); err != nil {
return nil, fmt.Errorf("purging database: %w", err)
@@ -26,39 +29,50 @@ func Index(db *DB, root string) (*IndexResult, error) {
result := &IndexResult{}
// Pass 1: parse everything
// Pass 1: parse everything from all source directories
var functions []*Function
var types []*Type
functionsDir := filepath.Join(root, "functions")
if _, err := os.Stat(functionsDir); err == nil {
filepath.Walk(functionsDir, func(path string, info os.FileInfo, err error) error {
if err != nil || info.IsDir() || !strings.HasSuffix(path, ".md") {
return nil
}
f, err := ParseFunctionMD(path)
// Directories to scan for functions and types.
// Base dirs + language-specific dirs discovered automatically.
funcDirs := []string{filepath.Join(root, "functions")}
typeDirs := []string{filepath.Join(root, "types")}
// Discover language-specific directories (e.g. python/functions/, python/types/)
entries, _ := os.ReadDir(root)
for _, e := range entries {
if !e.IsDir() {
continue
}
langFuncs := filepath.Join(root, e.Name(), "functions")
if fi, err := os.Stat(langFuncs); err == nil && fi.IsDir() {
funcDirs = append(funcDirs, langFuncs)
}
langTypes := filepath.Join(root, e.Name(), "types")
if fi, err := os.Stat(langTypes); err == nil && fi.IsDir() {
typeDirs = append(typeDirs, langTypes)
}
}
for _, dir := range funcDirs {
walkMD(dir, func(path string) {
f, err := ParseFunctionMD(path, root)
if err != nil {
result.Errors = append(result.Errors, fmt.Sprintf("parse %s: %v", path, err))
return nil
return
}
functions = append(functions, f)
return nil
})
}
typesDir := filepath.Join(root, "types")
if _, err := os.Stat(typesDir); err == nil {
filepath.Walk(typesDir, func(path string, info os.FileInfo, err error) error {
if err != nil || info.IsDir() || !strings.HasSuffix(path, ".md") {
return nil
}
t, err := ParseTypeMD(path)
for _, dir := range typeDirs {
walkMD(dir, func(path string) {
t, err := ParseTypeMD(path, root)
if err != nil {
result.Errors = append(result.Errors, fmt.Sprintf("parse %s: %v", path, err))
return nil
return
}
types = append(types, t)
return nil
})
}
@@ -99,3 +113,17 @@ func Index(db *DB, root string) (*IndexResult, error) {
return result, nil
}
// walkMD walks a directory recursively and calls fn for each .md file found.
func walkMD(dir string, fn func(path string)) {
if _, err := os.Stat(dir); err != nil {
return
}
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil || info.IsDir() || !strings.HasSuffix(path, ".md") {
return nil
}
fn(path)
return nil
})
}