(pkg *packages.Package, typeList string)
| 232 | } |
| 233 | |
| 234 | func processPackage(pkg *packages.Package, typeList string) error { |
| 235 | // Find structs to generate code for |
| 236 | var targetTypes []string |
| 237 | if typeList != "" { |
| 238 | targetTypes = strings.Split(typeList, ",") |
| 239 | } |
| 240 | |
| 241 | // Also check if there are any compilation errors |
| 242 | if len(pkg.Errors) > 0 { |
| 243 | for _, err := range pkg.Errors { |
| 244 | logger.Printf("package error: %s", err) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | // Parse structs from package |
| 249 | structs, err := parseStructsFromPackage(pkg, targetTypes) |
| 250 | if err != nil { |
| 251 | return fmt.Errorf("parsing structs from package: %w", err) |
| 252 | } |
| 253 | |
| 254 | if len(structs) == 0 { |
| 255 | if len(targetTypes) > 0 { |
| 256 | scope := pkg.Types.Scope() |
| 257 | allNames := scope.Names() |
| 258 | logger.Printf("Warning: No matching structs found for target types: %v", targetTypes) |
| 259 | logger.Printf("Available types in package: %v", allNames) |
| 260 | return fmt.Errorf("no matching structs found for target types: %v", targetTypes) |
| 261 | } |
| 262 | logger.Printf("No structs to generate (no target types specified)") |
| 263 | return nil |
| 264 | } |
| 265 | |
| 266 | // Generate code (legacy package mode) |
| 267 | logger.Printf("Generating code for %d struct(s): %v", len(structs), getStructNames(structs)) |
| 268 | if err := generateCode(pkg, structs); err != nil { |
| 269 | return err |
| 270 | } |
| 271 | logger.Printf("Successfully generated code for package %s", pkg.Name) |
| 272 | return nil |
| 273 | } |
| 274 | |
| 275 | // generateCodeForFile generates code with file-based naming |
| 276 | func generateCodeForFile(pkg *packages.Package, structs []*StructInfo, sourceFile string) error { |
no test coverage detected