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

introduce a fully featured version manager #230

Merged
merged 25 commits into from
Dec 7, 2024
Merged

Conversation

Techatrix
Copy link
Collaborator

@Techatrix Techatrix commented Sep 7, 2024

Installing Zig or ZLS with the extension doesn't properly handle switching between different Zig project.
You have to manually figure out which version to get and install it every time your switch to a project that requires a different Zig version. Same goes for ZLS. The vscode configuration for Zig also can't handle switching between devices (see #111)
Let's stop giving developer the ability to misconfigure their editor.

  1. No initial setup for Zig
  2. initial setup for ZLS is only 'yes' or 'no'
  3. Done!

Version Manager

This is how the extension selects which version of Zig to install:

  • set the zig.version config option (can be global or per-workspace)
  • manually set the version through the 'Select and Install' popup (per-workspace)
  • set minimum_zig_version in the build.zig of your workspace
  • add a .zigversion to your workspace which stores the desired Zig version

If none of the above apply, the latest tagged release of Zig is installed.
Installs are automatically uninstalled to not fill up disk storage too much.
Installs are downloaded from mirrors just like setup-zig (fixes #238) and verified with minisign
The version of ZLS is inferred from the Zig version.

One unfortunate limitation is that the Zig installation will fail if the exact Zig version in the build.zig.zon is not provided as a prebuilt binary. There is no mechanism in place that will try to find the next available version.

Status Bar

Hovering over the "Editor Language Status" will show whether Zig and ZLS are installed + their versions. The Status Bar Item for Zig will turn red if is not installed. Clicking on it will open the 'Select and Install' popup.

Screenshot from 2024-09-07 21-23-59

Updated 'Select and Install' popup

  • added an option to manually specify the path to Zig
  • added an option to select Zig from PATH (if available)
  • added an option to install Mach's Nominated Zig versions
  • display the exact version of nightly
  • display which versions are already installed on the host machine
  • if no network connection is available, only versions that are already installed are displayed

Screenshot from 2024-11-22 09-38-52

Zig version update

  • The zig.update command has been removed. The 'Select and Install' popup can be used instead.
  • The zig.checkForUpdate has been removed. I can open a follow-up issue about it. I can foresee this needing some extra discussion to evaluate whether this feature is worth bringing back and how exactly it should behave.

follow-up tasks

  • select a Zig version should suggest to add or modify .zigversion or build.zig.zon
  • make it clear that the currently use Zig version does not match the .zigversion or build.zig.zon
  • make it possible to explicitly uninstall Zig builds (I believe that the quickpick popup can have buttons)
  • emit a warning if the installed Zig version does not satisfy the minimum_zig_version
  • make it clear that the 'Select and Install' popup is in "offline mode"
  • bring back checkForUpdate if possible

I wanted to keep these changes as small as possible but I couldn't stop myself. 😞
Any feedback would be greatly appreciated.

@Techatrix
Copy link
Collaborator Author

@Vexu Any thoughts on these changes?

@Lygaen
Copy link

Lygaen commented Sep 24, 2024

I allowed myself to mention your PR here !
#232

I can remove it from the list if you desire

@Techatrix Techatrix force-pushed the techatrix/version-manager branch 2 times, most recently from 7c6cb52 to 1475806 Compare September 29, 2024 22:46
@Vexu
Copy link
Member

Vexu commented Sep 29, 2024

I'm guessing there is precedence for extensions downloading additional binaries unprompted when installed so I guess that is fine especially since it is from the official source. As long as overriding the path to the Zig binary still works these all seem like good changes. And sorry for taking so long to get to this.

These changes make ZLS an "invisible" component of the extension after the initial setup.

This also removes the `zig.zls.checkForUpdate` command. I am not sure if it even needs to be brought back. I've made sure that no error is reported if no internet connection is available. The last installed ZLS version should be reused.

closes #136 because `zig.zls.startRestart` will just enable ZLS instead of complaining
The manual update command is already covered by the 'Select and Install' popup.
This commit replaces the initial setup with the following mechanism:
1. Check if the "Install Zig" has been previously executed in the active workspace. If so, install that version.
2. If the workspace contains a `.zigversion`, install the given Zig version.
3. If the workspace contains a `build.zig.zon` with a `minimum_zig_version`, install the next available Zig version.
4. Otherwise fallback to the latest tagged release of Zig.

Some parts of this are not fully implemented.

fixes #111
- add the ability to remove the workspace zig-version
- add an option to manually specify the path to Zig
- add an option to select Zig from PATH (if available)
- display the exact version of nightly
- display which versions are already installed on the host machine
- make the popup usable without an internet connection
This unfortunately has a large impact on the bundle size: 600kb -> 1.3mb
For now, the list of mirrors has been manually copied over from mlugg/setup-zig. Adding mirrors for ZLS is also possible even though none exist.

fixes #238
@Techatrix Techatrix force-pushed the techatrix/version-manager branch from a59bc53 to b6adadc Compare November 22, 2024 08:33
@Techatrix Techatrix force-pushed the techatrix/version-manager branch from b6adadc to d5430e3 Compare November 22, 2024 08:55
@Techatrix Techatrix marked this pull request as ready for review November 22, 2024 09:30
@Techatrix
Copy link
Collaborator Author

Ready for Review 🚀
I tried to keep the individual commits as readable as possible. Please let me know if there is anything I can do to make it easier to review.

Also, I think that publishing a pre-release can make sense here. I can ask in some of the Zig communities to see if there are people who would like to try this out before it gets published to everyone.

Copy link
Member

@Vexu Vexu left a comment

Choose a reason for hiding this comment

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

Looks good! I published this as 0.5.10 (pre-release) so you can get people to try it after which I'll release it as 0.6.0.

@aaronjheng
Copy link

{} zig Zig 0.13.0 seems a little redundant.

How about the following changes:

  • Capitalize the first zig
  • Remove the second Zig

The result would be {} Zig 0.13.0.

- removed redundant "Zig" from text
- changed the Name (that appears in the context menu) from "Zig" to "Zig Version"
@Techatrix
Copy link
Collaborator Author

{} zig Zig 0.13.0 seems a little redundant.

You are referring to the status bar items, right?

The reason why I had it this way was because they were made up of two independent items, the {} zig specifies the language of the current document and Zig 0.13.0 specifies the version of compiler. It is possible to hide one of them and keep the other. But I have to agree that having "Zig" appear twice is redundant, I updated it like you suggested.

A similar test is already done in versionManager.ts
This should help when going back to the extension version. Otherwise it wont show the initial setup popup again.
This also fixes some cases where the status item would incorrectly state that ZLS is running
@Techatrix
Copy link
Collaborator Author

I did find some minor issues that have been resolved. Otherwise, this is ready to go. I can open some new issues about the follow-up tasks.

@Vexu Vexu merged commit 681e0a9 into master Dec 7, 2024
2 checks passed
@Techatrix Techatrix deleted the techatrix/version-manager branch December 7, 2024 22:00
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.

Use mirrors for downloading Zig (and ZLS?) tarballs
4 participants