-
Notifications
You must be signed in to change notification settings - Fork 386
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
Extend autocompletion to be build arg aware #1330
Conversation
d7bd274
to
d82cd92
Compare
targets := make([]string, 0, len(ef.Targets)) | ||
for _, target := range ef.Targets { | ||
targets := make([]string, 0, len(bc.Earthfile.Targets)) | ||
for _, target := range bc.Earthfile.Targets { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the reason for passing in the resolver here? It seems like we're passing in the resolver here to get the Earthfile which was also possible before by using ast.Parse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hoping to extend auto-completion to also work on remote targets in a future PR, which will require the resolver.
|
||
// GetTargetArgs returns a list of build arguments for a specificed target | ||
func GetTargetArgs(ctx context.Context, resolver *buildcontext.Resolver, gwClient gwclient.Client, target domain.Target) ([]string, error) { | ||
bc, err := resolver.Resolve(ctx, gwClient, target) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here about passing in resolver instead of using ast.Parse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still reviewing this PR but had some initial questions
if strings.HasSuffix(targetToParse, "+") { | ||
targetToParse += "base" | ||
} | ||
target, err := domain.ParseTarget(targetToParse) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does domain.ParseTarget
expect a full target name but here we could be passing in just a prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, without the target name ParseTarget
returns an error since it's not a target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm just missing something here, but if we return err here wouldn't that return early here instead of expanding the potentials below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's assume we're expanding on ./path+
, If we call domain.ParseTarget(targetToParse)
that will return an error as it is not a valid target.
So prior to calling that we call: if strings.HasSuffix(targetToParse, "+") {
, and then pretend the user is expanding on ./path+base
instead which will allow domain.ParseTarget
to return successfully.
When we call earthfile2llb.GetTargets
, we pass it a target (because that's what the resolver expects); however we never actually look at the target name -- we only look at the path to the Earthfile. The reason I want to change it from a string path and to a target, is to allow us to (one-day) expand on a remote target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if targetsToParse
(or prefix
) is ./path+foo
(where full target is foobar
), in this case we wouldn't be passing +base
to ParseTarget
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about I change // GetTargets returns a list of targets from an Earthfile.
-> // GetTargets returns a list of targets from an Earthfile. Note that the target name of domain.Target is ignored and doesn't matter
?
I agree it's weird, it's just to work around the fact that the resolver expects a target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's not ignoring it completely because it uses it for LocalDirs and other metadata, but my initial instinct is to assume it's some sort of filter used in GetTargets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about I change // GetTargets returns a list of targets from an Earthfile. -> // GetTargets returns a list of targets from an Earthfile. Note that the target name of domain.Target is ignored and doesn't matter?
I agree it's weird, it's just to work around the fact that the resolver expects a target.
Sounds good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// GetTargets returns a list of targets from an Earthfile.
// Note that the passed in domain.Target's target name is ignored (only the reference to the Earthfile is used)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks!
RUN diff expected actual | ||
|
||
RUN echo "--city=" > expected | ||
RUN COMP_LINE="earthly +othertargetwithargs --ci" COMP_POINT=33 earthly > actual |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also add a test case here where autocomplete is called in the middle of a build arg value? I'm assuming in that case there should be no potentials returned right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we set it to COMP_POINT=8, we will truncate it to earthly
and autocomplete based on that.
Currently (even without this PR) if you type earthly --intera<tab><tab>ctive
it will give us earthly --interactive ctive
. If we want to fix that bug, I would rather open a new issue (and PR) for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently (even without this PR) if you type earthly --interactive it will give us earthly --interactive ctive. If we want to fix that bug, I would rather open a new issue (and PR) for that.
Ah interseting. I was referring to build arg values, not args to earthly
. Would this bug still apply in that case? For example earthly +target --MY_ARG=foo<tab><tab>
, which I would assume returns nothing because we can't know what potential values would be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It applies in all cases:
earthly/autocomplete/complete.go
Line 195 in 6fa0591
compLine = compLine[:compPoint] |
36791e1
to
ef95973
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time to answer all my questions! :)
Earthly will now look at ARG commands within a target and make suggestions based on them. e.g. earthly +update-buildkit -<tab><tab> will suggest --BUILDKIT_GIT_SHA, --BUILDKIT_GIT_BRANCH Additionally earthly will no longer suggest global flags after a target was given (which was incorrect behaviour). Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
ef95973
to
fb0559b
Compare
Earthly will now look at ARG commands within a target
and make suggestions based on them. e.g.
will suggest
Additionally earthly will no longer suggest global flags after
a target was given (which was incorrect behaviour).
Signed-off-by: Alex Couture-Beil alex@earthly.dev