feat: add go sdk pragma parsing for default and optional#6179
Conversation
|
Note, this PR only adds support for this behavior for arguments, we'll need a follow-up for struct fields - which should be pretty easy if this approach looks good! |
|
Nice!
My vote is for I don't think we need to be as explicit as Go since we can safely assume the comment is written for Dagger if we're discovering it while crawling a module type. Go has to disambiguate from all possible code comments, but we don't afaict. Even K8s, where we originally drew this inspiration from, just uses |
That's actually the type of corner case that feels like a slight argument for a To be clear, the situations in which this would happen are so obscure that they're right on the border of whether I think we should even care or not. It would have to be that someone is using a struct that just so happens to have a comment line with However, if we do use a prefix like I guess my vote would be a Also, I'd be find if it was even just |
sipsma
left a comment
There was a problem hiding this comment.
Overall looks great!
Echoing my other comment, I'd probably air on the side of dag: as the prefix (but could still be convinced of +, not incredibly opinionated here). And support for additionally being able to combine the annotations onto a single line if desired would be nice, but can easily be a follow up.
Only last question is what the failure mode is currently for types that don't make sense to have defaults in this approach, i.e. Container.
I don't want to support that at all to be clear, just want to make sure the error message is comprehensible and/or we don't crash :-D
There was a problem hiding this comment.
Are there situations in which this is expected to happen now? just curious
There was a problem hiding this comment.
I don't think it was really possible before either actually - since we only ever ran commentForFuncField on functions in the current module, and they were always parsed. Even in the context of #6185, where functions might be outside of the current package, then the fset is still populated for files in those other packages (though they haven't been fully parsed into a syntax tree).
So really this case wasn't actually possible to trigger, so we don't need to bother about returning an error (and even if there's a bizarre edge case, this just means that we don't return any comments for that field, which seems like the right behavior).
Signed-off-by: Justin Chadwell <me@jedevc.com>
This allows defining defaults and optional parameters for Go modules using "dagger" pragmas. These are inspired in style by "go" pragmas. Thankfully, this is actually a pretty simple patch, so we can bikeshed exact syntax - the earlier refactoring of opts through parsing args into paramSpecs makes this relatively simple to work with. Signed-off-by: Justin Chadwell <me@jedevc.com>
Yeah this is actually fine - in this case, we end up generating a weird But, the server errors out "nicely" in this case: The code for this is in Lines 1219 to 1222 in 24e552a |
b5f092a to
e439699
Compare
And also allow standalone "+optional" without a value. Signed-off-by: Justin Chadwell <me@jedevc.com>
|
Ok, so trying to steer this towards a decision - I think I'd rather have Couple key things from above that sway it for me:
I think we should take the |
SGTM, like I said the cases where it matters were right on the border of being meaningful or not, so not gonna block on splitting micro-hairs :-) Taking another quick look at the updated code now |
Fixes #6162.
This allows defining defaults and optional parameters for Go modules using "dagger" pragmas. These are inspired in style by "go" pragmas.
Thankfully, this is actually a pretty simple patch, so we can bikeshed exact syntax - the earlier refactoring of opts through parsing args into paramSpecs makes this relatively simple to work with (also because of the way
baseTypeandparamTypeare separated out, it's no extra effort to keep supporting theOptionalgeneric as well, though I do think if this approach is successful, we might want to remove that at some point).Personally, I think I prefer the more explicit
//dagger: default=abcinstead of//+default abc, but I also don't realllly have strong opinions on this. I've written the code so we just need to update the regexp and the respective tests for this - no other code is dependent on this.