-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: cmd/go: generate allow arguments to span multiple lines #46050
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
Comments
since comment structure is not enforced, how would it differentiate between the below being a single directive //go:generate do something
//foo |
A (partial) remedy might be requiring a shell-line line separator like so:
Is it possible to query github for such structures to see if that would break existing repos? Alternatively (though much weaker) could be a heuristic of treating |
I don't think it's wise to make There's also the question of whether such "escaped newlines" should also apply to other directives, like Also, how often are long |
That's a fair question. In my project I'm using them all over the place to generate code for implementing arbitrary optional interfaces
Any pointer how to? |
I think @rsc used to have a large corpus of Go code, but I don't think that's up to date and publicly available. You could try https://github.com/mvdan/corpus. |
Not scientific, but I've tried this on the mod cache of the top 1000 modules:
|
If you need a really long That adds its own overhead, of course, but if the long lines are really that much of a problem... |
Or, you could change the generator itself to parse its parameters from the file (identified via the (Actually, is the //go:generate go run ../../cmd/tools/decorate.go
//evcc:package vehicle
//evcc:function decorateVehicle
//evcc:base api.Vehicle
//evcc:file vehicle_decorators
//evcc:type api.ChargeState,Status,func() (api.ChargeStatus, error)
//evcc:type api.VehicleRange,Range,func() (int64, error) |
(CC @matloob @jayconrod) |
The backslash version #46050 (comment) is better than the non-backslash version, but even then we will run into issues with continued strings and such. It will just lead to more and more weird corner cases. Given that the usual thing is "go:generate go run x.go" why not put all that complexity into x.go where you have a real parser? Or even "go:generate bash x.bash". It doesn't seem like we need multiline input as a feature here when it can be moved to a better place. |
This proposal has been added to the active column of the proposals project |
To play the devil's advocate for a moment: interpreters like Largely, I agree that the complexity should be put elsewhere, if it doesn't comfortably fit into a single line. |
Thank you for taking the time to comment so extensively. Performance was never my concern, more readability. I appreciate the comments above, especially the use if the GOFILE and GOPACKAGE variables that I wasn‘t aware of. It seems that moving parsing into the action generator shouldn‘t be too complicated. I‘d prefer this approach over writing yet another stub that calls the actual generator. Based on the options lined out I‘d be happy to withdraw this proposal. |
For reference: https://golang.org/pkg/cmd/go/internal/generate/ |
No change in consensus, so declined. |
Go does encourage use of generated code by using
go generate
and the respective//go:generate
build comments.Working with implementing optional interfaces that a go object might chose to provide to extend a base interface type at runtime, I've come across the need to write long build comments like https://github.com/andig/evcc/blob/master/internal/vehicle/vehicle.go#L28
For readability it would be great if these could be supplied as multi-line comment. This could look like this:
I would like to propose to allow multi-line comments, given that the comment marker
).
//
is not followed by a space (The text was updated successfully, but these errors were encountered: