Reparse re-parses the indicated file paths, updating the Parser's state. If rill.yaml has previously errored, or if rill.yaml is included in paths, it will reload the entire project. If a previous call to Reparse has returned an error, the Parser may not be accessed or called again.
(ctx context.Context, paths []string)
| 252 | // If rill.yaml has previously errored, or if rill.yaml is included in paths, it will reload the entire project. |
| 253 | // If a previous call to Reparse has returned an error, the Parser may not be accessed or called again. |
| 254 | func (p *Parser) Reparse(ctx context.Context, paths []string) (*Diff, error) { |
| 255 | var changedRillYAML bool |
| 256 | for _, path := range paths { |
| 257 | if !pathIsRillYAML(path) { |
| 258 | continue |
| 259 | } |
| 260 | oldRillYAML := p.RillYAML |
| 261 | err := p.parseRillYAML(ctx, path) |
| 262 | if err == nil { |
| 263 | // Watcher sends multiple events for a single edit. We want to only restart the controller when rill.yaml actually changes. |
| 264 | // So we check the new rill.yaml contents against the contents stored in parser state. |
| 265 | changedRillYAML = !reflect.DeepEqual(oldRillYAML, p.RillYAML) |
| 266 | } else { |
| 267 | // any error including parse error means rill.yaml changed |
| 268 | changedRillYAML = true |
| 269 | } |
| 270 | break |
| 271 | } |
| 272 | |
| 273 | if changedRillYAML { |
| 274 | err := p.reload(ctx) |
| 275 | if err != nil { |
| 276 | return nil, err |
| 277 | } |
| 278 | return &Diff{Reloaded: true}, nil |
| 279 | } |
| 280 | |
| 281 | // If rill.yaml previously errored, we're not going to reparse anything until it's changed, at which point we'll reload the entire project. |
| 282 | if p.RillYAML == nil { |
| 283 | return &Diff{Skipped: true}, nil |
| 284 | } |
| 285 | |
| 286 | return p.reparseExceptRillYAML(ctx, paths) |
| 287 | } |
| 288 | |
| 289 | // IsSkippable returns true if the path will be skipped by Reparse. |
| 290 | // It's useful for callers to avoid triggering a reparse when they know the path is not relevant. |