Skip to content

Match downloaded ZLS version to the installed Zig toolchain - #47

Open
insideable wants to merge 2 commits into
zed-extensions:mainfrom
insideable:fix-zig-0.16-zls-version-matching
Open

Match downloaded ZLS version to the installed Zig toolchain#47
insideable wants to merge 2 commits into
zed-extensions:mainfrom
insideable:fix-zig-0.16-zls-version-matching

Conversation

@insideable

Copy link
Copy Markdown

Summary

Fixes #36 and #38.

The extension always fetched the latest zigtools/zls GitHub release regardless of which Zig version was actually installed. ZLS refuses to run against a mismatched Zig version, so once zls moved ahead of a user's Zig install (e.g. Zig 0.16 while zls was still 0.15), the extension broke with:

ZLS '0.15.0' does not support Zig '0.16.0'. A ZLS '0.16' release should be used instead.

This also affected dev builds, as reported in #38.

Changes

  • detect_zig_version resolves zig via the worktree's PATH (respecting version managers like mise/asdf that alter the shell env) and runs zig version to get the installed version.
  • matching_zls_release queries zigtools' select-version API to fetch the ZLS build that actually matches the installed Zig version, using the API-provided tarball URL directly (handles both the current {arch}-{os} naming and legacy {os}-{arch} naming from older ZLS releases).
  • Falls back to the previous "latest GitHub release" behavior only when no zig binary can be found on PATH at all.
  • extension.toml gains a process:exec capability for zig version, required by Zed's WASM sandbox.
  • ZigExtension's binary-path cache is now keyed by detected Zig version (instead of a single global cache), since different worktrees may need different ZLS builds concurrently. Added a bounded cleanup pass that removes zls-* directories no longer referenced by the current session's cache, so this doesn't grow disk usage unboundedly.
  • Added unit tests for the new pure logic (version-string parsing, URL construction, response parsing including the API's error-shaped payloads).

Test plan

  • cargo test — 12/12 unit tests pass
  • cargo clippy --target wasm32-wasip2 --release — no warnings
  • cargo fmt --check — clean
  • cargo build --release --target wasm32-wasip2 — builds successfully
  • Manually verified against a real Zig 0.16.0 install: zig version0.16.0, and https://releases.zigtools.org/v1/zls/select-version?zig_version=0.16.0&compatibility=only-runtime returns a matching ZLS 0.16.0 release with a working tarball URL
  • Not tested inside the actual Zed editor as a dev extension (no GUI available in the environment this was developed in) — would appreciate a test run from a maintainer or reviewer with a Zed GUI available

🤖 Generated with Claude Code

@cla-bot

cla-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Vitali Falileev.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

The extension always fetched the latest zigtools/zls GitHub release
regardless of which Zig version was installed. ZLS refuses to run
against a mismatched Zig version, so once zls moved ahead of a user's
Zig install (e.g. Zig 0.16 while zls was still 0.15) the extension
would break with "ZLS 'X' does not support Zig 'Y'" (zed-extensions#36, zed-extensions#38).

Detect the Zig version via `zig version` on the worktree's resolved
PATH and use zigtools' select-version API to fetch the ZLS build that
actually matches it, falling back to the latest release only when no
zig binary can be found at all.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@insideable
insideable force-pushed the fix-zig-0.16-zls-version-matching branch from 8807446 to 8a4d795 Compare August 10, 2026 05:03
@cla-bot

cla-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @insideable on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@insideable

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot

cla-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @insideable on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@cla-bot

cla-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@insideable

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Aug 10, 2026
@cla-bot

cla-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

… Zig

The version-matching download logic added in the previous commit never
ran for users who already had a `zls` binary on PATH (e.g. installed
via a system package manager, like Arch's `zls` package), because that
case short-circuited before the new logic. Reproduced with pacman's
`zls` 0.15.1 alongside Zig 0.16.0: the extension kept handing Zed the
outdated system zls, hitting the exact "ZLS 'X' does not support Zig
'Y'" error the previous fix was meant to resolve.

Now the PATH shortcut checks that the found zls's major.minor actually
matches the detected Zig version (mirroring ZLS's own compatibility
rule) before trusting it, falling through to the version-matched
download otherwise.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Zig 0.16 support

1 participant