(opts *GeneratorOptions)
| 79 | } |
| 80 | |
| 81 | func runFileMode(opts *GeneratorOptions) error { |
| 82 | // Load packages including the specific file |
| 83 | cfg := &packages.Config{ |
| 84 | Mode: packages.NeedTypes | packages.NeedSyntax | packages.NeedName | packages.NeedFiles | packages.NeedTypesInfo, |
| 85 | } |
| 86 | |
| 87 | // Load the directory containing the file |
| 88 | dir := filepath.Dir(opts.SourceFile) |
| 89 | if dir == "" { |
| 90 | dir = "." |
| 91 | } |
| 92 | |
| 93 | pkgs, err := packages.Load(cfg, dir) |
| 94 | if err != nil { |
| 95 | return fmt.Errorf("loading packages: %w", err) |
| 96 | } |
| 97 | |
| 98 | if len(pkgs) == 0 { |
| 99 | return fmt.Errorf("no packages found") |
| 100 | } |
| 101 | |
| 102 | if packages.PrintErrors(pkgs) > 0 { |
| 103 | // Check if any errors are compile-time guard related |
| 104 | var allErrors []string |
| 105 | for _, pkg := range pkgs { |
| 106 | for _, err := range pkg.Errors { |
| 107 | allErrors = append(allErrors, err.Error()) |
| 108 | } |
| 109 | } |
| 110 | errorMsg := strings.Join(allErrors, "; ") |
| 111 | |
| 112 | // If this looks like a compile-time guard error, provide better context |
| 113 | if isCompileGuardError(errorMsg) { |
| 114 | return fmt.Errorf("compile-time guard detected struct changes: %s", errorMsg) |
| 115 | } |
| 116 | |
| 117 | return fmt.Errorf("errors in packages") |
| 118 | } |
| 119 | |
| 120 | // Process only the specified file |
| 121 | for _, pkg := range pkgs { |
| 122 | if err := processPackageFile(pkg, opts.SourceFile, opts.TypeList); err != nil { |
| 123 | return fmt.Errorf("processing file %s: %w", opts.SourceFile, err) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | return nil |
| 128 | } |
| 129 | |
| 130 | func runPackageMode(opts *GeneratorOptions) error { |
| 131 | // Legacy package-based mode |
no test coverage detected