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

fix: remove automatic compinit #678

Merged
merged 6 commits into from Mar 19, 2020
Merged

fix: remove automatic compinit #678

merged 6 commits into from Mar 19, 2020

Conversation

@jthegedus
Copy link
Contributor

@jthegedus jthegedus commented Mar 13, 2020

Summary

#544 released in https://github.com/asdf-vm/asdf/releases/tag/v0.7.7 changed:

- if [ -n "$ZSH_VERSION" ]; then
-   autoload -U bashcompinit	
-   bashcompinit
+ if [ -n "${ZSH_VERSION:-}" ]; then
+   fpath=(${ASDF_DIR}/completions $fpath)
+   autoload -Uz compinit
+   compinit
+ fi

which results in compinit being executed multiple times (should people use a framework or explicitly use compinit in their own zshrc``). compinit` is designed to be called once, so we should not automatically run it here and double up on those already calling it.

This has performance implications and concerns were raised about asdf being unexpectedly intrusive.

Clearer documentation updates will rectify any issues with this removal. I would wager few ZSH users are relying on asdf to run compinit so hopefully we see minimal affect.

This was previously not a problem for ZSH users as we were:

  • using bashcompinit and thus not interfering with compinit
  • advising users to source the Bash completions in their zshrc files

Fixes: #674

Raised by concerns in #674 about performance implications and unexpected intrusive behaviour
@jthegedus jthegedus added the WIP label Mar 13, 2020
@jthegedus jthegedus self-assigned this Mar 13, 2020
@jthegedus
Copy link
Contributor Author

@jthegedus jthegedus commented Mar 13, 2020

Update to docs still pending hence the WIP badge

!>If you are not using a framework, or if on starting your shell you get an error message like command not found: compinit, then add the below line before the ones above.

Should probably instruct users to do this after sourcing asdf.sh as it adds to fpath, not before asdf.sh like it does now

@jthegedus
Copy link
Contributor Author

@jthegedus jthegedus commented Mar 13, 2020

@andrewthauer @Strayer Could you test and review to ensure these changes do as you expect and resolve any performance issues you may have seen? Thanks

@Strayer
Copy link

@Strayer Strayer commented Mar 13, 2020

Works great for me, I now only source asdf.sh in my .zshrc and let zinit handle the rest. Loads MUCH quicker and completions work as expected. Thank you @jthegedus! Any way to donate you a beer/coffee/tea/whateveryoulove?

Copy link
Contributor

@andrewthauer andrewthauer left a comment

Same. Back to normal 🎉. Thanks for the quick response and fix @jthegedus!

@andrewthauer
Copy link
Contributor

@andrewthauer andrewthauer commented Mar 13, 2020

I should point out that I noticed the following error could still occur if a user is sourcing the bash completions manually and using zsh (instead of bash):

asdf/completions/asdf.bash:68: command not found: complete

I have a script that wraps the asdf initialization that is intended to work with both zsh and bash. I was previously always sourcing the bash completions, but sine v0.77, I started getting this error as well. This was easily worked around by conditionally checking if the session is bash before sourcing. However, this leads me to think this could have started for some others as well. However, you could view this as a separate issue. I don't see these PR changes having any effect on this either way.

@Strayer
Copy link

@Strayer Strayer commented Mar 13, 2020

However, this leads me to think this could have started for some others as well.

That was exactly what I was doing and got me to even look up the issue here. I think it is reasonable to assume that sourcing a file that specifically states bash may not work in zsh, but maybe a warning in that file when it is run inside zsh might make sense.

@andrewthauer
Copy link
Contributor

@andrewthauer andrewthauer commented Mar 13, 2020

I think it is reasonable to assume that sourcing a file that specifically states bash may not work in zsh, but maybe a warning in that file when it is run inside zsh might make sense.

Exactly. It didn't affect anything noticeable, which is why I probably didn't think twice about it. I did start seeing it in v0.77 though. I would say my fix is not a workaround and is the proper course of action. Maybe it should be noted to not source the bash completions if your using zsh? Not sure on where this actually stems from.

@jthegedus jthegedus added bug and removed WIP labels Mar 14, 2020
@jthegedus
Copy link
Contributor Author

@jthegedus jthegedus commented Mar 14, 2020

I should point out that I noticed the following error could still occur if a user is sourcing the bash completions manually and using zsh (instead of bash):

Given we were advising people to manually source the .bash completions before v0.7.7 (and we were running bashcompinit automatically)I think this will be a common issue. I shall update the docs to point people in the right direction. Thanks for pointing this out 🎉

docs before v0.7.7:

Anyone have feelings on how we should handle deprecating things like https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/asdf/asdf.plugin.zsh as they are now doing needless work?

Thank you @jthegedus! Any way to donate you a beer/coffee/tea/whateveryoulove?

@Strayer thanks, but I am yet to setup GitHub sponsors yet. Has been on my backlog since the beta 😅

@jthegedus
Copy link
Contributor Author

@jthegedus jthegedus commented Mar 14, 2020

The more I get into the weeds of this the more I think we should not be adding things to the fpath at all 🤔

We recommend sourcing asdf.sh after ZSH frameworks, but if the framework calls compinit, then the addition to fpath isn't picked up, so users would have to run compinit themselves anyway. But then plugins may exist for the framework that does integrate the sourcing of asdf.sh at the correct time in the lifecycle. There are infinite combinations here.

So I think the solution here is to:

  • update ZSH framework plugins to add completions to fpath to properly integrate with their lifecycle and usage of compinit. oh-my-zsh asdf plugin needs updating, I'm sure others exist. A note in the docs might suffice here.
  • update Brew installation to use the native ZSH completions - Homebrew/homebrew-core#51720
  • update documentation for completions to direct people to either roll their own compinit OR if using a framework, ensure there's an asdf plugin which integrates it correctly

Thoughts anyone? @nomasprime @philpennock?

@philpennock
Copy link
Contributor

@philpennock philpennock commented Mar 14, 2020

Documenting required steps and otherwise not doing anything WFM. Packagers can drop the completion into whatever directory their system sets up for such things (Homebrew/whatever), power-users who bypass such things can read the docs.

@andrewthauer
Copy link
Contributor

@andrewthauer andrewthauer commented Mar 14, 2020

As a power use myself, I already have the expectation of manually appending things to the fpath. I've also had to factor in the lifecycle when modifying the fpath. Therefore, this strategy makes perfect sense to me and seems consistent with how many other libraries deal with zsh completions.

For reference:

  • homebrew installed packages typically symlink their completions to [brew-prefix]/share/zsh/site-functions. If a user or framework adds this to their fpath (as I do), they will get completions for all that comply to that convention. See https://docs.brew.sh/Shell-Completion
  • zsh-completions is a prominent project that adds zsh completions for many utilities. Their instructions tell users to add to the fpath manually as well.
@jthegedus
Copy link
Contributor Author

@jthegedus jthegedus commented Mar 14, 2020

Thanks for weighing in @philpennock

Thanks for the information @andrewthauer

Then Homebrew ZSH change has been merged, so users installing with Homebrew should get the correct ZSH completions through that. I will update the docs to reflect this.

I will try the symlink method used by zsh-completions in the oh-my-zsh asdf plugin and see if we can remove the usage of the bash completions there.

And I will update the docs for the rest of people using other ZSH frameworks about manual fpath setup or looking at the aforementioned plugins to update their own ecosystems.

Thanks for all your input everyone.

@Stratus3D Perhaps once I get this fix in we can organise a patch release so others don't run into these same issues?

@juanibiapina
Copy link

@juanibiapina juanibiapina commented Mar 17, 2020

The call to compinit will still be removed, right ?

@jthegedus
Copy link
Contributor Author

@jthegedus jthegedus commented Mar 17, 2020

@juanibiapina Yes, the compinit will also be removed. Sorry for the disruption.

@Stratus3D
Copy link
Member

@Stratus3D Stratus3D commented Mar 18, 2020

@jthegedus yes, assuming no breaking changes have been merged since 0.7.7 was tagged. I don't think there were any, but as soon as you merge this I'll check and then tag 0.7.8.

@jthegedus jthegedus added the WIP label Mar 18, 2020
jthegedus added 3 commits Mar 19, 2020
@jthegedus
Copy link
Contributor Author

@jthegedus jthegedus commented Mar 19, 2020

I think we are good to go now. Updates to plugins can hopefully be socialised by those who use them once they find this "feature" was reversed.

@jthegedus jthegedus removed the WIP label Mar 19, 2020
@jthegedus jthegedus merged commit 3246c26 into master Mar 19, 2020
9 checks passed
9 checks passed
test (macOS-latest)
Details
test (macos-latest)
Details
test (ubuntu-latest)
Details
test (ubuntu-latest)
Details
test (windows-latest) test (windows-latest)
Details
lint
Details
lint
Details
format
Details
format
Details
@jthegedus jthegedus deleted the remove-zsh-automatic-compinit branch Mar 19, 2020
@jthegedus
Copy link
Contributor Author

@jthegedus jthegedus commented Mar 19, 2020

@Stratus3D Please cut a new release when you have the time, cheers 🍻

@Stratus3D
Copy link
Member

@Stratus3D Stratus3D commented Mar 23, 2020

0.7.8 has been tagged. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.