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

add a new shell completion provider #2858

Merged
merged 6 commits into from
Mar 5, 2024
Merged

add a new shell completion provider #2858

merged 6 commits into from
Mar 5, 2024

Conversation

MarkoMin
Copy link
Contributor

@MarkoMin MarkoMin commented Jan 22, 2024

Provider to generate autocompletion files. Generates completion for plugins too, which is a big step forward! Previous completion also worked only for the first flag.

Currently only completion for bash is implemented. I'll first wait for comments on style/tests and then I'll implement zsh and maybe others.

Also, documentation is missing, but it will be written as soon as implementation gets reviewed and I manage to get some free time.

@ferd About testing, I did what I believe is convenient here - do you have more suggestions ? It ensures that file is written and that it contains some key parts such as function definition (loose regex) and completion definitions for "rebar3" and for all os-level aliases. I can't run a bash built-in (source) to run the completion function from CT...

Closes #2077

EDIT:
#2754 can now be implemented as an oracle and it will be available in all supported shells! Actually, completion for rebar3 as <profile> and rebar3 clean --projects <project> could be implemented with small modifications. Current completion for rebar3 as is partly broken, so you can ignore it for now.

Copy link
Collaborator

@ferd ferd left a comment

Choose a reason for hiding this comment

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

So far I like the approach. The tests are more complete with the dynamic checks you do than what I had suggested, we just need to skip their execution in places where they're not available.

apps/rebar/src/rebar_prv_completion.erl Show resolved Hide resolved
apps/rebar/src/rebar_prv_completion.erl Show resolved Hide resolved
apps/rebar/src/rebar_prv_completion.erl Outdated Show resolved Hide resolved
Comment on lines +154 to +159
provider_get(P, bare) ->
element(5, P);
provider_get(P, short_desc) ->
element(8, P);
provider_get(P, namespace) ->
element(12, P).
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a messy bit, which I think you know. Not a blocker for now but we may need to go back at some point and update the providers lib to expose these.

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 know, if we're able to merge it and bump providers version in rebar then I'd do a PR to expose these. @tsloughter ?

apps/rebar/test/rebar_completion_SUITE.erl Outdated Show resolved Hide resolved
apps/rebar/test/rebar_completion_SUITE.erl Show resolved Hide resolved
Co-authored-by: Fred Hebert <mononcqc@ferd.ca>
@MarkoMin
Copy link
Contributor Author

Also, I use maps:groups_from_list/2 which is introduced in OTP 25.0, is that a problem?

@ferd
Copy link
Collaborator

ferd commented Jan 28, 2024

Also, I use maps:groups_from_list/2 which is introduced in OTP 25.0, is that a problem?

Yeah this is going to be an issue in the short term. We currently support 24, 25, and 26. Once 27 is out, we'll deprecate 24, though.

@MarkoMin
Copy link
Contributor Author

MarkoMin commented Jan 29, 2024

Yeah this is going to be an issue in the short term. We currently support 24, 25, and 26. Once 27 is out, we'll deprecate 24, though.

Solved via macro, we can remove it when <25 gets deprecated.

Let me know if everything is good now so I can create support for zsh before merging this.

Sorry about crashdump, mistake... Will get purged when we squash commits

@ferd
Copy link
Collaborator

ferd commented Feb 20, 2024

Woops I hadn't seen the update. This looks okay for zsh now, and yeah, feel free to remove that crashdump whenever.

@MarkoMin
Copy link
Contributor Author

MarkoMin commented Mar 2, 2024

Did it. Now only documentation is missing. I'll document it in commands section. Is it worth to move instructions on how to set up autocomplete to another section (probably in tutorials)? Because I don't wanna bloat commands page with setup instructions that might grow with different shells being supported.

What will be the number of the next version? It would be nice to mention from which version completion command became available

@ferd
Copy link
Collaborator

ferd commented Mar 5, 2024

Did it. Now only documentation is missing. I'll document it in commands section. Is it worth to move instructions on how to set up autocomplete to another section (probably in tutorials)? Because I don't wanna bloat commands page with setup instructions that might grow with different shells being supported.

I don't have an issue with that if you think it warrants the complexity. Having it in the commands for the list of arguments makes sense as well.

What will be the number of the next version? It would be nice to mention from which version completion command became available

3.23, since this is going to be a new feature, we'll be able to go up a number regardless.

apps/rebar/src/rebar_prv_completion.erl Outdated Show resolved Hide resolved
apps/rebar/src/rebar_completion.erl Show resolved Hide resolved
@MarkoMin
Copy link
Contributor Author

MarkoMin commented Mar 5, 2024

Fixed. I'll ping you when I'll submit docs PR to rebar3.org repo.

@ferd ferd changed the title completion provider add a new shell completion provider Mar 5, 2024
@ferd ferd merged commit 59238ca into erlang:main Mar 5, 2024
6 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.

Command to generate shell completion files
2 participants