feat: add zls toolchain support#653
Merged
Merged
Conversation
aherrmann
reviewed
May 19, 2026
Owner
aherrmann
left a comment
There was a problem hiding this comment.
This looks great! A few small comments.
I tried to use this locally on the tests that this adds:
Zed settings:
{
"lsp": {
"zls": {
"binary": {
"path": "tools/zls.sh"
}
}
}
}
zls.sh:
#!/usr/bin/env bash
cd "$(dirname "${BASH_SOURCE[0]}")"
cd "$(bazel info workspace)"
exec bazel run -- //zig/tests/zls-completion:completion "${@}"
and an empty build.zig in the workspace root.
I notice a few things:
- The ZLS log does show that it's picking up the Bazel provided ZLS:
Starting ZLS 0.16.0 @ '...BAZEL_CACHE.../external/+zls+zls_0.16.0_x86_64-linux/zls' - It is loading the generated config
Loaded config: /tmp/1779204056137495202.json - It configures the various config options, including
global_cache_path. - However, it still generates a local cache (
.zig-cache/in the Bazel workspace root) - is that intentional? It would seem more plausible to match the Bazel Zig toolchain setting for both local and global cache. - In the end I'm seeing
failed to receive message from zig build-on-save runner: error.EndOfStream, not sure if that's expected. - Things like go-to-definition from
app.zigonmid.value()do not work - is that expected?
Contributor
Author
|
All addressed, as for the mid.zig, that's because in this test, zls_completion only refers to lib and not the rest. Better to try on a real workspace ! |
Owner
Got it, just adding those targets to the list go-to-definition worked. Nice! |
aherrmann
approved these changes
May 20, 2026
Owner
aherrmann
left a comment
There was a problem hiding this comment.
Thank you for adding this! ZLS is a great feature to have! 🎉
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #403
This is an adapted port of an internal zls support code I've had for more than 6 months now.
Summary
rules_zig.zls_completionmacro that produces a Bazel-backed ZLS launcher for a set of Zig targets.Usage
Define a completion target for the Zig targets that should be visible to ZLS:
Configure the editor to run a small wrapper script, e.g.:
How It Works
:completiontarget through Bazel.:completionis a generated Zig runner. It resolves the selected ZLS binary, Zig executable, Zig lib directory, and custom build runner through Bazel runfiles, writes a temporary ZLS config, then launches ZLS with--config-path.print_build_configtarget, and returns a ZLS build config derived from the declared Zig deps.Implementation Notes
zig_versionis used for selection andzls_versionis the downloaded artifact version, so they can differ when needed, e.g. Zig0.15.2using ZLS0.15.1.Validation
zls_completionwith the default Zig toolchain and with--@zig_toolchains//:version=0.15.2.