Skip to content
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

Enable hooks for dynamic completion #123

Merged
merged 13 commits into from
Aug 1, 2022
Merged

Conversation

dbanck
Copy link
Member

@dbanck dbanck commented Jul 27, 2022

This PR extends the completion of attribute values by getting completion candidates from dynamically registered hooks.

If an attribute schema contains one (or multiple) completion hooks, we look in the global decoder context to see if those hooks are registered. If they are, each hook is executed and should return a list of completion candidates.

The resulting candidate always replaces the whole attribute value range (including quotes).


@dbanck dbanck added the enhancement New feature or request label Jul 27, 2022
@dbanck dbanck self-assigned this Jul 27, 2022
@dbanck dbanck force-pushed the f-hooks-for-dynamic-completion branch from ace4b0c to 8f7e931 Compare July 28, 2022 08:14
@dbanck dbanck marked this pull request as ready for review July 28, 2022 09:32
@dbanck dbanck requested a review from a team July 28, 2022 09:32
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

I left some comments in-line, mostly minor though.

Thank you for getting to the bottom of the quoting issue!

All in all it looks pretty good and I guess we can tweak the detection of empty expressions later, when/if necessary, based on some real configs which we find to trigger any bugs.

decoder/completion_resolve.go Show resolved Hide resolved
decoder/completion_resolve.go Show resolved Hide resolved
decoder/context.go Outdated Show resolved Hide resolved
decoder/context.go Show resolved Hide resolved
decoder/context.go Show resolved Hide resolved
decoder/expression_candidates_test.go Show resolved Hide resolved
lang/candidate.go Show resolved Hide resolved
schema/attribute_schema.go Outdated Show resolved Hide resolved
schema/body_schema.go Show resolved Hide resolved
decoder/context.go Show resolved Hide resolved
@dbanck dbanck requested a review from radeksimko August 1, 2022 11:01
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

LGTM, just some really minor suggestions in-line. 👍🏻

decoder/completion_resolve.go Outdated Show resolved Hide resolved
decoder/completion_resolve.go Outdated Show resolved Hide resolved
decoder/context.go Show resolved Hide resolved
decoder/context.go Outdated Show resolved Hide resolved
lang/candidate.go Outdated Show resolved Hide resolved
schema/attribute_schema.go Outdated Show resolved Hide resolved
}

func (d *Decoder) SetContext(ctx DecoderContext) {
d.ctx = ctx
}

type CompletionFunc func(ctx context.Context, value cty.Value) ([]Candidate, error)
Copy link
Member

Choose a reason for hiding this comment

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

As mentioned in the other PR review

is it worth bringing some of the docs here, so we can omit them downstream?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a valid point, I moved it here.

I'm just wondering how easy the docs are discoverable, one won't be able to see them anywhere on hover in the LS.

Copy link
Member

Choose a reason for hiding this comment

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

You could add a reference or comment to CompletionFuncMap which is easier to discover downstream on hover.

dbanck and others added 3 commits August 1, 2022 13:54
@dbanck dbanck merged commit 118ac45 into main Aug 1, 2022
@dbanck dbanck deleted the f-hooks-for-dynamic-completion branch August 1, 2022 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants