Skip to content

fix: support gazelle generation_mode:update_only #2708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2025

Conversation

jbedard
Copy link
Contributor

@jbedard jbedard commented Mar 27, 2025

This just fixes a crash when generation_mode: update_only causes GenerateRules to not be invoked for 100% of directories.

Fix #2707

@@ -134,12 +134,20 @@ type Configs map[string]*Config

// ParentForPackage returns the parent Config for the given Bazel package.
func (c *Configs) ParentForPackage(pkg string) *Config {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since map is a reference type, could you please update the receiver arg to be a type of c Configs please?

Suggested change
func (c *Configs) ParentForPackage(pkg string) *Config {
func (c Configs) ParentForPackage(pkg string) *Config {

if dir == "" {
return nil
}
pkg = dir
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a unit test for this new logic? Just testing the Configs in isolation would be sufficient.

Right now it is a little bit hard to read and having tests would help understand what this has to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a few basic tests for this method.

There should probably be some additional full tests for update_only and mixing that with the different python_generation_mode modes but I'm not familiar enough with it to do in this initial PR.

@jbedard jbedard force-pushed the gazelle-update_only branch 2 times, most recently from 552417e to 956cff8 Compare April 4, 2025 20:00
@jbedard jbedard force-pushed the gazelle-update_only branch from 956cff8 to 3410bf2 Compare April 4, 2025 20:01
@@ -125,21 +125,28 @@ const (

// defaultIgnoreFiles is the list of default values used in the
// python_ignore_files option.
var defaultIgnoreFiles = map[string]struct{}{
}
var defaultIgnoreFiles = map[string]struct{}{}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The precommit seems to be doing this? 🤷

Copy link
Collaborator

@aignas aignas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the extra tests!

@aignas aignas added this pull request to the merge queue Apr 5, 2025
Merged via the queue into bazel-contrib:main with commit 69a9920 Apr 5, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crash when using gazelle generation_mode:update_only
2 participants